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 · 11 comments
Open

Content type for PATCH sub resource requests is incorrect #3143

suman-ganta opened this issue Mar 1, 2024 · 11 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

@k8s-triage-robot
Copy link

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 5, 2024
@suman-ganta
Copy link
Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 5, 2024
@k8s-triage-robot
Copy link

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 3, 2024
@rjeberhard
Copy link
Contributor

I'm touching this bug as I'm hitting the same issue.

@brendandburns, would you be open to a PR to make GenericKubernetesApi.updateStatus() and patch() use the PatchUtils internally?

@k8s-triage-robot
Copy link

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/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was 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

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 4, 2024
@mnlipp
Copy link

mnlipp commented Oct 4, 2024

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Oct 4, 2024
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

6 participants