Unknown apiVersionKind XXXX is it registered?
Solution!!!!!!!!!!!!!!!!!!!!!!!
Use "ClassLoader classLoader = Thread.currentThread().getContextClassLoader();"
instead of "Yaml.class.getClassLoader()", and it works!!!!
so please fix this issue, thanks
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):
- OS: Linux
- Environment container
- Cloud Azure
Additional context N/A
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.
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.
https://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader
"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.
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle rotten - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Reopen this issue with
/reopen - Mark this issue as fresh with
/remove-lifecycle rotten - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
In response to this:
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied- After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied- After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closedYou can:
- Reopen this issue with
/reopen- Mark this issue as fresh with
/remove-lifecycle rotten- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
Now I have also encountered it, Java client version is 18.0.1.
Can also load it like this, hoping it can help others.
package io.kubernetes.client.util;
/**
* Model mapper loads pre-built kubernetes models from classpath and manages their mapping between
* their apiVersion and kind.
*/
public class ModelMapper {
static {
try {
initModelMap();
} catch (Exception ex) {
logger.error("Unexpected exception while loading classes", ex);
}
}
/**
* Registering concrete model classes by its apiGroupVersion (e.g. "apps/v1") and kind (e.g.
* "Deployment").
*
* <p>Note that the the so-called apiGroupVersion equals to the "apiVersion" in the kubenretes
* resource yamls.
*/
@Deprecated
public static void addModelMap(String apiGroupVersion, String kind, Class<?> clazz) {
String[] parts = apiGroupVersion.split("/");
if (parts.length <= 1) { // legacy api group
addModelMap("", apiGroupVersion, kind, clazz);
} else {
addModelMap(parts[0], parts[1], kind, clazz);
}
}
/**
* Registering concrete model classes by its group, version and kind (e.g. "apps", "v1",
* "Deployment")
*
* @param group the group
* @param version the version
* @param kind the kind
* @param clazz the clazz
*/
@Deprecated
public static void addModelMap(String group, String version, String kind, Class<?> clazz) {
preBuiltAddModelMap(group, version, kind, clazz);
}
/**
* Registering concrete model classes by its group, version and kind (e.g. "apps", "v1",
* "Deployment")
*
* @param group the group
* @param version the version
* @param kind the kind
* @param resourceNamePlural the resource name plural
* @param objClass the clazz
*/
public static void addModelMap(
String group,
String version,
String kind,
String resourceNamePlural,
Class<? extends KubernetesObject> objClass,
Class<? extends KubernetesListObject> objListClass) {
// TODO(yue9944882): consistency between bi-directional maps
classesByGVK.add(new GroupVersionKind(group, version, kind), objClass);
classesByGVR.add(new GroupVersionResource(group, version, resourceNamePlural), objClass);
if (objListClass != null) {
classesByGVK.add(new GroupVersionKind(group, version, kind + "List"), objListClass);
}
}
/**
* Registering concrete model classes by its group, version, kind and isNamespaced (e.g. "apps",
* "v1", "Deployment", true).
*
* @param group the group
* @param version the version
* @param kind the kind
* @param resourceNamePlural the resource name plural
* @param isNamespacedResource the is namespaced resource
* @param objClass the clazz
*/
public static void addModelMap(
String group,
String version,
String kind,
String resourceNamePlural,
Boolean isNamespacedResource,
Class<? extends KubernetesObject> objClass) {
addModelMap(group, version, kind, resourceNamePlural, objClass, null);
isNamespacedByClasses.put(objClass, isNamespacedResource);
}
public static void addModelMap(
String group,
String version,
String kind,
String resourceNamePlural,
Boolean isNamespacedResource,
Class<? extends KubernetesObject> objClass,
Class<? extends KubernetesListObject> objListClass) {
addModelMap(group, version, kind, resourceNamePlural, objClass, objListClass);
isNamespacedByClasses.put(objClass, isNamespacedResource);
}