quarkus-operator-sdk icon indicating copy to clipboard operation
quarkus-operator-sdk copied to clipboard

Build error "AptContext has not been created"

Open kdubb opened this issue 1 year ago • 15 comments
trafficstars

With 6.5.0 I am getting a the following error listed below.

This is with our project using the sdk aligned Quarkus 3.6.4.

Previously, using 6.4.0 with Quarkus 3.5.3 (and the Fabric8 client version locked to 6.7.2) we weren't getting any issue during the build.

Execution failed for task ':cloud-vault-operator:quarkusAppPartsBuild'.
> There was a failure while executing work items
   > A failure occurred while executing io.quarkus.gradle.tasks.worker.BuildWorker
      > io.quarkus.builder.BuildException: Build failure: Build failed due to errors
                [error]: Build step io.quarkiverse.operatorsdk.deployment.CRDGenerationBuildStep#generateCRDs threw an exception: java.lang.IllegalStateException: AptContext has not been created, yet.
                at io.sundr.adapter.apt.AptContext.getContext(AptContext.java:95)
                at io.sundr.adapter.apt.AptLookup.forName(AptLookup.java:30)
                at io.sundr.adapter.api.TypeLookup.lambda$lookup$0(TypeLookup.java:30)
                at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
                at java.base/java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1950)
                at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
                at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
                at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
                at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
                at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
                at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
                at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
                at io.sundr.adapter.api.TypeLookup.lookup(TypeLookup.java:34)
                at io.sundr.model.functions.GetDefinition.lambda$apply$1(GetDefinition.java:47)
                at java.base/java.util.Optional.orElseGet(Optional.java:364)
                at io.sundr.model.functions.GetDefinition.apply(GetDefinition.java:47)
                at io.sundr.model.functions.GetDefinition.of(GetDefinition.java:36)
                at io.fabric8.crd.generator.utils.Types.typeDefFrom(Types.java:73)
                at io.fabric8.crd.generator.visitor.AnnotatedPropertyPathDetector.visitPropertiesClasses(AnnotatedPropertyPathDetector.java:86)
                at io.fabric8.crd.generator.visitor.AnnotatedPropertyPathDetector.visit(AnnotatedPropertyPathDetector.java:76)
                at io.fabric8.crd.generator.visitor.AnnotatedPropertyPathDetector.visit(AnnotatedPropertyPathDetector.java:34)
                at io.sundr.builder.Visitor.visit(Visitor.java:30)
                at io.sundr.builder.VisitorWiretap.visit(VisitorWiretap.java:79)
                at io.sundr.builder.Visitable.accept(Visitable.java:67)
                at io.sundr.builder.Visitable.lambda$accept$1(Visitable.java:81)
                at java.base/java.util.Optional.ifPresent(Optional.java:178)
                at io.sundr.builder.Visitable.accept(Visitable.java:73)
                at io.sundr.builder.Visitable.accept(Visitable.java:53)
                at io.sundr.builder.Visitable.accept(Visitable.java:30)
                at io.fabric8.crd.generator.visitor.AnnotatedPropertyPathDetector.visitPropertiesClasses(AnnotatedPropertyPathDetector.java:91)
                at io.fabric8.crd.generator.visitor.AnnotatedPropertyPathDetector.visit(AnnotatedPropertyPathDetector.java:76)
                at io.fabric8.crd.generator.visitor.AnnotatedPropertyPathDetector.visit(AnnotatedPropertyPathDetector.java:34)
                at io.sundr.builder.Visitor.visit(Visitor.java:30)
                at io.sundr.builder.VisitorWiretap.visit(VisitorWiretap.java:79)
                at io.sundr.builder.Visitable.accept(Visitable.java:67)
                at io.sundr.builder.Visitable.accept(Visitable.java:53)
                at io.sundr.builder.Visitable.accept(Visitable.java:30)
                at io.fabric8.crd.generator.visitor.AnnotatedPropertyPathDetector.visitPropertiesClasses(AnnotatedPropertyPathDetector.java:91)
                at io.fabric8.crd.generator.visitor.AnnotatedPropertyPathDetector.visit(AnnotatedPropertyPathDetector.java:76)
                at io.fabric8.crd.generator.visitor.AnnotatedPropertyPathDetector.visit(AnnotatedPropertyPathDetector.java:34)
                at io.sundr.builder.Visitor.visit(Visitor.java:30)
                at io.sundr.builder.VisitorWiretap.visit(VisitorWiretap.java:79)
                at io.sundr.builder.Visitable.accept(Visitable.java:67)
                at io.sundr.builder.Visitable.accept(Visitable.java:53)
                at io.sundr.builder.Visitable.accept(Visitable.java:30)
                at io.fabric8.crd.generator.AbstractCustomResourceHandler.visitTypeDefSequentially(AbstractCustomResourceHandler.java:116)
                at io.fabric8.crd.generator.AbstractCustomResourceHandler.visitTypeDef(AbstractCustomResourceHandler.java:109)
                at io.fabric8.crd.generator.AbstractCustomResourceHandler.handle(AbstractCustomResourceHandler.java:77)
                at io.fabric8.crd.generator.v1.CustomResourceHandler.handle(CustomResourceHandler.java:98)
                at io.fabric8.crd.generator.CRDGenerator.lambda$detailedGenerate$5(CRDGenerator.java:177)
                at java.base/java.util.HashMap$Values.forEach(HashMap.java:1073)
                at io.fabric8.crd.generator.CRDGenerator.detailedGenerate(CRDGenerator.java:177)
                at io.quarkiverse.operatorsdk.deployment.CRDGeneration.generate(CRDGeneration.java:83)
                at io.quarkiverse.operatorsdk.deployment.CRDGenerationBuildStep.generateCRDs(CRDGenerationBuildStep.java:91)
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
                at java.base/java.lang.reflect.Method.invoke(Method.java:580)
                at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:849)
                at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
                at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
                at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
                at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
                at java.base/java.lang.Thread.run(Thread.java:1583)
                at org.jboss.threads.JBossThread.run(JBossThread.java:501)

kdubb avatar Jan 08 '24 07:01 kdubb

Hi @kdubb, is there a way for me to replicate the issue? To be clear, you're using QOSDK 6.5.0 with Quarkus 3.6.4, correct? Are you using the Quarkus platform BOM or the QOSDK BOM? Which version of java are you using?

metacosm avatar Jan 10 '24 10:01 metacosm

@metacosm Sorry for not responding. I thought I had.

Yes QOSDK 6.5.0 and Quarkus 3.6.4. It also happens now with QOSDK 6.6.2 and Quarkus 3.7.1.

We are using the Quarkus platform BOM and Java 17.

kdubb avatar Mar 04 '24 00:03 kdubb

Would you be able to share your model since it seems to happen during CRD generation?

metacosm avatar Mar 04 '24 08:03 metacosm

@metacosm You're onto something here. We have to subprojects in a Gradle build that share a common "operators" dependency. One is a trust operator for generating certificate bundles and projecting them into needed namespaces handling rotation; it's pretty simple. The other is a Vault operator that manages Vault items required by our services; it's much more in-depth and has a lot of model objects.

I'm just realizing that the Vault operator project is where we get the failure. If I attempt to build the simpler trust operator project it builds fine with no error.

Our build is scattered across common deps, a common operator dep and then the operator projects themselves; it won't be easy to rip it apart and get it to build in a manner I can share.

Any thoughts, based on the stacktrace and this new information, on what exactly might be causing this? Remember it worked with previous Q and QOSDK versions (which we're attempting to move off of). So it must be a change introduced after this setup

QOSDK 6.4.0 with Quarkus 3.5.3 (and the Fabric8 client version locked to 6.7.2 because of a Q dep change)

kdubb avatar Mar 14 '24 00:03 kdubb

@metacosm By deleting model files until I don't get the error, I was able to narrow it down to a "spec" class that has multiple properties derived from the same base class.

E.g. (in kotlin)

abstract class Config {}
class SomeConfig: Config {}
class OtherConfig: Config {}

class SomeSpec(
  val someConfig: SomeConfig?
  val otherConfig: OtherConfig?
)

If I remove either someConfig or otherConfig it does not produce the error.

kdubb avatar Mar 14 '24 07:03 kdubb

Note that if I change one of the properties to use a different class hierarchy it does not produce the error...

E.g. (in kotlin)

abstract class AConfig {}
class SomeConfig: AConfig {}

abstract class BConfig {}
class OtherConfig: BConfig {}

class SomeSpec(
  val someConfig: SomeConfig?
  val otherConfig: OtherConfig?
)

kdubb avatar Mar 14 '24 08:03 kdubb

Just to make sure, you're not locking the fabric8 version anymore, right?

metacosm avatar Mar 14 '24 08:03 metacosm

No not locked anymore. Currently testing with Q/3.7.2 and QOSDK/6.6.3

kdubb avatar Mar 14 '24 08:03 kdubb

The issue happens because AptContext the code attempts to use AptContext without AptContext being created.

IMHO, AptContext should never be used outside of annotation processors and it's sundrio's fault that it does when GetDefinition is called or at least. I'll try to address that next week.

iocanel avatar Mar 14 '24 10:03 iocanel

Thank you, @iocanel!

metacosm avatar Mar 15 '24 11:03 metacosm

Any update on this, @iocanel?

metacosm avatar Mar 21 '24 20:03 metacosm

@iocanel Any news? Sorry to ping again, but this has stopped us for a while.

kdubb avatar Apr 19 '24 20:04 kdubb

@kdubb: created https://github.com/sundrio/sundrio/pull/472

iocanel avatar Apr 23 '24 06:04 iocanel

@iocanel Do you know if this has landed in Quarkus, if so, what version?

kdubb avatar Jun 20 '24 14:06 kdubb