kubernetes-client / java

Official Java client library for kubernetes
http://kubernetes.io/
Apache License 2.0
3.46k stars 1.84k forks source link

Unknown apiVersionKind XXXX is it registered? #3364

Open LikLiComing opened 2 months ago

LikLiComing commented 2 months ago

Solution!!!!!!!!!!!!!!!!!!!!!!! Use "ClassLoader classLoader = Thread.currentThread().getContextClassLoader();" instead of "Yaml.class.getClassLoader()", and it works!!!! so please fix this issue, thanks image

Describe the bug Unknown apiVersionKind XXXClass is it registered? and "No kubernetes api model classes found from classloader, this may break automatic api discovery"

Client Version since from 15.0.1 as I know

Kubernetes Version N/A

Java Version Java 8

To Reproduce as it is deployed to server through CI and CD in way of JAR, we got wrong because of 'Yaml.class.getClassLoader()'

Expected behavior get all KubernetesObject class in package 'io.kubernetes.client.openapi.models', but fail, since It scan the running server JAR, not "java-client.jar"!

KubeConfig N/A

Server (please complete the following information):

Additional context N/A

brendandburns commented 2 months ago

The class loading stuff is kind of hacky no matter what because of the dependency on classes. I'm not sure that this is better (e.g. fewer situations where it doesn't work) vs anything else, but I'm open to a discussion or pointers for why this is better.

LikLiComing commented 1 month ago

agree, this is uderlying code, we should be very careful for each single change, you can find more details in the QA below, please use it as reference and do enough testing, like 'try to find an overload of the method that accepts the class loader as a parameter.', look forwards to your team's effort. Thanks for your attention, brendandburns. image

https://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader

godnesszsp commented 1 month ago

"I'm facing an issue where the Kubernetes Java client (client-java) is loaded as expected when running in IntelliJ IDEA locally, but after packaging the application into a JAR via Maven or building a Docker image and then attempting to run it, the client-java JAR is not being loaded correctly. Despite this, I've confirmed that the client-java JAR is correctly included within both the Maven-built JAR and the Docker image.