java icon indicating copy to clipboard operation
java copied to clipboard

Content type for PATCH sub resource requests is incorrect

Open suman-ganta opened this issue 1 year ago • 21 comments

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.

suman-ganta avatar Mar 01 '24 23:03 suman-ganta

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

brendandburns avatar Mar 01 '24 23:03 brendandburns

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

brendandburns avatar Mar 02 '24 16:03 brendandburns

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.

suman-ganta avatar Mar 03 '24 15:03 suman-ganta

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 avatar Mar 07 '24 09:03 mnlipp

This is a duplicate of https://github.com/kubernetes-client/java/issues/3106

mnlipp avatar Mar 07 '24 10:03 mnlipp

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-triage-robot avatar Jun 05 '24 11:06 k8s-triage-robot

/remove-lifecycle stale

suman-ganta avatar Jun 05 '24 13:06 suman-ganta

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-triage-robot avatar Sep 03 '24 13:09 k8s-triage-robot

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?

rjeberhard avatar Sep 04 '24 12:09 rjeberhard

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-triage-robot avatar Oct 04 '24 13:10 k8s-triage-robot

/remove-lifecycle rotten

mnlipp avatar Oct 04 '24 13:10 mnlipp

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-triage-robot avatar Jan 02 '25 14:01 k8s-triage-robot

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-triage-robot avatar Feb 01 '25 14:02 k8s-triage-robot

/remove-lifecycle rotten

mnlipp avatar Feb 01 '25 18:02 mnlipp

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-triage-robot avatar May 02 '25 19:05 k8s-triage-robot

/remove-lifecycle stale

mnlipp avatar May 03 '25 05:05 mnlipp

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-triage-robot avatar Aug 01 '25 05:08 k8s-triage-robot

/remove-lifecycle stale

mnlipp avatar Aug 01 '25 08:08 mnlipp

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-triage-robot avatar Oct 30 '25 08:10 k8s-triage-robot