Fix issue #194: Remove fields with value 0 when conditionals change #103
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.
PR-194: Remove fields present in actual but missing in expected (handles zero-value cases like "0")
Summary
This change fixes a bug where fields with "zero-like" values (e.g.,
"0") were not removed when conditionals stop rendering them in templates. The comparison/patch logic previously didn’t emit deletions for keys missing in expected but present in actual.Implementation
9569465createPatchWithNullFields+addNullFieldsForMissinginjectnullinto JSON merge patches for keys present only in actual, so Kubernetes removes them.How reviewers can reproduce and verify (using my operator fork)
feature/finalizer-fixes-template-filtering-testsexamples/test-and-logic/ISSUE-194-ROOT-CAUSE-SUMMARY.mdexamples/test-and-logic/ISSUE-194-FIX-IMPLEMENTATION.mdexamples/test-and-logic/ISSUE-194-VERIFICATION-GUIDE.mdWire the fixed dependency
Option A (track branch):
# In namespace-configuration-operator go get github.com/ephico2real2/operator-utils@fix-issue-194-field-removal-zero-value go mod tidyOption B (pin exact commit via pseudo-version):
check examples/test-and-logic/ISSUE-194-FIX-IMPLEMENTATION.md for directions.
Build & run locally (in namespace-configuration-operator)
Test config
Verification steps
Real-time proof (timestamps + full YAML)
Server-side apply captures
managedFields.time:Capture and diff YAML:
Live YAML excerpt (after fix — allow-pvc=true) and the original template snippet are embedded in:
examples/test-and-logic/ISSUE-194-VERIFICATION-GUIDE.mdCommands used to identify the correct module
Impact & compatibility
nulldeletes); respects excluded paths; supports nested structures.Checklist
Fix implemented with recursive null-injection for missing keys
Verified locally and on a cluster with before/after YAML diffs
No changes to public API of operator-utils
Backwards compatible
Add createPatchWithNullFields to set missing fields to null in merge patches
Add addNullFieldsForMissing helper to recursively handle nested structures
Ensures fields are properly removed when they should be absent
Fixes bug where fields with value "0" are not removed when conditionals change from true to false