Documentation
¶
Overview ¶
webhook/admission.go — /validate and /mutate HTTP handlers.
The Kubernetes API server POSTs an AdmissionReview to /validate for every CREATE and UPDATE on a resource covered by the ValidatingWebhookConfiguration, and to /mutate for every CREATE and UPDATE covered by the MutatingWebhookConfiguration.
Mutation fires before validation in the Kubernetes admission chain, so defaults are applied before validation sees the object.
webhook/admission_evaluation.go — validation and mutation rule evaluation.
webhook/admission_review.go — Kubernetes AdmissionReview types.
These mirror the Kubernetes admissionregistration.k8s.io/v1 types. Declared here to keep the webhook package self-contained without importing the full k8s.io/api module where it isn't needed.
The Kubernetes API server sends an AdmissionReview to /validate and /mutate. Orkestra reads the Request, evaluates rules from the Katalog, and writes the Response. The API server reads the Response and either stores the object (allowed) or rejects it (denied).
webhook/controller.go — continuous webhook configuration reconciliation.
The webhook controller runs in the background and ensures that Orkestra's admission surface (validation, mutation, deletion protection, namespace protection) exists exactly when the user has declared it — and disappears when they have not.
Declarative Webhook Lifecycle
security.admission.enabled: true
→ create/update the validating and mutating webhook configurations
security.deletionProtection.enabled: true
→ create/update the deletion-protection webhook
(inverse: when disabled, the controller removes the corresponding webhook)
Cleanup Semantics ¶
Webhook configurations are not removed on pod restart by default. Cleanup is opt-in via security.admission.cleanupOnShutdown and security.deletionProtection.cleanupOnShutdown. This avoids race conditions during rollout where a new leader sees an existing webhook while the old leader is still shutting down.
The controller returns only fatal initialization errors. Reconciliation itself is continuous and non-blocking.
webhook/conversion.go — /convert HTTP handler for CRD version conversion.
The Kubernetes API server POSTs a ConversionReview to this endpoint when it needs to convert a CR from one version to another. Orkestra applies the conversion rules declared in the Katalog for the object's Kind.
webhook/conversion_logic.go — CRD version conversion logic.
webhook/deletion_protection.go — /deletion-protection webhook handler.
Registered only when security.deletionProtection.enabled: true in the Katalog. Intercepts DELETE operations on CRDs owned by this operator and Orkestra's own resources (deployment, service, ingress, webhook configurations).
failurePolicy: Fail — if Orkestra is unreachable, DELETE is blocked. To decommission: set deletionProtection.enabled: false, redeploy, then delete.
webhook/namespace_protection.go — /namespace-protection webhook handler.
Registered only when security.namespaceProtection.enabled: true in the Katalog. Intercepts CREATE and UPDATE on CRDs that declare allowedNamespaces or restrictedNamespaces, and rejects operations in forbidden namespaces.
failurePolicy: Fail — if Orkestra is unreachable, the operation is blocked.
webhook/registration.go — webhook configuration registration and cleanup.
At startup, when admission webhooks or deletion/namespace protection are enabled, Orkestra creates or updates the corresponding ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects that tell the API server to call Orkestra during admission.
All registration functions are idempotent — safe to call on restart or from the reconciliation controller. Existing configurations are updated to match the current Katalog state.
Package webhook implements Orkestra's admission and conversion webhook surface as a domain.Komponent that can be registered and managed alongside other runtime components.
Responsibility ¶
The webhook package owns everything required to operate Kubernetes admission and conversion webhooks:
- TLS HTTPS server that handles /validate, /mutate, /convert, /deletion-protection, and /namespace-protection
- Webhook configuration registration and reconciliation with the API server
- All HTTP handlers for admission review processing
- Periodic controller that keeps webhook configurations in sync with the Katalog
The health package (pkg/health) handles only HTTP health and readiness probes. This package handles only the HTTPS webhook surface.
TLS ¶
TLS certificates are provisioned by cmd/internal.ensureSecurity before Start() is called. The certificate file paths are read from konfig.Security().Webhooks after ensureSecurity writes them there. WebhookServer never generates its own certificates — that is the caller's responsibility.
Lifecycle ¶
WebhookServer implements domain.Komponent:
New(kubeClient, katalog, konfig)
→ Start(ctx) — validate TLS, register endpoints, start HTTPS server,
register webhook configs, start controller
→ Shutdown(ctx) — stop HTTPS server, clean up webhook configs on shutdown
All registration and reconciliation errors are logged and non-fatal. The HTTPS server starts only when at least one webhook capability is declared in the Katalog. When no capabilities are declared, Start() is a no-op.
Index ¶
- func RegisterAdmissionWebhooks(ctx context.Context, client kubernetes.Interface, ...) error
- func UnregisterAdmissionWebhooks(ctx context.Context, client kubernetes.Interface, opts WebhookCleanupOptions) error
- type AdmissionRequest
- type AdmissionResponse
- type AdmissionReview
- type AdmissionStatus
- type ConversionReview
- type ConversionReviewRequest
- type ConversionReviewResponse
- type JSONPatchOp
- type NamespaceRules
- type Status
- type WebhookCleanupOptions
- type WebhookRegistrationOptions
- type WebhookServer
- func (ws *WebhookServer) GetAdmissionStats() *health.AdmissionStats
- func (ws *WebhookServer) GetConversionStats() *health.ConversionStats
- func (ws *WebhookServer) GetNamespaceStats() *health.NamespaceProtectionStats
- func (ws *WebhookServer) GetProtectionStats() *health.DeletionProtectionStats
- func (ws *WebhookServer) GetWebhookStats() *health.WebhookStats
- func (ws *WebhookServer) Name() string
- func (ws *WebhookServer) SetCertManager(m certManagerIface)
- func (ws *WebhookServer) Shutdown(ctx context.Context)
- func (ws *WebhookServer) Start(ctx context.Context) error
- func (ws *WebhookServer) Started() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterAdmissionWebhooks ¶
func RegisterAdmissionWebhooks( ctx context.Context, client kubernetes.Interface, registry admissionRegistryReader, opts WebhookRegistrationOptions, ) error
RegisterAdmissionWebhooks creates or updates the ValidatingWebhookConfiguration and MutatingWebhookConfiguration based on the current admission registry. Idempotent — safe to call on restart and from the webhook controller.
func UnregisterAdmissionWebhooks ¶
func UnregisterAdmissionWebhooks( ctx context.Context, client kubernetes.Interface, opts WebhookCleanupOptions, ) error
UnregisterAdmissionWebhooks removes the ValidatingWebhookConfiguration and/or MutatingWebhookConfiguration entries previously created from the admission registry. Called from Shutdown() when cleanupOnShutdown is enabled.
Types ¶
type AdmissionRequest ¶
type AdmissionRequest struct {
UID string `json:"uid"`
Kind metav1.GroupVersionKind `json:"kind"`
Resource metav1.GroupVersionResource `json:"resource"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Operation string `json:"operation"`
Object json.RawMessage `json:"object,omitempty"`
OldObject json.RawMessage `json:"oldObject,omitempty"`
DryRun *bool `json:"dryRun,omitempty"`
}
AdmissionRequest contains the object the API server is asking about.
type AdmissionResponse ¶
type AdmissionResponse struct {
UID string `json:"uid"`
Allowed bool `json:"allowed"`
Status *AdmissionStatus `json:"status,omitempty"`
Patch []byte `json:"patch,omitempty"`
PatchType *string `json:"patchType,omitempty"`
Warnings []string `json:"warnings,omitempty"`
}
AdmissionResponse is what Orkestra writes in reply to an AdmissionRequest.
type AdmissionReview ¶
type AdmissionReview struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Request *AdmissionRequest `json:"request,omitempty"`
Response *AdmissionResponse `json:"response,omitempty"`
}
AdmissionReview is the top-level wrapper sent by the API server. The same struct is used for both request and response directions.
type AdmissionStatus ¶
AdmissionStatus is the rejection reason returned when Allowed is false.
type ConversionReview ¶
type ConversionReview struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Request *ConversionReviewRequest `json:"request,omitempty"`
Response *ConversionReviewResponse `json:"response,omitempty"`
}
type ConversionReviewRequest ¶
type ConversionReviewRequest struct {
UID string `json:"uid"`
DesiredAPIVersion string `json:"desiredAPIVersion"`
Objects []json.RawMessage `json:"objects"`
}
type ConversionReviewResponse ¶
type ConversionReviewResponse struct {
UID string `json:"uid"`
ConvertedObjects []json.RawMessage `json:"convertedObjects"`
Result *Status `json:"result"`
}
type JSONPatchOp ¶
type JSONPatchOp struct {
Op string `json:"op"`
Path string `json:"path"`
Value interface{} `json:"value,omitempty"`
}
JSONPatchOp is one operation in a JSON Patch document (RFC 6902).
type NamespaceRules ¶
NamespaceRules holds the allow/restrict namespace sets for one CRD.
func (*NamespaceRules) IsNamespaceAllowed ¶
func (r *NamespaceRules) IsNamespaceAllowed(ns string) bool
IsNamespaceAllowed returns true when the namespace passes the CRD's namespace rules.
type WebhookCleanupOptions ¶
type WebhookCleanupOptions struct {
// contains filtered or unexported fields
}
WebhookCleanupOptions selects which webhook configurations to remove.
type WebhookRegistrationOptions ¶
type WebhookRegistrationOptions struct {
ServiceName string
ServiceNamespace string
Port int32
FailurePolicy admissionv1.FailurePolicyType
TLSCertFile string
OrkestraResourceLabels map[string]string
OrkestraResourceSelector *metav1.LabelSelector
}
WebhookRegistrationOptions holds the configuration for webhook registration.
type WebhookServer ¶
type WebhookServer struct {
// contains filtered or unexported fields
}
WebhookServer is Orkestra's HTTPS admission and conversion webhook surface. It owns the HTTPS server, all webhook handlers, registration, and the webhook controller that reconciles configurations with the API server.
Created via NewWebhookServer and registered as a domain.Komponent in cmd/internal/konstructor.go. It starts after the HealthServer so that /ready is live before webhook registration runs.
func NewWebhookServer ¶
func NewWebhookServer(kubeClient kubernetes.Interface, kat *katalog.Katalog, kfg *konfig.Konfig) *WebhookServer
NewWebhookServer constructs a WebhookServer and resolves all declarative webhook behavior from the Katalog and Konfig. No I/O is performed — Start() activates servers, registration, and reconciliation.
func (*WebhookServer) GetAdmissionStats ¶
func (ws *WebhookServer) GetAdmissionStats() *health.AdmissionStats
GetAdmissionStats returns the admission statistics instance.
func (*WebhookServer) GetConversionStats ¶
func (ws *WebhookServer) GetConversionStats() *health.ConversionStats
GetConversionStats returns the conversion statistics instance.
func (*WebhookServer) GetNamespaceStats ¶
func (ws *WebhookServer) GetNamespaceStats() *health.NamespaceProtectionStats
GetNamespaceStats returns the namespace-protection statistics instance.
func (*WebhookServer) GetProtectionStats ¶
func (ws *WebhookServer) GetProtectionStats() *health.DeletionProtectionStats
GetProtectionStats returns the deletion-protection statistics instance.
func (*WebhookServer) GetWebhookStats ¶
func (ws *WebhookServer) GetWebhookStats() *health.WebhookStats
GetWebhookStats returns the webhook reconciliation statistics instance.
func (*WebhookServer) Name ¶
func (ws *WebhookServer) Name() string
Name returns the component name.
func (*WebhookServer) SetCertManager ¶
func (ws *WebhookServer) SetCertManager(m certManagerIface)
SetCertManager provides the cert manager for TLS secret cleanup on graceful shutdown. Set only when Orkestra generated self-signed certificates (certMgr == nil when the user provided explicit TLS_CERT/TLS_KEY).
func (*WebhookServer) Shutdown ¶
func (ws *WebhookServer) Shutdown(ctx context.Context)
Shutdown gracefully stops the HTTPS server and performs declarative cleanup of webhook configurations as declared in the Katalog.
func (*WebhookServer) Start ¶
func (ws *WebhookServer) Start(ctx context.Context) error
Start activates the WebhookServer. It registers all declared webhook endpoints, launches the HTTPS server, performs best-effort webhook registration with the API server, and starts the reconciliation controller.
Start is a no-op when no webhook capabilities are declared in the Katalog or when the process is not running inside a Kubernetes cluster.
func (*WebhookServer) Started ¶
func (ws *WebhookServer) Started() bool
Started reports whether Start() has been called.