webhook

package
v0.10.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package webhook provides the entry point for configuring Kubernetes admission webhooks for the Multigres Operator.

The package exposes a Setup function that registers all webhook handlers with the controller-runtime manager. It wires together:

  • Mutating Webhooks: Apply defaults to MultigresCluster resources before they are persisted (see pkg/webhook/handlers for implementation).

  • Validating Webhooks: Enforce semantic rules for MultigresCluster, template resources, and child resources that cannot be expressed in CRD schemas.

Configuration

The Options struct controls webhook behavior:

  • Namespace: Operator namespace for service account identity.
  • ServiceAccountName: Used to construct the operator principal for child resource validation (only the operator can modify its managed resources).

TLS Certificates

Certificate management is handled by the generic pkg/cert module. This package provides webhook-specific helpers (PatchWebhookCABundle, FindOperatorDeployment) that are wired into the cert module's hooks by main.go.

Index

Constants

View Source
const (
	// CASecretName is the name of the Secret that stores the CA certificate and key.
	CASecretName = "multigres-operator-ca-secret" //nolint:gosec // K8s resource name, not a credential

	// ServerSecretName is the name of the Secret that stores the webhook server certificate and key.
	ServerSecretName = "multigres-webhook-certs" //nolint:gosec // K8s resource name, not a credential

	// MutatingWebhookName is the name of the MutatingWebhookConfiguration resource.
	MutatingWebhookName = "multigres-operator-mutating-webhook-configuration"

	// ValidatingWebhookName is the name of the ValidatingWebhookConfiguration resource.
	ValidatingWebhookName = "multigres-operator-validating-webhook-configuration"

	// CertStrategyAnnotation marks how the webhook TLS certificates are managed.
	// The operator sets this to CertStrategySelfSigned when it manages its own PKI.
	CertStrategyAnnotation = "multigres.com/cert-strategy"

	// CertStrategySelfSigned indicates the operator manages its own CA and server certs.
	CertStrategySelfSigned = "self-signed"
)

Variables

This section is empty.

Functions

func FindOperatorDeployment

func FindOperatorDeployment(
	ctx context.Context,
	c client.Client,
	namespace string,
	labels map[string]string,
	name string,
) (*appsv1.Deployment, error)

FindOperatorDeployment locates the operator's own Deployment for use as an owner reference on cert secrets. It first tries a label selector match, then falls back to an explicit name lookup. Returns (nil, nil) when no deployment is found, meaning secrets will be created without an owner reference.

func HasCertAnnotation

func HasCertAnnotation(ctx context.Context, c client.Client) bool

HasCertAnnotation returns true if either webhook configuration carries the cert-strategy annotation set by the operator. This is used during startup to detect that the operator previously managed its own certs, even when cert files exist on disk from surviving projected volumes.

func PatchWebhookCABundle

func PatchWebhookCABundle(ctx context.Context, c client.Client, caBundle []byte) error

PatchWebhookCABundle injects the CA bundle and cert-strategy annotation into both the Mutating and Validating webhook configurations using Server-Side Apply. Using SSA with a dedicated field owner ensures that user-side SSA upgrades (e.g. kubectl apply --server-side -f install.yaml) do not wipe caBundle, because different field managers own different fields.

func Setup

func Setup(mgr ctrl.Manager, res *resolver.Resolver, opts Options) error

Setup configures the webhook handlers using the builder pattern.

Types

type Options

type Options struct {
	Namespace          string
	ServiceAccountName string
}

Options contains the configuration required to set up the webhook server.

Directories

Path Synopsis
Package handlers implements the specific business logic for Kubernetes Admission Control.
Package handlers implements the specific business logic for Kubernetes Admission Control.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL