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

Client 20.0.1 changes to non-required Map fields break basic use cases #3356

Closed
rjeberhard opened this issue Apr 25, 2024 · 2 comments
Closed

Comments

@rjeberhard
Copy link
Contributor

Describe the bug
The following example Java class results in an exception when run:

import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.Configuration;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.V1Container;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1Pod;
import io.kubernetes.client.openapi.models.V1PodSpec;
import io.kubernetes.client.util.Config;
import java.io.IOException;
import java.util.Arrays;

public class PodExample {
    public static void main(String[] args) throws IOException, ApiException {
        ApiClient client = Config.defaultClient();
        Configuration.setDefaultApiClient(client);

        CoreV1Api api = new CoreV1Api();
        api.createNamespacedPod("test-namespace",
            new V1Pod().metadata(new V1ObjectMeta().name("test-pod").namespace("test-namespace"))
                    .spec(new V1PodSpec().addContainersItem(
                            new V1Container().name("test-container").image("busybox:1.28")
                                    .command(Arrays.asList("sh", "-c", "echo \"Hello, Kubernetes\""))))).execute();
    }
}

Assuming that you've created the "test-namespace" namespace, the output is:

Exception in thread "main" io.kubernetes.client.openapi.ApiException: Message: 
HTTP response code: 403
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"pods \"test-pod\" is forbidden: pod rejected: Pod Overhead set without corresponding RuntimeClass defined Overhead","reason":"Forbidden","details":{"name":"test-pod","kind":"pods"},"code":403}

HTTP response headers: {audit-id=[db4aab6c-a8c6-43c4-955d-bc49625c2548], cache-control=[no-cache, private], content-length=[272], content-type=[application/json], date=[Thu, 25 Apr 2024 19:24:02 GMT], x-kubernetes-pf-flowschema-uid=[190a5b0e-20ba-45d3-a8d8-5fdb90717772], x-kubernetes-pf-prioritylevel-uid=[655b2c69-cb8a-4115-a2b1-885c91d769a7]}
	at io.kubernetes.client.openapi.ApiClient.handleResponse(ApiClient.java:1116)
	at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:1029)
	at io.kubernetes.client.openapi.apis.CoreV1Api.createNamespacedPodWithHttpInfo(CoreV1Api.java:10876)
	at io.kubernetes.client.openapi.apis.CoreV1Api.access$22100(CoreV1Api.java:77)
	at io.kubernetes.client.openapi.apis.CoreV1Api$APIcreateNamespacedPodRequest.execute(CoreV1Api.java:10972)
	at PodExample.main(PodExample.java:23)

Process finished with exit code 1

I believe the reason is that classes like V1PodSpec set non-required Map-typed fields to a new HashMap rather than leaving them as null.

We see similar unexpected behavior with Yaml.dump(). For instance, if you create a V1CustomResourceDefinition and populate a schema then Yaml.dump() will output fields like "definitions" and "dependencies" that are not legal to specify.

Client Version
e.g. 20.0.1

Kubernetes Version
e.g. 1.28.2

Java Version
e.g. Java 8

To Reproduce
Run the reproducer after creating the namespace.

Expected behavior
I'm hoping that these fields can be null by default as they were in 19.0.1.

KubeConfig
If applicable, add a KubeConfig file with secrets redacted.

Server (please complete the following information):

  • OS: [e.g. MacOS]
  • Environment [e.g. container]
  • Cloud [e.g. Oracle OKE]

Additional context
Add any other context about the problem here.

@rjeberhard rjeberhard changed the title Client 20.0.1 changes to non-required Map fields breaks basic use cases Client 20.0.1 changes to non-required Map fields break basic use cases Apr 25, 2024
@brendandburns
Copy link
Contributor

This is a duplicate of #3076 closing in favor of that issue.

tl;dr; I think this is a bug in the upstream kubernetes api server.

@rjeberhard
Copy link
Contributor Author

Thanks, @brendandburns. I'll put my thoughts over there. I'm going to argue in favor of not treating this as a bug in the upstream server and pushing for a fix in the template generation.

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

No branches or pull requests

2 participants