Repository navigation
fix(controller): delete the webhook configuration of the old kind - #2152
Conversation
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>
There was a problem hiding this comment.
🟢 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 Report✅ All modified and coverable lines are covered by tests. 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
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:
|
viccuad
left a comment
There was a problem hiding this comment.
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>
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