Skip to content

Verify WantDeleteCollections in TableTest - #3380

Open
pujitha24 wants to merge 1 commit into
knative:mainfrom
pujitha24:auto/issue-2455
Open

Verify WantDeleteCollections in TableTest#3380
pujitha24 wants to merge 1 commit into
knative:mainfrom
pujitha24:auto/issue-2455

Conversation

@pujitha24

Copy link
Copy Markdown

Fixes #2455

Motivation:
TableRow.WantDeleteCollections has existed since it was added to the
struct, but (r *TableRow) Test() never compared it against the actual
recorded DeleteCollection actions. A test author setting
WantDeleteCollections gets no verification at all: whether the
reconciler under test issues the expected DeleteCollection call, issues
the wrong one, or issues none, the test silently passes either way.

A maintainer comment on the issue speculated this couldn't be fixed
because of an upstream fake-client limitation
(kubernetes/kubernetes#105357), where DeleteCollection calls with a
label selector don't actually remove matching objects from the fake
ObjectTracker. That bug is real, but it's orthogonal to this issue:
reconciler/testing/actions.go's ActionsByVerb() already captures
delete-collection verb actions into Actions.DeleteCollections from
the fake clientset's recorded action list, independent of whether the
tracker actually performed the deletion. So the missing verification in
Test() is a separate, fixable gap in the test framework itself, not
blocked by the upstream issue.

Approach:
Add a verification block in Test(), alongside the existing
WantDeletes check, that compares r.WantDeleteCollections against
actions.DeleteCollections. DeleteCollectionActionImpl has no
GetName() (it targets a namespace + label/field selector, not a single
named object), so it can't reuse the WantDeletes comparison verbatim.
Instead, a new deleteCollectionKey helper builds a comparison key from
resource + label selector string + field selector string (+ namespace,
unless SkipNamespaceValidation is set), and the two sets of keys are
compared the same way WantDeletes/gotDeletes are. Nil label/field
selectors (as would result from a hand-written
DeleteCollectionActionImpl{} literal in a test's
WantDeleteCollections) are treated as labels.Everything() /
fields.Everything(), matching what client-go's own
NewDeleteCollectionActionWithOptions defaults them to internally, so
constructing a "delete everything" expectation doesn't panic on a nil
selector's .String().

This does not change behavior for any existing test: a repo-wide search
found no existing use of WantDeleteCollections anywhere in
knative/pkg, since it was never actually verified before. It only turns
a previously-silent no-op field into a working one, so tests written
against it going forward actually enforce their expectations.

Validation:
go build ./...
go test ./reconciler/... -count=1
go test ./webhook/psbinding/... -count=1
both pass. Added reconciler/testing/table_test.go with
TestDeleteCollectionKey, unit-testing the new helper directly:
constructor-built vs. hand-written-literal actions key identically,
nil-selector defaults match an explicit "everything" selector, and
namespace affects the key unless SkipNamespaceValidation is set.

/kind bug

Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com

Fixes knative#2455

Motivation:
`TableRow.WantDeleteCollections` has existed since it was added to the
struct, but `(r *TableRow) Test()` never compared it against the actual
recorded DeleteCollection actions. A test author setting
`WantDeleteCollections` gets no verification at all: whether the
reconciler under test issues the expected DeleteCollection call, issues
the wrong one, or issues none, the test silently passes either way.

A maintainer comment on the issue speculated this couldn't be fixed
because of an upstream fake-client limitation
(kubernetes/kubernetes#105357), where DeleteCollection calls with a
label selector don't actually remove matching objects from the fake
ObjectTracker. That bug is real, but it's orthogonal to this issue:
`reconciler/testing/actions.go`'s `ActionsByVerb()` already captures
`delete-collection` verb actions into `Actions.DeleteCollections` from
the fake clientset's recorded action list, independent of whether the
tracker actually performed the deletion. So the missing verification in
`Test()` is a separate, fixable gap in the test framework itself, not
blocked by the upstream issue.

Approach:
Add a verification block in `Test()`, alongside the existing
`WantDeletes` check, that compares `r.WantDeleteCollections` against
`actions.DeleteCollections`. `DeleteCollectionActionImpl` has no
`GetName()` (it targets a namespace + label/field selector, not a single
named object), so it can't reuse the `WantDeletes` comparison verbatim.
Instead, a new `deleteCollectionKey` helper builds a comparison key from
resource + label selector string + field selector string (+ namespace,
unless `SkipNamespaceValidation` is set), and the two sets of keys are
compared the same way `WantDeletes`/`gotDeletes` are. Nil label/field
selectors (as would result from a hand-written
`DeleteCollectionActionImpl{}` literal in a test's
`WantDeleteCollections`) are treated as `labels.Everything()` /
`fields.Everything()`, matching what client-go's own
`NewDeleteCollectionActionWithOptions` defaults them to internally, so
constructing a "delete everything" expectation doesn't panic on a nil
selector's `.String()`.

This does not change behavior for any existing test: a repo-wide search
found no existing use of `WantDeleteCollections` anywhere in
knative/pkg, since it was never actually verified before. It only turns
a previously-silent no-op field into a working one, so tests written
against it going forward actually enforce their expectations.

Validation:
  go build ./...
  go test ./reconciler/... -count=1
  go test ./webhook/psbinding/... -count=1
both pass. Added `reconciler/testing/table_test.go` with
`TestDeleteCollectionKey`, unit-testing the new helper directly:
constructor-built vs. hand-written-literal actions key identically,
nil-selector defaults match an explicit "everything" selector, and
namespace affects the key unless `SkipNamespaceValidation` is set.

/kind bug

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 00:40
@knative-prow knative-prow Bot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 30, 2026

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@knative-prow

knative-prow Bot commented Jul 30, 2026

Copy link
Copy Markdown

Welcome @pujitha24! It looks like this is your first PR to knative/pkg 🎉

@knative-prow knative-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 30, 2026
@knative-prow

knative-prow Bot commented Jul 30, 2026

Copy link
Copy Markdown

Hi @pujitha24. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow

knative-prow Bot commented Jul 30, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pujitha24
Once this PR has been reviewed and has the lgtm label, please assign dprotaso for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow
knative-prow Bot requested review from dprotaso and skonto July 30, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WantDeleteCollections was never implemented in TableTest

2 participants