Documentation
¶
Overview ¶
Package webhook connects the admission server to controller validation.
Index ¶
Constants ¶
const ( // ComponentName is the unique identifier for this component. ComponentName = "webhook" // DefaultWebhookPort is the default HTTPS port for the webhook server. DefaultWebhookPort = 9443 // DefaultWebhookPath is the default URL path for validation requests. DefaultWebhookPath = "/validate" // DefaultResourceAdmissionTimeout bounds watched-resource (for example, // Ingress) dry-run admission. The chart pairs it with a 10-second Kubernetes // webhook timeout. Keeping this path at nine seconds limits per-request work // and preserves fail-closed admission under untrusted routing-resource load. DefaultResourceAdmissionTimeout = 9 * time.Second // MaximumAdmissionTimeout is the largest safe controller-side deadline. // Kubernetes caps ValidatingWebhookConfiguration.timeoutSeconds at 30; // keeping one second of response margin makes 29 seconds the hard maximum. MaximumAdmissionTimeout = 29 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component is the webhook adapter component that manages webhook lifecycle.
It coordinates the pure webhook library server with the event-driven controller architecture.
func New ¶
func New(logger *slog.Logger, config *Config, restMapper meta.RESTMapper, metrics MetricsRecorder) *Component
New creates a new webhook component.
Parameters:
- logger: Structured logger
- config: Component configuration (must include CertPEM and KeyPEM)
- restMapper: RESTMapper for resolving resource kinds from GVR
- metrics: Optional metrics recorder (can be nil)
Returns:
- A new Component instance ready to be started
func (*Component) Listening ¶
func (c *Component) Listening() <-chan struct{}
Listening returns a channel that is closed once the underlying webhook server has bound its TLS listener. Until this channel is closed, an admission request routed at the controller fails with "connection refused", because the listening socket simply doesn't exist yet.
type Config ¶
type Config struct {
// Port is the HTTPS port for the webhook server.
// Default: 9443
Port int
// Path is the URL path for validation requests.
// Default: "/validate"
Path string
// CertDir, when set, is a directory containing tls.crt and tls.key
// (typically the mounted webhook-cert Secret). The server reads them
// per-handshake and hot-reloads a rotated certificate without a restart.
// Takes precedence over CertPEM/KeyPEM; production uses this path.
CertDir string
// CertPEM is the PEM-encoded TLS certificate.
// Used when CertDir is unset (e.g. tests pass certs directly).
CertPEM []byte
// KeyPEM is the PEM-encoded TLS private key.
// Used when CertDir is unset.
KeyPEM []byte
// Rules defines which resources the webhook validates.
// Used for registering validators by GVK.
Rules []WebhookRule
// DryRunValidator performs dry-run validation of resources.
// Required when Rules is non-empty.
DryRunValidator DryRunValidator
// ResourceAdmissionTimeout bounds watched-resource dry-run validation.
// Default: 9s. Keep it below the corresponding Kubernetes webhook
// timeoutSeconds value so the controller can return a structured decision.
ResourceAdmissionTimeout time.Duration
// Server is a caller-owned listener; the component replaces only its validator generation.
Server *webhook.Server
// OnGenerationRetired releases resources captured by the installed table.
OnGenerationRetired func()
}
Config configures the webhook component.
type DryRunValidator ¶
type DryRunValidator interface {
ValidateDirect(ctx context.Context, gvk, namespace, name string, object, oldObject any, operation string) (allowed bool, reason string, warnings []string)
}
DryRunValidator defines the synchronous interface the webhook uses to validate resources. The implementation in pkg/controller/dryrunvalidator is a library, not a lifecycle component.
Warnings are surfaced via AdmissionResponse.Warnings on both allow and deny paths so kubectl prints them as "Warning:" lines without blocking admission. Pluggable validators (e.g. the SPOA hub running in --validate-socket mode) populate this slice from their non-fatal diagnostics; the standard render+validate pipeline does not.
type MetricsRecorder ¶
type MetricsRecorder interface {
RecordWebhookRequest(gvk, result string, durationSeconds float64)
RecordWebhookValidation(gvk, result string)
}
MetricsRecorder defines the interface for recording webhook metrics. This allows the component to work with or without metrics.
type WebhookRule ¶
type WebhookRule struct {
// APIGroup that this rule matches.
// Example: "networking.k8s.io"
APIGroup string
// APIVersion that this rule matches.
// Example: "v1"
APIVersion string
// Resource that this rule matches (plural, lowercase).
// Example: "ingresses"
Resource string
}
WebhookRule specifies which resources a webhook should intercept.
func ExtractWebhookRules ¶
func ExtractWebhookRules(cfg *config.Config) []WebhookRule
ExtractWebhookRules extracts webhook rules from controller configuration.
It iterates through watched resources and creates webhook rules for resources with enable_validation_webhook: true.
Parameters:
- cfg: Controller configuration containing watched resources
Returns:
- Slice of webhook rules for resources that have validation enabled
- Empty slice if no resources have webhook validation enabled