Skip to content

fix(controller): delete the webhook configuration of the old kind - #2152

Merged
flavio merged 2 commits into
mainfrom
fix/issue2149-orphan-webhook
Nov 12, 2026
Merged

flavio merged 2 commits into
mainfrom
fix/issue2149-orphan-webhook

Conversation

@jvanz

@jvanz jvanz commented Nov 11, 2026

Copy link
Copy Markdown
Member

Description

The controller created only the webhook configuration that matched spec.mutating. After a change of spec.mutating, the configuration of the old kind stayed in the cluster. Policy deletion removed only the configuration of the current kind. After the policy was deleted, the old configuration still sent requests to the policy server. The policy server answered 404, and the API server rejected the requests.

Reconcile now deletes the configuration of the other kind after it creates the current one. The cleanup on policy deletion, on a rejected namespaced policy, and on a missing policy server now removes both kinds.

Fix #2149

The controller created only the webhook configuration that matched
spec.mutating. After a change of spec.mutating, the configuration of
the old kind stayed in the cluster. Policy deletion removed only the
configuration of the current kind. After the policy was deleted, the
old configuration still sent requests to the policy server. The policy
server answered 404, and the API server rejected the requests.

Reconcile now deletes the configuration of the other kind after it
creates the current one. The cleanup on policy deletion, on a rejected
namespaced policy, and on a missing policy server now removes both
kinds.

Assisted-by: OpenCode (Claude Sonnet 5.5)
Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
@jvanz jvanz self-assigned this Nov 11, 2026
@jvanz
jvanz requested a review from a team as a code owner November 11, 2026 13:47
Copilot AI balanced review requested due to automatic review settings November 11, 2026 13:47
@github-project-automation github-project-automation Bot moved this to Pending review in Admission Controller Nov 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the stale-webhook cleanup changes.

No open issues 🎉

What changed in this PR

Fixes #2149 by removing stale webhook configurations when a policy’s spec.mutating changes, preventing leftover webhooks from blocking requests after policy deletion.

Changes:

  • Reconciles the current webhook kind before deleting the other kind.
  • Updates shared cleanup to remove both mutating and validating webhook configurations.
  • Adds unit tests for both policy kinds and webhook directions, plus an integration regression test for deletion with a stale webhook.
File Description
internal/​controller/​policy_subreconciler.go Removes obsolete webhook kinds during reconciliation and both kinds during cleanup.
internal/​controller/​policy_subreconciler_webhook_test.go Tests stale-webhook removal, cleanup of both kinds, and finalizer removal.

Review effort: Balanced

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.36%. Comparing base (9c669a0) to head (deee15e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2152      +/-   ##
==========================================
- Coverage   84.88%   82.36%   -2.53%     
==========================================
  Files         148      203      +55     
  Lines       20675    25951    +5276     
==========================================
+ Hits        17551    21374    +3823     
- Misses       3124     4577    +1453     
Flag Coverage Δ
go-tests 72.46% <100.00%> (?)
rust-tests 84.88% <ø> (ø)

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.

@viccuad viccuad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks good, I have silly quibbles, and one about not stopping after the first deletion if we have errors.

When the controller deletes the webhook configurations of a policy, it
now tries to delete both kinds and returns the errors together. Before,
an error on the first kind stopped the delete of the second kind.

Also rename the function to deleteWebhookConfigurations and reuse
newTestScheme in the tests.

Assisted-by: OpenCode (Claude Opus 5.5)
Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
@jvanz
jvanz requested review from flavio and viccuad and a balanced review from Copilot November 11, 2026 17:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the stale-webhook reconciliation and policy cleanup changes.

No open issues 🎉

Review effort: Balanced

@viccuad viccuad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@flavio
flavio merged commit c318138 into main Nov 12, 2026
60 of 61 checks passed
@flavio
flavio deleted the fix/issue2149-orphan-webhook branch November 12, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Old webhook configuration is left behind when a policy's spec.mutating changes

4 participants