Repository navigation
fix: do not read a CR's chart-rendered nulls as drift on the three-way merge - #1093
Merged
Merged
Conversation
…y merge When the chart is unchanged, the desired state of a custom resource is built by applying the new manifest to the live object as a JSON merge patch. A merge patch reads a null as "delete this key", so every null a chart renders, such as an unset value from its defaults, showed as a removal even though the upgrade sends no patch for it and the live object keeps it. Drop the new manifest's nulls before the merge. Signed-off-by: Valentin Fedoskin <valentin.fedoskin@gmail.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the custom-resource null-handling changes.
No open issues 🎉
What changed in this PR
This PR refines three-way merge handling for custom resources so unchanged chart-rendered nulls are not reported as drift, while preserving live values.
Changes:
- Remove null-valued object keys before building the desired state when the chart is unchanged; leave lists untouched.
- Add regression tests for chart-rendered nulls where the live field contains either null or a value.
| File | Description |
|---|---|
manifest/generate.go |
Adds recursive null-key removal to the chart-unchanged merge path. |
manifest/generate_test.go |
Adds two regression cases covering preservation of live fields. |
Review effort: Balanced
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.
Problem
Since #923, when the chart is unchanged,
createPatchbuilds the desired state of a custom resource asjsonpatch.MergePatch(current, new). A JSON merge patch readsnullas "delete this key". Every explicitnulla chart renders therefore shows as a removal under--three-way-merge, even though nothing has drifted: the chart is unchanged, so the upgrade sends no patch for the field, and the live object keeps it.This is common with charts that build a CR spec from defaults files. For example, grafana/k8s-monitoring 3.8.5 renders its
AlloyCRs withconfigMap.key: null,image.digest: null,podDisruptionBudget.minAvailable: nulland more. Every plan then shows on each collector:Fix
In the chart-unchanged path, drop the null-valued keys from the new manifest's objects before the merge. A null the chart renders leaves the field unset, so the live value, null or otherwise, is kept. Lists are left as they are, since a merge patch replaces them whole.
Tests
Two cases in
TestCreatePatchForUnstructured, both with the chart unchanged:go test ./...passes. I also checked against a live cluster: the Alloy diffs above are gone, and a real manual edit on a PrometheusRule is still reported.A related gap I left out of scope: a null inside a list element still reads as a change, because
MergePatchprunes nulls inside the patch's lists as well.