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

java.lang.IllegalStateException: No adapter available for type:class io.fabric8.kubernetes.client.V1APIGroupClient #3063

Closed
yeikel opened this issue Apr 30, 2021 · 4 comments
Assignees
Labels
Waiting on feedback Issues that require feedback from User/Other community members

Comments

@yeikel
Copy link

yeikel commented Apr 30, 2021

Hi team,

I have the following configuration in my pom :

    <dependency>
        <groupId>io.fabric8</groupId>
        <artifactId>openshift-client</artifactId>
        <version>5.3.1</version>
    </dependency>

And I am creating my client :

final Config config = new ConfigBuilder().withOauthToken(token).withMasterUrl(env.url()).build();
this.client = new DefaultKubernetesClient(config).adapt(OpenShiftClient.class);

And then, I am calling the following api to get the list of events :

client.v1().events().inNamespace(project).list().getItems();

But that is producing the following runtime exception :

20:46:41  Exception in thread "main" java.lang.IllegalStateException: java.lang.IllegalStateException: No adapter available for type:class io.fabric8.kubernetes.client.V1APIGroupClient
20:46:41  	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
20:46:41  	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
20:46:41  	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
20:46:41  	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
20:46:41  	at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:600)
20:46:41  	at java.base/java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:678)
20:46:41  	at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:737)
20:46:41  	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateParallel(ReduceOps.java:919)
20:46:41  	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
20:46:41  	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
20:46:41  	at com.aexp.c360.sre.UnHealthyPodReStarter.main(UnHealthyPodReStarter.java:132)
20:46:41  Caused by: java.lang.IllegalStateException: No adapter available for type:class io.fabric8.kubernetes.client.V1APIGroupClient
20:46:41  	at io.fabric8.kubernetes.client.BaseClient.adapt(BaseClient.java:130)
20:46:41  	at io.fabric8.openshift.client.DefaultOpenShiftClient.v1(DefaultOpenShiftClient.java:654)

I tried adding both dependencies :

       <dependency>
            <groupId>io.fabric8</groupId>
            <artifactId>openshift-client</artifactId>
            <version>5.3.1</version>
        </dependency>

        <dependency>
            <groupId>io.fabric8</groupId>
            <artifactId>kubernetes-client</artifactId>
            <version>5.3.1</version>
        </dependency>

But that produced a different runtime exception

If it helps in any way, I am using Java 11 and Maven

Also, it does not seem to happen when I run the project locally. It only happens when I shade the build :

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <minimizeJar>true</minimizeJar>
                            <createDependencyReducedPom>true</createDependencyReducedPom>
                            <dependencyReducedPomLocation>
                                ${java.io.tmpdir}/dependency-reduced-pom.xml
                            </dependencyReducedPomLocation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
@manusa manusa assigned manusa and rohanKanojia and unassigned manusa Jul 5, 2021
@rohanKanojia
Copy link
Member

This issue is not just with V1APIGroupClient but with any Client whose Adapter is discovered via ServiceLoader:

io.fabric8.kubernetes.client.AppsAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.AdmissionRegistrationAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1AdmissionRegistrationAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1beta1AdmissionRegistrationAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.AutoscalingAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.ApiextensionsAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.AuthorizationAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1AutoscalingAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V2beta1AutoscalingAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V2beta2AutoscalingAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.BatchAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1BatchAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1beta1BatchAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.ExtensionsAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.EventingAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1EventingAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1beta1EventingAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.FlowControlAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1beta1FlowControlAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.MetricAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.NetworkAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.PolicyAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1PolicyAPIGroupExtensionAdapter
io.fabric8.kubernetes.client.V1beta1PolicyAPIGroupExtensionAdapter

@manusa
Copy link
Member

manusa commented Jul 5, 2021

@rohanKanojia
Copy link
Member

@yeikel : Hello, I think maven-shade-plugin needs to be configured to avoid service entry declaration collision in kubernetes-client and openshift-client modules. If you add ServiceResourceTransformer in your maven-shade-plugin configuration you should get merged service entry declarations from both jars:

<configuration>
       <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />                            
       </transformers>
</configuration>

I tested it with this project and I'm able to run the fat jar with the above configuration: https://github.com/r0haaaan/fabric8-kubernetes-client-demo-shaded

I've tested with both openshift-client and kubernetes-client dependencies and also with single openshift-client dependencies and it seems to work in both cases.

@manusa manusa added the Waiting on feedback Issues that require feedback from User/Other community members label Jul 5, 2021
@yeikel
Copy link
Author

yeikel commented Jul 6, 2021

Confirmed to be the solution. Thank you @rohanKanojia

@yeikel yeikel closed this as completed Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting on feedback Issues that require feedback from User/Other community members
Projects
None yet
Development

No branches or pull requests

3 participants