quarkiverse / quarkus-operator-sdk

Quarkus Extension to create Kubernetes Operators in Java using the Java Operator SDK (https://github.com/java-operator-sdk/java-operator-sdk) project
Apache License 2.0
118 stars 50 forks source link

Java Operator JUnit Extension is unusable from Quarkus #328

Open andreaTP opened 2 years ago

andreaTP commented 2 years ago

Trying to use the Java Operator JUnit Extension from a project using the Quarkus Operator SDK results in multiple errors and, currently, is impossible to run the tests.

Here you can find a minimal reproducer: https://github.com/andreaTP/operator-junit-repro

Additional considerations:

cc. @DGuhr @metacosm @csviri

scrocquesel commented 2 years ago

Do you need both Local and Remote support ? Remote would require the image to be built but I'm not sure quarkus do it before running the tests. Like the OLM testing, it could not be a mvn one liner as with josdk.

For local, I think that what you are asking can interest Quarkus k8s development more broadly as part of Dev Service experience. Maybe with quarkus-kind or quarkus-minikube extension, a cluster can be created if not detected during dev and tests.

Nonetheless, what about a custom QuarkusTestResourceLifecycleManager that can wrap an AbstractOperatorExtension to just prepare the cluster and let quarkus run the app normally. Meaning, the JOSDK JUnit extension is not responsible of creating and running the operator instance because it should not in the first place.

andreaTP commented 2 years ago

I forgot to give more context to this issue. We do have a working setup for local/remote testing in the Keycloak operator: https://github.com/keycloak/keycloak/blob/9541852a9bf7d36647d4723d3420556f4b75ac92/operator/src/test/java/org/keycloak/operator/ClusterOperatorTest.java#L39

And that's the reason why I contributed this functionality to the JOSDK. To pay tech debt, we have attempted to use the JUnit extension and failed. But it's definitely possible to do it!

metacosm commented 2 years ago

Nonetheless, what about a custom QuarkusTestResourceLifecycleManager that can wrap an AbstractOperatorExtension to just prepare the cluster and let quarkus run the app normally. Meaning, the JOSDK JUnit extension is not responsible of creating and running the operator instance because it should not in the first place.

That's the approach we decided to take: we will write a Quarkus test resource that deals with setting up the cluster, though I'm not sure how much code we'll be able to reuse from the JOSDK JUnit extension…