feat: Add validating admission webhook for TTL annotation validation #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Validating Admission Webhook for TTL Annotation Validation
Overview
This PR implements a validating admission webhook that validates TTL annotation format before objects are created or updated in Kubernetes. The webhook prevents invalid lease configurations from being applied to the cluster.
Architecture
Shared Webhook Design
ValidatingWebhookConfigurationKey Components
cmd/webhook/main.go) - Separate binary that runs as a deploymentpkg/webhook/validator.go) - Validates TTL format using existingParseFlexibleDurationpkg/webhook/config_manager.go) - Watches LeaseController CRs and manages webhook rulesFeatures
✅ Validates TTL annotation format (2d, 1h30m, 1w, etc.)
✅ Configurable per-GVK - Enable/disable validation for each resource type
✅ Configurable failure policy -
Ignore(soft fail) orFail(hard fail) per GVK✅ Automatic certificate management - Uses cert-manager for TLS certificates
✅ High availability - 2 replicas with proper health checks
✅ Security hardened - Non-root, no capabilities, seccomp profile
✅ Finalizer-based cleanup - Guaranteed removal of webhook config on deletion
✅ 100% backward compatible - Disabled by default, no breaking changes
Configuration Example
How It Works
Cleanup & Finalizers
The webhook uses Kubernetes finalizers to ensure proper cleanup:
webhook.object-lease-controller.ullberg.io/finalizerwhen webhook is enabledValidatingWebhookConfigurationValidatingWebhookConfigurationif no rules remainTesting
✅ All existing tests pass (100% coverage for controllers/metrics/util)
✅ Webhook binary compiles successfully
✅ Main controller binary compiles successfully
✅ golangci-lint: 0 issues
✅ No breaking changes to existing functionality
Security
Performance
Dependencies
Required
admissionregistration.k8s.io/v1Optional
Backward Compatibility
✅ Fully backward compatible:
webhook.enabled: false)Documentation
docs/webhook.md: Comprehensive webhook documentationREADME.md: Updated with webhook feature in features listFuture Enhancements
Closes
Addresses the need for early validation of TTL annotations, preventing invalid configurations from being applied to objects.