Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make it possible to inject OpenShiftClient instead of plain k8s #355

Merged
merged 1 commit into from
Mar 8, 2021

Conversation

metacosm
Copy link
Collaborator

@metacosm metacosm commented Mar 4, 2021

Fixes #330

@jmesnil
Copy link

jmesnil commented Mar 8, 2021

I think the PR is not enough.
If I switch my operator to use the OpenShift client, the compilation fails with:

[INFO] --- quarkus-maven-plugin:1.11.0.Final:build (default) @ wildfly-operator ---
[INFO] [org.jboss.threads] JBoss Threads version 3.2.0.Final
[INFO] [io.javaoperatorsdk.quarkus.extension.deployment.QuarkusExtensionProcessor] Processed 'org.wildfly.operator.WildFlyServerController' controller named 'wildflyservercontroller' for 'wildflyservers.wildfly.org' CR (version 'wildfly.org/v1beta1')
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  7.039 s
[INFO] Finished at: 2021-03-08T14:37:14+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:1.11.0.Final:build (default) on project wildfly-operator: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR]         [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.AmbiguousResolutionException: Ambiguous dependencies for type io.fabric8.kubernetes.client.KubernetesClient and qualifiers [@Default]
[ERROR]         - java member: io.javaoperatorsdk.quarkus.extension.OperatorProducer#operator()
[ERROR]         - declared on PRODUCER METHOD bean [types=[java.lang.Object, io.javaoperatorsdk.operator.Operator], qualifiers=[@Default, @Any], target=io.javaoperatorsdk.operator.Operator operator(io.fabric8.kubernetes.client.KubernetesClient client, io.javaoperatorsdk.operator.api.config.ConfigurationService configuration, javax.enterprise.inject.Instance<io.javaoperatorsdk.operator.api.ResourceController<? extends io.fabric8.kubernetes.client.CustomResource>> controllers), declaringBean=io.javaoperatorsdk.quarkus.extension.OperatorProducer]
[ERROR]         - available beans:
[ERROR]                 - PRODUCER METHOD bean [types=[java.lang.AutoCloseable, io.fabric8.kubernetes.client.KubernetesClient, java.lang.Object, java.io.Closeable, io.fabric8.openshift.client.OpenShiftClient, io.fabric8.kubernetes.client.ConfigAware, io.fabric8.kubernetes.client.Client], qualifiers=[@Default, @Any], target=io.fabric8.openshift.client.OpenShiftClient openShiftClient(io.fabric8.kubernetes.client.Config config), declaringBean=io.quarkus.it.openshift.client.runtime.OpenShiftClientProducer]
[ERROR]                 - PRODUCER METHOD bean [types=[java.lang.AutoCloseable, io.fabric8.kubernetes.client.KubernetesClient, java.lang.Object, java.io.Closeable, io.fabric8.kubernetes.client.ConfigAware, io.fabric8.kubernetes.client.Client], qualifiers=[@Default, @Any], target=io.fabric8.kubernetes.client.KubernetesClient kubernetesClient(io.fabric8.kubernetes.client.Config config), declaringBean=io.quarkus.kubernetes.client.runtime.KubernetesClientProducer]
[ERROR]         at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1064)
[ERROR]         at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:245)
[ERROR]         at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:129)
[ERROR]         at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:423)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR]         at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:972)
[ERROR]         at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2415)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
[ERROR]         at java.base/java.lang.Thread.run(Thread.java:834)
[ERROR]         at org.jboss.threads.JBossThread.run(JBossThread.java:501)
[ERROR] Caused by: javax.enterprise.inject.AmbiguousResolutionException: Ambiguous dependencies for type io.fabric8.kubernetes.client.KubernetesClient and qualifiers [@Default]
[ERROR]         - java member: io.javaoperatorsdk.quarkus.extension.OperatorProducer#operator()
[ERROR]         - declared on PRODUCER METHOD bean [types=[java.lang.Object, io.javaoperatorsdk.operator.Operator], qualifiers=[@Default, @Any], target=io.javaoperatorsdk.operator.Operator operator(io.fabric8.kubernetes.client.KubernetesClient client, io.javaoperatorsdk.operator.api.config.ConfigurationService configuration, javax.enterprise.inject.Instance<io.javaoperatorsdk.operator.api.ResourceController<? extends io.fabric8.kubernetes.client.CustomResource>> controllers), declaringBean=io.javaoperatorsdk.quarkus.extension.OperatorProducer]
[ERROR]         - available beans:
[ERROR]                 - PRODUCER METHOD bean [types=[java.lang.AutoCloseable, io.fabric8.kubernetes.client.KubernetesClient, java.lang.Object, java.io.Closeable, io.fabric8.openshift.client.OpenShiftClient, io.fabric8.kubernetes.client.ConfigAware, io.fabric8.kubernetes.client.Client], qualifiers=[@Default, @Any], target=io.fabric8.openshift.client.OpenShiftClient openShiftClient(io.fabric8.kubernetes.client.Config config), declaringBean=io.quarkus.it.openshift.client.runtime.OpenShiftClientProducer]
[ERROR]                 - PRODUCER METHOD bean [types=[java.lang.AutoCloseable, io.fabric8.kubernetes.client.KubernetesClient, java.lang.Object, java.io.Closeable, io.fabric8.kubernetes.client.ConfigAware, io.fabric8.kubernetes.client.Client], qualifiers=[@Default, @Any], target=io.fabric8.kubernetes.client.KubernetesClient kubernetesClient(io.fabric8.kubernetes.client.Config config), declaringBean=io.quarkus.kubernetes.client.runtime.KubernetesClientProducer]
[ERROR]         at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:493)
[ERROR]         at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:378)
[ERROR]         at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:237)
[ERROR]         ... 12 more
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Once I fixed the code in https://github.com/java-operator-sdk/java-operator-sdk/blob/e437bfc883ba9c807ea64a0ed38cd094ef05cb16/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/OperatorProducer.java#L20, I was able to compile and run my operator but it fails with the error:

java -jar target/wildfly-operator-1.0.0-SNAPSHOT-runner.jar
Mar 08, 2021 2:48:01 PM org.jboss.threads.Version <clinit>
INFO: JBoss Threads version 3.2.0.Final
Mar 08, 2021 2:48:01 PM io.quarkus.bootstrap.runner.Timing printStartupTime
INFO: wildfly-operator 1.0.0-SNAPSHOT on JVM (powered by Quarkus 1.11.0.Final) started in 0.795s. Listening on: http://0.0.0.0:8080
Mar 08, 2021 2:48:01 PM io.quarkus.bootstrap.runner.Timing printStartupTime
INFO: Profile prod activated.
Mar 08, 2021 2:48:01 PM io.quarkus.bootstrap.runner.Timing printStartupTime
INFO: Installed features: [cdi, kubernetes, kubernetes-client, openshift-client, operator-sdk, smallrye-health]
Exception in thread "main" java.lang.NoSuchMethodError: 'io.fabric8.kubernetes.client.dsl.NonNamespaceOperation io.fabric8.kubernetes.client.V1ApiextensionAPIGr
oupDSL.customResourceDefinitions()'
        at io.javaoperatorsdk.operator.Operator.register(Operator.java:102)
        at io.javaoperatorsdk.operator.Operator.register(Operator.java:63)
        at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
        at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)

My code was using 1.7.0 so it might be something that I missed when I upgraded to the 1.7.3-SNAPSHOT version.

@jmesnil
Copy link

jmesnil commented Mar 8, 2021

fwiw, this is the commit I used to test this PR: jmesnil/wildfly-operator@java-operator...jmesnil:openshift_client (the main change is switching the @injected client from Kubernetes to OpenShift

@metacosm
Copy link
Collaborator Author

metacosm commented Mar 8, 2021

I think this also needs: quarkusio/quarkus#14943 which is in 1.12.1…

@metacosm
Copy link
Collaborator Author

metacosm commented Mar 8, 2021

The second issue is due to a mismatch between the fabric8 version used in the SDK and the one brought up by quarkus, so it would really be needed to test with the latest master if possible…

@jmesnil
Copy link

jmesnil commented Mar 8, 2021

sorry for the noise, it turned out that this PR was not on the tip of master and my operator did not import consistent versions of operator-sdk and quarkus.
Once I fixed all of this, my operator was compiling and running fine. So this looks good to me.

@metacosm
Copy link
Collaborator Author

metacosm commented Mar 8, 2021

@jmesnil no problems, my bad for not rebasing properly before asking for tests 😥

@metacosm metacosm merged commit f1cdb6c into master Mar 8, 2021
@metacosm metacosm deleted the openshift branch March 8, 2021 16:59
@metacosm metacosm self-assigned this Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have access to Fabric8 OpenShift Client
2 participants