Repository navigation
fix: skip objects without a key when collecting expectations - #4938
ogulcanaydogan wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4938 +/- ##
==========================================
- Coverage 54.49% 54.38% -0.12%
==========================================
Files 134 311 +177
Lines 12329 26151 +13822
==========================================
+ Hits 6719 14221 +7502
- Misses 5116 10698 +5582
- Partials 494 1232 +738
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Orka review
Verdict: needs_changes
Confidence: high
Head: 837b7334
The collector now makes progress past a malformed template, but it can cancel an expectation for a template that still exists. The regression test also misses cleanup of the deleted template’s constraint tracker.
Findings
- P1: Preserve expectations for a live template whose key cannot be read (
pkg/readiness/ready_tracker.go:546) — A key lookup failure is not evidence of deletion. Startup lists typed ConstraintTemplates, and both typed branches ofkeyForaccept an empty constraint kind (pkg/readiness/object_tracker.go:391andpkg/readiness/object_tracker.go:397). The unstructured relist rejects that same object. The newcontinueleaves its expectation inunsatisfiedmap, so the cancellation loop drops it without a controller observation, even with--readiness-retries=-1. The same problem occurs if a previously keyed template loses its kind between lists. — Recommendation: When key extraction fails, use the listed object’s namespace and name to exclude matching expectations from cancellation, then continue collecting unrelated deletions. Add a regression with two pending templates: one still listed without a kind and one absent. Assert that only the absent one is canceled. - P2: Verify that collection stops the deleted template’s constraint tracker (
pkg/readiness/ready_tracker_unit_test.go:206) — Passingnilfor cleanup hides a lifecycle bug in the scenario this test covers. Production callscleanup(gvk)atpkg/readiness/ready_tracker.go:562with the listedConstraintTemplateGVK, but the child tracker and its runner are keyed by the generated constraint GVK (k.gvk). If the template disappears before its constraint CRD exists, its template expectation is canceled while the child keeps retrying LIST until shutdown. — Recommendation: Passk.gvkto cleanup. Extend the regression to capture the callback argument and assert that cleanup runs exactly once for the deleted template’s generated constraint kind.
Tests
Status: not_run
No validation image was configured for this review.
| // expectations, so it must not stop the other deleted objects from | ||
| // being collected. | ||
| log.Error(err, "skipping object without a key in collectForObjectTracker", "name", o.GetName(), "namespace", o.GetNamespace(), "gvk", gvk, "tracker", trackerName) | ||
| continue |
There was a problem hiding this comment.
P1: Preserve expectations for a live template whose key cannot be read
A key lookup failure is not evidence of deletion. Startup lists typed ConstraintTemplates, and both typed branches of keyFor accept an empty constraint kind (pkg/readiness/object_tracker.go:391 and pkg/readiness/object_tracker.go:397). The unstructured relist rejects that same object. The new continue leaves its expectation in unsatisfiedmap, so the cancellation loop drops it without a controller observation, even with --readiness-retries=-1. The same problem occurs if a previously keyed template loses its kind between lists.
Recommendation: When key extraction fails, use the listed object’s namespace and name to exclude matching expectations from cancellation, then continue collecting unrelated deletions. Add a regression with two pending templates: one still listed without a kind and one absent. Assert that only the absent one is canceled.
| t.Fatal("templates tracker should not be satisfied before the collection") | ||
| } | ||
|
|
||
| if err := rt.collectForObjectTracker(context.Background(), rt.templates, nil, "ConstraintTemplate"); err != nil { |
There was a problem hiding this comment.
P2: Verify that collection stops the deleted template’s constraint tracker
Passing nil for cleanup hides a lifecycle bug in the scenario this test covers. Production calls cleanup(gvk) at pkg/readiness/ready_tracker.go:562 with the listed ConstraintTemplate GVK, but the child tracker and its runner are keyed by the generated constraint GVK (k.gvk). If the template disappears before its constraint CRD exists, its template expectation is canceled while the child keeps retrying LIST until shutdown.
Recommendation: Pass k.gvk to cleanup. Extend the regression to capture the callback argument and assert that cleanup runs exactly once for the deleted template’s generated constraint kind.
collectForObjectTracker returned on the first object that cannot be keyed, such as a ConstraintTemplate without a constraint kind. That one object stopped the collection of the expectations of every deleted template on each pass, so the templates tracker could stay unsatisfied and readiness could be blocked. Log it and continue. Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@gmail.com>
837b733 to
6937cc6
Compare
What this PR does / why we need it:
collectForObjectTrackerreturned on the first object that cannot be keyed, such as a ConstraintTemplate without a constraint kind. That one object stopped the collection of the expectations of every deleted template on each pass, so the templates tracker could stay unsatisfied and readiness could be blocked. It now logs the object and continues.If returning the error was intended (the comment above the LIST says a failed LIST must not stop other kinds), I'm happy to change this to whatever you prefer.
Which issue(s) this PR fixes (optional, using
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when the PR gets merged):Fixes #4937
Added
Test_Tracker_collectForObjectTracker_SkipsObjectWithoutKey: one template without a kind in the lister and one expected template that is not there. It fails on master (the collector returns the keying error and the expectation is not canceled) and passes with this change.go test -race ./pkg/readiness/...and golangci-lint on the new code are clean.