Skip to content

docs: add custom object patch example - #4868

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
YuqiGuo105:docs/issue-3106-custom-object-patch
Aug 4, 2026
Merged

docs: add custom object patch example#4868
kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
YuqiGuo105:docs/issue-3106-custom-object-patch

Conversation

@YuqiGuo105

Copy link
Copy Markdown
Contributor

Summary

  • add a runnable example for patching namespaced custom objects through PatchUtils
  • document why generated custom-object PATCH requests should not be executed directly
  • accept the JSON Patch document as a file instead of hard-coding a resource-specific operation
  • add HTTP-level tests for namespaced and cluster-scoped custom objects
  • cover both JSON Patch and JSON Merge Patch media types

Problem

The generated CustomObjectsApi PATCH request defaults to Content-Type: application/json. Kubernetes PATCH endpoints require a patch-specific media type such as:

  • application/json-patch+json
  • application/merge-patch+json

Calling the generated request's execute() method directly can therefore result in 415 Unsupported Media Type, even when the patch document itself is valid.

Solution

The new PatchCustomObjectExample builds the generated custom-object request with buildCall(null) and executes it through PatchUtils.patch(...):

PatchUtils.patch(
    Object.class,
    () ->
        api.patchNamespacedCustomObject(
                group,
                version,
                namespace,
                plural,
                name,
                new V1Patch(patchJson))
            .buildCall(null),
    V1Patch.PATCH_FORMAT_JSON_PATCH,
    client);

The example reads the patch document from a user-provided file, so it does not assume a particular custom-resource schema or that optional metadata fields already exist.

The generated CustomObjectsApi.java and generated API documentation are intentionally left unchanged because those files would be overwritten during OpenAPI regeneration.

Tests

PatchUtilsTest now verifies that custom-object PATCH requests:

  • use the namespaced custom-object URL
  • preserve the original JSON Patch and JSON Merge Patch bodies
  • send the requested patch-specific Content-Type
  • deserialize the returned custom object
  • use the correct cluster-scoped custom-object URL

Validation performed:

  • ./mvnw -pl util,examples/examples-release-latest -am -Dtest=PatchUtilsTest -Dsurefire.failIfNoSpecifiedTests=false test
  • ./mvnw spotless:check
  • ./mvnw -pl util,examples/examples-release-latest -am clean test

Closes #3106.

@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 29, 2026
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 29, 2026
@YuqiGuo105
YuqiGuo105 marked this pull request as ready for review July 29, 2026 15:57
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 29, 2026
@brendandburns

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 4, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, YuqiGuo105

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 4, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit ca783b2 into kubernetes-client:master Aug 4, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to patch custom object with CustomObjectsApi.patchNamespacedCustomObject

2 participants