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 ( // BasicValidatorComponentName is the unique identifier for the basic validator component. BasicValidatorComponentName = "basic-validator" // BasicValidatorID identifies the basic validator in scatter-gather responses. BasicValidatorID = "basic" )
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 BasicValidatorComponent ¶
type BasicValidatorComponent struct {
// contains filtered or unexported fields
}
BasicValidatorComponent performs basic structural validation of Kubernetes resources.
This validator checks:
- Object is a valid map structure
- Required metadata fields exist
- Metadata fields have valid values
It subscribes to WebhookValidationRequest events and publishes WebhookValidationResponse events.
func NewBasicValidatorComponent ¶
func NewBasicValidatorComponent(eventBus *busevents.EventBus, logger *slog.Logger) *BasicValidatorComponent
NewBasicValidatorComponent creates a new basic validator component.
func (*BasicValidatorComponent) Name ¶
func (b *BasicValidatorComponent) Name() string
Name returns the unique identifier for this component. Implements the lifecycle.Component interface.
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(eventBus *busevents.EventBus, logger *slog.Logger, config *Config, restMapper meta.RESTMapper, metrics MetricsRecorder) *Component
New creates a new webhook component.
Parameters:
- eventBus: EventBus for publishing webhook events
- 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
}
Config configures the webhook component.
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.