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

Content type for PATCH sub resource requests is incorrect #3143

Open
suman-ganta opened this issue Mar 1, 2024 · 5 comments
Open

Content type for PATCH sub resource requests is incorrect #3143

suman-ganta opened this issue Mar 1, 2024 · 5 comments

Comments

@suman-ganta
Copy link

Describe the bug
Patching status subresource of a CRD always fails with java client.

Client Version
20.0.0

Kubernetes Version
1.29.1

Java Version
Java 17

To Reproduce

var fooApi = new GenericKubernetesApi<>(Foo.class, FooList.class, "foo.bar", "v1", "foos", apiClient);
fooApi.updateStatus(foo, Foo::getStatus).throwsApiException().getObject();

Above code always fails with the following error

{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"the body of the request was in an unknown format - accepted media types include: application/json-patch+json, application/merge-patch+json, application/apply-patch+yaml","reason":"UnsupportedMediaType","code":415}

Expected behavior
This call is expected to succeed.

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

Server (please complete the following information):

  • OS: MacOS
  • Kind cluster

Additional context
The equivalent call from kubectl succeeds -

kubectl patch foos.foo.bar foo1 --subresource=status --type=json -p '[{"op":"replace","path":"/status","value":{"availableReplicas":20}}]'

In kubernetes/api/openapi.yaml, operationId: patchNamespacedCustomObject has the content type defined as application/json, which seem to be incorrect.

@brendandburns
Copy link
Contributor

Yeah, there's lots of errors in the upstream YAML. We try to fix them when we find them.

@brendandburns
Copy link
Contributor

Also, see the patch example here:

https://github.com/kubernetes-client/java/blob/master/examples/examples-release-latest/src/main/java/io/kubernetes/client/examples/PatchExample.java

@suman-ganta
Copy link
Author

Thanks @brendandburns. This path has worked. Working code snippet following my problem description for posterity

var customObjectsApi = new CustomObjectsApi(apiClient);
PatchUtils.patch(
    Foo.class,
    () ->
        customObjectsApi.patchNamespacedCustomObjectStatus(
             API_GROUP, "v1", foo.getMetadata().getNamespace(), "foos",
             foo.getMetadata().getName(),
             new V1Patch(String.format(JSON_PATH_TEMPLATE, newPodsSize))
        ).buildCall(null),
    V1Patch.PATCH_FORMAT_JSON_PATCH,
    customObjectsApi.getApiClient()
)

The GenericKubernetesApi path still need to be fixed.

@mnlipp
Copy link

mnlipp commented Mar 7, 2024

Using PatchUtils is a workaround at best. This bug also makes GenericKubernetesApi's patch and updateStatus unusable.

The cause is the wrong (static) choice of mimetype.

@mnlipp
Copy link

mnlipp commented Mar 7, 2024

This is a duplicate of #3106

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

3 participants