kubernetes-client: java.lang.NoClassDefFoundError: io/fabric8/kubernetes/internal/KubernetesDeserializer

With 5.8.0 running on OSGI we get a NoClassDefFoundError.

The io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl from the kubernetes-client module is referencing the io.fabric8.kubernetes.internal.KubernetesDeserializer class from the kubernetes-model-core module which declares the package io.fabric8.kubernetes.internal as private and doesn’t export it.


java.lang.NoClassDefFoundError: io/fabric8/kubernetes/internal/KubernetesDeserializer                                                                                                                                   
     at io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl.<init>(HasMetadataOperationsImpl.java:62)                                                                                                    
     at io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl.<init>(HasMetadataOperationsImpl.java:39)                                                                                                    
     at io.fabric8.kubernetes.client.ResourceHandlerImpl.operation(ResourceHandlerImpl.java:70)                                                                                                                          
     at io.fabric8.kubernetes.client.Handlers.getOperation(Handlers.java:65)                                                                                                                                             
     at io.fabric8.kubernetes.client.Handlers.getNonListingOperation(Handlers.java:69)                                                                                                                                   
     at io.fabric8.kubernetes.client.V1AuthorizationAPIGroupClient.selfSubjectAccessReview(V1AuthorizationAPIGroupClient.java:40)

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 27 (15 by maintainers)

Most upvoted comments

Sorry - I am currently OOO and I don’t have access to any machine to test it. As far as I recall, we used the bundle jar back then when the issue has occured. I will try to verify this once again at the beginning of next week.

Hello guys, I have tried preparing a reproducer project https://github.com/rohankanojia-forks/kubernetes-client-osgi-demo . Basically, I’m just creating a Book custom resource. I’m sure control that goes through HasMetadataOperationsImpl and custom resource class is registered via KubernetesDeserializer

  public void createBook() {
    try (KubernetesClient client = new DefaultKubernetesClient()) {
      MixedOperation<Book, BookList, Resource<Book>> fooClient = client.customResources(Book.class, BookList.class);
      Book foo = fooClient.load(getClass().getResourceAsStream("/test-foo.yml")).get();
      foo.getMetadata().setName("book" + count);
      fooClient.inNamespace("default").createOrReplace(foo);
    }
  }

I deployed this application to Kubernetes using Kubernetes Maven Plugin where it’s run in a Karaf based image:

$ eval $(minikube -p minikube docker-env)
$ mvn k8s:build k8s:resource k8s:apply
...
$ kubectl get pods
NAME                                          READY   STATUS    RESTARTS   AGE
kubernetes-client-osgi-demo-db47c6f76-p77zm   1/1     Running   0          14s

As expected I was able to see Book resources being created every second:

kubernetes-client-osgi-demo : $ kubectl get book -w
NAME     AGE
book1    49s
book10   4s
book2    44s
book3    39s
book4    34s
book5    29s
book6    24s
book7    19s
book8    14s
book9    9s
book11   0s
book12   0s

Could you please check if I have prepared the reproducer correctly 🙏 ? It could be possible that I have missed something since I’m not familiar with OSGi.

Same for me. Even when using the bundle version, the exception occurs at runtime.

From an OSGi point of view the issue seems to be clear: bundle A (client jar) uses a class (deserializer) from bundle B (model jar) which is not exported/imported properly. Because the import cannot be resolved at runtime, the exception is raised by the JVM.

To check why the existing integration test is passing successfully, it could be helpful to verify the class loader (I assume it is using a shared class loader whereas each bundle has its own in an OSGi environment).

I’ll get it tested on Monday, thanks for looking into it!

@hakontro @hanneshofmann : Would it be possible for you to also try out using kubernetes-client-*-bundle.jar instead of kubernetes-client*.jar to see if it resolves your issue?

https://github.com/fabric8io/kubernetes-client/blob/7f76db5f80e8a824526a5e83e2938c259c904776/platforms/karaf/itests/pom.xml#L36-L47