Skip to content

fix: use explicit JSON merge patch type in merge patch operations - #3514

Open
csviri wants to merge 1 commit into
mainfrom
json-patch-fix
Open

fix: use explicit JSON merge patch type in merge patch operations#3514
csviri wants to merge 1 commit into
mainfrom
json-patch-fix

Conversation

@csviri

@csviri csviri commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Fabric8's no-context patch() fetches the resource from the server and
computes an RFC 6902 JSON Patch diff, which removes the fields omitted
from a partial resource (including the whole spec). Pass an explicit
JSON_MERGE PatchContext so the non-status merge patch operations really
send application/merge-patch+json.

Fabric8's no-context patch() fetches the resource from the server and
computes an RFC 6902 JSON Patch diff, which removes the fields omitted
from a partial resource (including the whole spec). Pass an explicit
JSON_MERGE PatchContext so the non-status merge patch operations really
send application/merge-patch+json.
Copilot AI review requested due to automatic review settings July 27, 2026 16:23
@openshift-ci
openshift-ci Bot requested review from metacosm and xstefank July 27, 2026 16:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Ensures JSON Merge Patch operations use an explicit Fabric8 PatchContext with PatchType.JSON_MERGE so partial-resource merge patches don’t behave like JSON Patch diffs (which can delete omitted fields).

Changes:

  • Use patch(PatchContext.of(PatchType.JSON_MERGE)) for all JSON merge patch operations in ResourceOperations.
  • Add unit tests asserting merge patch calls never use no-context patch() and always use PatchType.JSON_MERGE.
  • Add an integration test scenario that patches only metadata (labels) and asserts omitted spec fields remain intact.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/resourceoperations/ResourceOperationsReconciler.java Adds a new operation that performs a metadata-only merge patch using a partial resource.
operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/resourceoperations/ResourceOperationsIT.java Adds IT coverage ensuring partial merge patches don’t delete omitted fields like spec.
operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/ResourceOperationsTest.java Strengthens unit assertions around merge patch behavior and patch type selection.
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceOperations.java Switches merge patch calls to use explicit JSON merge patch type via PatchContext.

Comment on lines +44 to +45
public static final String LABEL_KEY = "resolved";
public static final String LABEL_VALUE = "true";
Comment on lines +484 to +489
/** Answer that executes the update operation passed to the caching methods of an event source. */
@SuppressWarnings("rawtypes")
private static Answer<Object> runUpdateOperation() {
return invocation ->
((UnaryOperator) invocation.getArgument(1)).apply(invocation.getArgument(0));
}
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

Successfully merging this pull request may close these issues.

jsonMergePatch operations use Fabric8 JSON Patch semantics and can remove spec

2 participants