Skip to content

fix: skip objects without a key when collecting expectations - #4938

Open
ogulcanaydogan wants to merge 1 commit into
open-policy-agent:masterfrom
ogulcanaydogan:fix/readiness-collector-skip-unkeyable
Open

ogulcanaydogan wants to merge 1 commit into
open-policy-agent:masterfrom
ogulcanaydogan:fix/readiness-collector-skip-unkeyable

Conversation

@ogulcanaydogan

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
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. 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.

@codecov-commenter

codecov-commenter commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.38%. Comparing base (3350319) to head (6937cc6).
⚠️ Report is 962 commits behind head on master.

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     
Flag Coverage Δ
unittests 54.38% <100.00%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JaydipGabani JaydipGabani added the orka:review Opt in to Orka review of this pull request and subsequent pushes label Nov 24, 2026

@gatekeeper-orka-reviewer gatekeeper-orka-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 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.
  • P2: Verify that collection stops the deleted template’s constraint tracker (pkg/readiness/ready_tracker_unit_test.go:206) — 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.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>
@ogulcanaydogan
ogulcanaydogan force-pushed the fix/readiness-collector-skip-unkeyable branch from 837b733 to 6937cc6 Compare December 2, 2026 18:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orka:review Opt in to Orka review of this pull request and subsequent pushes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readiness: one ConstraintTemplate without a constraint kind stops the collection of deleted templates

3 participants