Skip to content

feat: validating admission webhook for v1alpha2 Silences - #661

Open
QuentinBisson wants to merge 4 commits into
feat/mutating-webhook-forced-matchersfrom
feat/validating-webhook
Open

feat: validating admission webhook for v1alpha2 Silences#661
QuentinBisson wants to merge 4 commits into
feat/mutating-webhook-forced-matchersfrom
feat/validating-webhook

Conversation

@QuentinBisson

Copy link
Copy Markdown
Contributor

Summary

Stacked on #660. Adds a validating webhook that enforces business rules the CRD OpenAPI schema cannot express.

Validations:

  • Duplicate matchers — same name+value+matchType appearing more than once is rejected with the index of the duplicate
  • Regex validity=~ and !~ matchers must compile as valid Go regular expressions; bad patterns are caught at admission, not silently at sync time
  • valid-until parseability — annotation must be RFC3339 or date-only (YYYY-MM-DD); bad format returns a clear error with accepted examples
  • Non-past expiry on CREATE — creating an already-expired silence is rejected immediately; UPDATE allows past values so the controller can expire silences naturally

Enforces business rules not expressible in the CRD OpenAPI schema:
- No duplicate matchers (same name+value+matchType)
- Regex matchers (=~ / !~) must compile as valid Go regular expressions
- valid-until annotation must parse as RFC3339 or date-only
- On CREATE: valid-until must not already be in the past
- UPDATE allows past valid-until so the controller expires silences naturally

Enabled via --webhook-validating-enabled=true (set by Helm when
webhook.enabled=true). Shares TLS cert, Service, and cert-manager
Certificate with the mutating webhook.

18 unit tests covering all validation paths and multi-error aggregation.
config/webhook/manifests.yaml updated via controller-gen.
webhook.mutating.enabled and webhook.validating.enabled (both default true)
allow each webhook type to be toggled independently under the shared
webhook.enabled master switch.

- MutatingWebhookConfiguration only rendered when both webhook.enabled
  and webhook.mutating.enabled are true
- ValidatingWebhookConfiguration only rendered when both webhook.enabled
  and webhook.validating.enabled are true
- --webhook-cel-rules only passed to the operator when mutating.enabled
- --webhook-validating-enabled only passed when validating.enabled

Use cases:
  validating only (no CEL rules yet): mutating.enabled: false
  mutating only (skip validation):    validating.enabled: false
  both (default):                     no overrides needed
celRules belongs to the mutating webhook, not the webhook section as a
whole. Move it to webhook.mutating.celRules and relocate all examples
and CEL documentation to sit directly alongside the field.

Also updates values.schema.json and the deployment template accordingly.

Signed-off-by: QuentinBisson <quentin@giantswarm.io>
@QuentinBisson
QuentinBisson marked this pull request as ready for review April 8, 2026 12:57
@QuentinBisson
QuentinBisson requested a review from a team as a code owner April 8, 2026 12:57
@QuentinBisson QuentinBisson self-assigned this Apr 8, 2026
@QuentinBisson

Copy link
Copy Markdown
Contributor Author

Tested on graveler

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant