Skip to content

Cant patch a deployment using Java Kubernetes API library #4328

@max-b2c2

Description

@max-b2c2

Describe the bug
Unable to patch a namespace deployment using java kubernetes library. Results in HTTP 415, issue being incorrect Content-Type header set by library.

Client Version
24.0.0

Kubernetes Version
1.33.5

Java Version
17

To Reproduce

ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
AppsV1Api api = new AppsV1Api(client);

String timeNow = java.time.Instant.now().toString();
String patchJson = """
                    {
                        "spec": {
                            "template": {
                                "metadata": {
                                    "annotations": {
                                        "kubectl.kubernetes.io/restartedAt": "%s"
                                    }
                                }
                            }
                        }
                    }
""".formatted(timeNow);

AppsV1Api.APIpatchNamespacedDeploymentRequest apIpatchNamespacedDeploymentRequest =
api.patchNamespacedDeployment(
"some-deployment-name",
"some-namespace",
new V1Patch(patchJson));

apIpatchNamespacedDeploymentRequest.execute();

Expected behavior
HTTP 200 resulting in deployment patch

KubeConfig
wont provide for now

Server (please complete the following information):

  • OS: macOS Sequoia 15.5
  • Environment: local
  • Cloud ???

Additional context
it seems the fault lies at io.kubernetes.client.openapi.apis.AppsV1Api:9231, it sets Content-Type header value to application/json where it should be application/strategic-merge-patch+json according to docs here
This has a workaround but that shouldnt be the case

PatchUtils.patch(
                    V1Deployment.class,
                    () -> client.buildCall(
                            null,
                            String.format(
                                    "/apis/apps/v1/namespaces/%s/deployments/%s",
                                    namespaceParam,
                                    deploymentParam),
                            "PATCH",
                            new ArrayList<>(),
                            new ArrayList<>(),
                            new V1Patch(PATCH_JSON.formatted(timeNow)),
                            HEADERS,
                            new HashMap<>(),
                            new HashMap<>(),
                            new String[] {"BearerToken"},
                            null),
                    "application/strategic-merge-patch+json");

and this issue was mentioned twice already here and here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions