package loader

import "k8s.io/apiserver/pkg/admission/plugin/webhook/manifest/loader"

Package loader provides generic functionality to load webhook configurations from manifest files. It handles file reading, YAML/JSON decoding, and generic manifest validation. Type-specific defaulting and validation (e.g., scheme-based defaulting via internal types) are injected by callers through the AcceptObjectFunc callback.

Index

Functions

func BuildMutatingAccessors

BuildMutatingAccessors builds webhook accessors from mutating webhook configurations.

func BuildValidatingAccessors

BuildValidatingAccessors builds webhook accessors from validating webhook configurations.

func LoadManifests

func LoadManifests[T metav1.Object](
	dir string,
	decoder runtime.Decoder,
	acceptObject AcceptObjectFunc[T],
) ([]T, string, error)

LoadManifests loads webhook configurations from manifest files in dir using the provided decoder and acceptObject callback. It handles file I/O, YAML splitting, decoding, v1.List unwrapping, manifest name validation, webhook client config validation, and deterministic sorting by name.

func ValidateWebhookClientConfig

func ValidateWebhookClientConfig(webhookName, configName, filePath string, cc admissionregistrationv1.WebhookClientConfig) error

ValidateWebhookClientConfig checks that a webhook uses URL-based client config (service references are not supported for static manifests).

Types

type AcceptObjectFunc

type AcceptObjectFunc[T metav1.Object] func(obj runtime.Object) ([]T, error)

AcceptObjectFunc extracts typed items from a decoded runtime.Object, applying defaulting and validation. Returns the extracted items, or an error if the object type is not recognized or processing fails.

type MutatingLoadResult

type MutatingLoadResult struct {
	// Configurations is the list of loaded mutating webhook configurations.
	Configurations []*admissionregistrationv1.MutatingWebhookConfiguration
	// Hash is the sha256 hash of all loaded files, used for change detection.
	Hash string
}

MutatingLoadResult holds the mutating webhook configurations loaded from manifest files.

func (*MutatingLoadResult) GetWebhookAccessors

func (r *MutatingLoadResult) GetWebhookAccessors() []webhook.WebhookAccessor

GetWebhookAccessors returns webhook accessors for all mutating webhooks.

type ValidatingLoadResult

type ValidatingLoadResult struct {
	// Configurations is the list of loaded validating webhook configurations.
	Configurations []*admissionregistrationv1.ValidatingWebhookConfiguration
	// Hash is the sha256 hash of all loaded files, used for change detection.
	Hash string
}

ValidatingLoadResult holds the validating webhook configurations loaded from manifest files.

func (*ValidatingLoadResult) GetWebhookAccessors

func (r *ValidatingLoadResult) GetWebhookAccessors() []webhook.WebhookAccessor

GetWebhookAccessors returns webhook accessors for all validating webhooks.

Source Files

loader.go

Version
v0.36.0 (latest)
Published
Apr 22, 2026
Platform
linux/amd64
Imports
7 packages
Last checked
4 days ago

Tools for package owners.