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.ClassNotFoundException: io.fabric8.kubernetes.client.DefaultKubernetesClient #4460

Closed
iampratapak opened this issue Sep 29, 2022 · 10 comments · Fixed by #4464
Closed
Assignees
Milestone

Comments

@iampratapak
Copy link

iampratapak commented Sep 29, 2022

Describe the bug

I'm using io.fabric8:kubernetes-client:6.1.1 and am running a simple client creation code:

final var kubernetesClient = new KubernetesClientBuilder().build();
System.out.println(kubernetesClient.getNamespace());

module-info.java

module com.some.module {
    requires kubernetes.client.api;
}

Error:

java.lang.ClassNotFoundException: io.fabric8.kubernetes.client.DefaultKubernetesClient

In module-info.java, if I use kubernetes.client instead of kubernetes.client.api, then I'mgetting the below error

module com.some.module {
    requires kubernetes.client;
}
java: module xyz reads package io.fabric8.kubernetes.client from both kubernetes.client.api and kubernetes.client

Since DefaultKubernetesClient is deprecated in 6.1.1, I'm using KubernetesClientBuilder.

Fabric8 Kubernetes Client version

6.1.1

Steps to reproduce

  1. Use io.fabric8:kubernetes-client:6.1.1
  2. In module-info.java add requires kubernetes.client.api
module com.some.module {
    requires kubernetes.client.api;
}
  1. Try to create a Kubernetes client using KubernetesClientBuilder
import io.fabric8.kubernetes.client.KubernetesClientBuilder;

public class Example {
    public static void main(String[] args) {
        final var kubernetesClient = new KubernetesClientBuilder().build();
        System.out.println(kubernetesClient.getNamespace());

    }
}

Expected behavior

Kubernetes client should be created without any errors

Runtime

other (please specify in additional context)

Kubernetes API Server version

other (please specify in additional context)

Environment

Windows

Fabric8 Kubernetes Client Logs

Exception in thread "main" io.fabric8.kubernetes.client.KubernetesClientException: An error has occurred.
	at kubernetes.client.api@6.1.1/io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:129)
	at kubernetes.client.api@6.1.1/io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:122)
	at kubernetes.client.api@6.1.1/io.fabric8.kubernetes.client.KubernetesClientBuilder.<init>(KubernetesClientBuilder.java:58)
	at com.some.module/com.some.module.Main.main(Main.java:106)
Caused by: java.lang.ClassNotFoundException: io.fabric8.kubernetes.client.DefaultKubernetesClient
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	at kubernetes.client.api@6.1.1/io.fabric8.kubernetes.client.KubernetesClientBuilder.<init>(KubernetesClientBuilder.java:56)
	... 1 more

Additional context

Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"cb303e613a121a29364f75cc67d3d580833a7479", GitTreeState:"clean", BuildDate:"2021-04-08T16:31:21Z", GoVersion:"go1.16.1", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.1", GitCommit:"5e58841cce77d4bc13713ad2b91fa0d961e69192", GitTreeState:"clean", BuildDate:"2021-05-12T14:12:29Z", GoVersion:"go1.16.4", Compiler:"gc", Platform:"linux/amd64"}
<dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>knative-client</artifactId>
      <version>6.1.1</version>
</dependency>
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Sep 29, 2022
@shawkins
Copy link
Contributor

I don't think the kubernetes client will currently work with Java modules due to the split packages. Can you see if #4464 will work for your usage?

@iampratapak
Copy link
Author

Thanks for the quick response, @shawkins. #4464 may work for my use case. I'll wait for the next release.

shawkins added a commit to shawkins/kubernetes-client that referenced this issue Sep 30, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Sep 30, 2022
@manusa manusa added this to the 6.2.0 milestone Oct 3, 2022
@manusa
Copy link
Member

manusa commented Oct 3, 2022

Hi @pratapgowda007
Once we merge the PR it would be great if you could confirm if the 6.2-SNAPSHOT nightly build resolves your issue.

@iampratapak
Copy link
Author

iampratapak commented Oct 3, 2022

@manusa Sure, please let me know once it's merged

shawkins added a commit to shawkins/kubernetes-client that referenced this issue Oct 4, 2022
@iampratapak
Copy link
Author

@manusa
I just cloned PR #4460 and tested. I can confirm 6.2-SNAPSHOT resolves my issue.

@iampratapak
Copy link
Author

@rohanKanojia May I know the tentative release date for 6.2.x?

@rohanKanojia
Copy link
Member

I think we should be releasing in upcoming sprint. So within 2-3 weeks from now if everything goes as expected.

@iampratapak
Copy link
Author

I think we should be releasing in upcoming sprint. So within 2-3 weeks from now if everything goes as expected.

Thank you

manusa pushed a commit that referenced this issue Oct 18, 2022
* fix #4460 removing the split packages

* fix #4460 running spotless

* fix #4460 renaming DefaultKubernetesClientTest
@mayankkulshreshtha
Copy link

java.lang.NoClassDefFoundError: io/fabric8/kubernetes/model/jackson/UnmatchedFieldTypeModule
at io.fabric8.kubernetes.client.utils.KubernetesSerialization.(KubernetesSerialization.java:68) ~[kubernetes-client-api-6.10.0.jar:?]
at io.fabric8.kubernetes.client.utils.KubernetesSerialization.(KubernetesSerialization.java:76) ~[kubernetes-client-api-6.10.0.jar:?]
at io.fabric8.kubernetes.client.KubernetesClientBuilder.(KubernetesClientBuilder.java:51) ~[kubernetes-client-api-6.10.0.jar:?]

@manusa
Copy link
Member

manusa commented Feb 29, 2024

java.lang.NoClassDefFoundError: io/fabric8/kubernetes/model/jackson/UnmatchedFieldTypeModule at io.fabric8.kubernetes.client.utils.KubernetesSerialization.(KubernetesSerialization.java:68) ~[kubernetes-client-api-6.10.0.jar:?] at io.fabric8.kubernetes.client.utils.KubernetesSerialization.(KubernetesSerialization.java:76) ~[kubernetes-client-api-6.10.0.jar:?] at io.fabric8.kubernetes.client.KubernetesClientBuilder.(KubernetesClientBuilder.java:51) ~[kubernetes-client-api-6.10.0.jar:?]

Hi @mayankkulshreshtha

Make sure yuo don't have convergence issues with Spring Cloud or any other dependency that may bring in their own Kubernetes Client Version.

https://github.com/fabric8io/kubernetes-client/blob/main/doc/FAQ.md#ive-tried-adding-a-dependency-to-kubernetes-client-but-im-still-getting-weird-class-loading-issues-what-gives

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 a pull request may close this issue.

5 participants