fix: use explicit JSON merge patch type in merge patch operations - #3514
Open
csviri wants to merge 1 commit into
Open
fix: use explicit JSON merge patch type in merge patch operations#3514csviri wants to merge 1 commit into
csviri wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
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 inResourceOperations. - Add unit tests asserting merge patch calls never use no-context
patch()and always usePatchType.JSON_MERGE. - Add an integration test scenario that patches only metadata (labels) and asserts omitted
specfields 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)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.