Fix issue #194: Remove fields with value 0 when conditionals change - #103
ephico2real2 wants to merge 1 commit into
Conversation
- 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
|
Using server side apply would be enough, no need to pass nulls and compute diffs |
|
Agreed on the mechanism, with three things the PR would need to handle before "enough" holds. I measured the four cases below against a live API server with
So SSA solves #194 at the server and is also safer than this PR's null injection, which removes any live-only field (for example a ServiceAccount's controller-populated What the rework has to define:
A side benefit worth noting: with SSA the wholesale I'm happy to rework this PR onto |
|
@Kajot-dev one clarification so I rework this the way you intend. Which of these did you mean?
My understanding is that the object which loses the field is the managed object (the RoleBinding or ConfigMap the template renders), and the only code that writes it is this reconciler, so the apply would have to happen here (reading 1). How the consumer applies its own CR would not change what this reconciler sends. If you meant reading 2, could you say where the apply would go? |
|
Following the discussion here, the server-side-apply approach is now a separate PR: #104. It replaces the null injection and diff computation with one forced apply per reconcile under a fixed field manager, keeps |
|
@Kajot-dev, closing the loop on your suggestion: the server-side-apply rework is implemented in #104, with issue #105 as its tracking issue. It does what you described and no more than that: one forced apply per reconcile under a fixed field manager, so the API server removes a field the template stops rendering (the #194 case, Proof on #104: envtest-backed tests for every claim, three recorded review passes, and a live run through the namespace-configuration-operator (25 checks, including the I would prefer to close this PR in favour of #104; happy to split #104 (cache fix, path parsing, enforcer) if that helps the review. |
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