kubernetes-client / java

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

CustomObjectsApi.getNamespacedCustomObject does not return metadata in the latest version of the client #3589

Open SachinHg opened 3 months ago

SachinHg commented 3 months ago

Describe the bug We use CustomObjectsApi to deal with the CRUD operations for istio related resources. Since upgrading the k8s client version to 20.0.1, the CustomObjectsApi.getNamespacedCustomObject does not return metadata as part of the response. This used to work in the older version of the client 1.12.

Client Version 20.0.1

Kubernetes Version 1.29

Java Version Java 21

To Reproduce Steps to reproduce the behavior:

public class CustomObjectResourceVersion {

public static void main(String[] args) {
    try {
        ApiClient client = Config.defaultClient();
        io.kubernetes.client.openapi.Configuration.setDefaultApiClient(client);

        CustomObjectsApi customObjectsApi = new CustomObjectsApi(client);

        String group = "networking.istio.io";
        String version = "v1beta1";
        String namespace = "default"; 
        String plural = "virtualservices";
        String name = "vs-name"; 

        Map<String, Object> customObject = (Map<String, Object>) customObjectsApi.getNamespacedCustomObject(
                group,
                version,
                namespace,
                plural,
                name
        );

       Gson gson = new Gson();
       String vsJsonString = gson.toJson(customObject);
       VirtualService existingVirtualService = gson.fromJson(vsJsonString, VirtualService.class);
      String resourceVersion = existingVirtualService.getMetadata().getResourceVersion();
} catch(Exception e) {
      e.printStackTrace();
}

}

Expected behavior It should return the metadata.

Output of raw JSON

{\\\"group\\\":\\\"networking.istio.io\\\",\\\"version\\\":\\\"v1beta1\\\",\\\"namespace\\\":\\\"namespace-name\\\",\\\"plural\\\":\\\"virtualservices\\\",\\\"name\\\":\\\"example-virtualservice-name\\\"} \"}
brendandburns commented 3 months ago

Can you print the raw JSON object and attach it to this issue?

brendandburns commented 3 months ago

Additionally, can you try the 20.0.1-legacy version and see if that works?

SachinHg commented 3 months ago

@brendandburns updated the issue description with the raw json object. I can also confirm that this works without any problem with 20.0.1-legacy

brendandburns commented 3 months ago

For the raw JSON, I was hoping for the JSON that came back from the API server, not the JSON output of the client side object.

Can you provide the JSON from the server so that we can determine if there is some sort of parsing error?

For context, the code generator changed in the 20 release, which is likely the difference causing this, but I'm not certain exactly what is going wrong.

k8s-triage-robot commented 1 week ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale