Documentation
¶
Overview ¶
Package webhook provides the webhook adapter component that bridges the pure webhook library to the event-driven controller architecture.
The webhook component manages the lifecycle of admission webhooks including:
- HTTPS webhook server
- Integration with controller validators
Note: TLS certificates are fetched from Kubernetes Secret via API. ValidatingWebhookConfiguration is created by Helm at installation time.
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" // EventBufferSize is the size of the event subscription buffer. EventBufferSize = 50 )
Variables ¶
This section is empty.
Functions ¶
func ExtractWebhookRules ¶
func ExtractWebhookRules(cfg *config.Config) []webhook.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
func HasWebhookEnabled ¶
HasWebhookEnabled checks if any watched resources have webhook validation enabled.
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) Name ¶
Name returns the unique identifier for this component. Implements the lifecycle.Component interface.
func (*Component) RegisterValidator ¶
func (c *Component) RegisterValidator(gvk string, validatorFunc webhook.ValidationFunc)
RegisterValidator registers a validation function for a specific resource type.
This should be called before Start() to register all validators.
Parameters:
- gvk: Group/Version.Kind identifier (e.g., "networking.k8s.io/v1.Ingress", "v1.ConfigMap")
- validatorFunc: The validation function to call for this resource type
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
// CertPEM is the PEM-encoded TLS certificate.
// Fetched from Kubernetes Secret via API.
CertPEM []byte
// KeyPEM is the PEM-encoded TLS private key.
// Fetched from Kubernetes Secret via API.
KeyPEM []byte
// Rules defines which resources the webhook validates.
// Used for registering validators by GVK.
Rules []webhook.WebhookRule
// DryRunValidator performs dry-run validation of resources.
// If nil, validation is skipped (fail-open).
DryRunValidator DryRunValidator
}
Config configures the webhook component.
type DryRunValidator ¶
type DryRunValidator interface {
ValidateDirect(ctx context.Context, gvk, namespace, name string, object interface{}, operation string) (allowed bool, reason string)
}
DryRunValidator defines the interface for dry-run validation. This allows the webhook to validate resources without scatter-gather events.
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.