Skip to content

fix: preserve array nulls in drift patches#5179

Open
puneetdixit200 wants to merge 2 commits into
rancher:mainfrom
puneetdixit200:fix/5020-drift-default-values
Open

fix: preserve array nulls in drift patches#5179
puneetdixit200 wants to merge 2 commits into
rancher:mainfrom
puneetdixit200:fix/5020-drift-default-values

Conversation

@puneetdixit200
Copy link
Copy Markdown

Refers to #5020

Preserve arrays while normalizing null-only map fields in drift patches. JSON merge patch arrays are replacement values, so recursively deleting nulls inside them can hide real drift such as container imagePullPolicy changes. Map-level null cleanup still handles Helm/default noise.

AI assistance: Used OpenAI GPT-5 to inspect and validate this focused change; I reviewed the code and tests.

Additional Information

Tested:

  • go test ./internal/cmd/agent/deployer/desiredset -run 'Test_Diff_NullPatch|Test_Diff_RemoveNullPatchFields' -count=1\n- go test ./internal/cmd/agent/deployer/desiredset -run 'Test_Diff_HPA' -count=1\n- go test ./internal/cmd/agent/deployer/desiredset -count=1\n- go test -shuffle=on ./internal/cmd/agent/deployer/desiredset -count=1\n- git diff --check\n\n### Checklist\n\n- [ ] I have updated the documentation via a pull request in the fleet-product-docs repository. Not applicable to this bug fix.

Assisted-by: OpenAI GPT-5
Signed-off-by: Puneet Dixit <puneetdixit200@users.noreply.github.com>
@puneetdixit200 puneetdixit200 requested a review from a team as a code owner May 21, 2026 08:19
Copilot AI review requested due to automatic review settings May 21, 2026 08:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a drift-detection regression (#5020) by adjusting null-normalization for JSON merge patch diffs so that arrays are preserved rather than recursively “cleaned,” avoiding cases where null-stripping inside arrays can hide real drift in keyed lists (e.g., container specs).

Changes:

  • Update removeNullPatchFields to preserve arrays as-is while still removing null-valued fields from map/object nodes.
  • Update and extend null-normalization tests to assert that nulls inside arrays (including null elements and null object fields) are preserved.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/cmd/agent/deployer/desiredset/diff.go Changes null-normalization logic to stop recursing into arrays to avoid masking drift in list-like fields.
internal/cmd/agent/deployer/desiredset/diff_null_test.go Updates expectations and adds coverage to ensure nulls inside arrays are preserved.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/cmd/agent/deployer/desiredset/diff.go Outdated
@puneetdixit200
Copy link
Copy Markdown
Author

AI-assisted follow-up on behalf of Puneet: pushed 2f8807d to clarify the removeNullPatchFields doc comment so it matches the array-preserving behavior.

Verified:

  • go test ./internal/cmd/agent/deployer/desiredset -run 'Test_Diff_NullPatch|Test_Diff_RemoveNullPatchFields' -count=1\n- gofmt -w internal/cmd/agent/deployer/desiredset/diff.go\n- git diff --check

Assisted-by: OpenAI GPT-5
Signed-off-by: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com>
@puneetdixit200 puneetdixit200 force-pushed the fix/5020-drift-default-values branch from 2f8807d to e92580f Compare May 23, 2026 19:59
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.

2 participants