admission

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2022 License: MIT Imports: 13 Imported by: 2

Documentation

Overview

Package admission provides interfaces for building admission controllers with chaining function with support for both k8s native and custom resources in a consistent way. It's based on the custom resource admission webhook from controller-runtime, modified to not be specific to custom resources only. The defaulter and validator can have multiple functions, chained together to form a processing pipeline. They also have the ability to perform checks in advance before passing the object to the processing pipeline to avoid repetitive checks in each of the functions for filtering the objects and ignoring if needed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultingWebhookFor

func DefaultingWebhookFor(defaulter Defaulter) *admission.Webhook

DefaultingWebhookFor creates a new webhook for Defaulting the provided object type.

func ValidatingWebhookFor

func ValidatingWebhookFor(validator Validator) *admission.Webhook

ValidatingWebhookFor creates a new Webhook for validating the provided object type.

Types

type Controller

type Controller interface {
	// Name returns the name of the controller.
	Name() string
	Defaulter
	Validator
}

Controller defines an interface for a webhook admission controller.

type DefaultFunc

type DefaultFunc func(ctx context.Context, obj client.Object)

DefaultFunc is a function in the defaulting function chain, which forms a defaulter pipeline.

type Defaulter

type Defaulter interface {
	// ObjectGetter returns a new instance of the target object type of the
	// defaulter.
	ObjectGetter
	// Default returns a list of default functions that form the defaulting
	// pipeline.
	Default() []DefaultFunc
	// RequireDefaulting can be used to perform a check before processing the
	// request object and decide if defaulting is required or the object can be
	// ignore. Default() will not be called if this returns false. In case of
	// any error, true can be returned and a similar check can be performed in
	// a defaulting function that can return the proper error message that'll
	// be propagated to the user.
	RequireDefaulting(obj client.Object) bool
}

Defaulter defines functions for setting defaults on resource.

type ObjectGetter

type ObjectGetter interface {
	// GetNewObject returns a new initialized object of the target object type.
	GetNewObject() client.Object
}

ObjectGetter defines an interface for getting an object of any type, depending on the controller's target object type, in a generic form.

type ValidateCreateFunc

type ValidateCreateFunc func(ctx context.Context, obj client.Object) error

Validate-Funcs are functions in validating function chain, which forms a validating pipeline for a type of operation.

type ValidateDeleteFunc

type ValidateDeleteFunc func(ctx context.Context, oldObj client.Object) error

type ValidateUpdateFunc

type ValidateUpdateFunc func(ctx context.Context, obj client.Object, oldObj client.Object) error

type Validator

type Validator interface {
	// ObjectGetter returns a new instance of the target object type of the
	// defaulter.
	ObjectGetter
	// ValidateCreate returns a list of validate functions for create event.
	ValidateCreate() []ValidateCreateFunc
	// ValidateCreate returns a list of validate functions for update event.
	ValidateUpdate() []ValidateUpdateFunc
	// ValidateCreate returns a list of validate functions for delete event.
	ValidateDelete() []ValidateDeleteFunc
	// RequireValidating can be used to perform a check before processing the
	// request object and decide if validating is required or the object can be
	// ignored. None of the validating functions will be called if this returns
	// false. In case of any error, true can be returned and a similar check
	// can be performed in a validate function that can return the proper error
	// message that'll be propogated to the user.
	RequireValidating(obj client.Object) bool
}

Validator defines functions for validating an operation.

Jump to

Keyboard shortcuts

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