admission

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package admission contains functions to add and retrieve admission request from context

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdmissionRequest

func AdmissionRequest(ctx context.Context) admission.Request

AdmissionRequest returns admission request from context

func DefaultingWebhookFor

func DefaultingWebhookFor(ctx context.Context, defaulter Defaulter, transforms ...TransformFunc) *admission.Webhook

DefaultingWebhookFor creates a new Webhook for Defaulting the provided type.

func RegisterDefaultWebhookFor

func RegisterDefaultWebhookFor(ctx context.Context, mgr ctrl.Manager, defaulter Defaulter, transforms ...TransformFunc) (err error)

RegisterDefaultWebhookFor registers a mutate webhook for the defaulter with transforms

func RegisterValidateWebhookFor

func RegisterValidateWebhookFor(ctx context.Context, mgr ctrl.Manager, validator Validator, validateCreateFuncs []ValidateCreateFunc, validateUpdateFuncs []ValidateUpdateFunc, validateDeleteFuncs []ValidateDeleteFunc) (err error)

RegisterValidateWebhookFor registers a mutate webhook for the defaulter with transforms

func SubjectFromRequest

func SubjectFromRequest(req admission.Request) *rbacv1.Subject

SubjectFromRequest returns a user based on the request information

func ValidatingWebhookFor

func ValidatingWebhookFor(ctx context.Context, validator Validator, creates []ValidateCreateFunc, updates []ValidateUpdateFunc, deletes []ValidateDeleteFunc) *admission.Webhook

ValidatingWebhookFor creates a new Webhook for Validating the provided type.

func WithAdmissionRequest

func WithAdmissionRequest(ctx context.Context, req admission.Request) context.Context

WithAdmissionRequest adds an admission request to the context

Types

type ContextInjector

type ContextInjector interface {
	InjectContext(ctx context.Context) context.Context
}

ContextInjector define function to inject context, such as logger, k8s client etc.

type Defaulter

type Defaulter interface {
	runtime.Object
	metav1.Object
	Default(context.Context)
}

Defaulter defines functions for setting defaults on resources

type DefaulterWebhook

type DefaulterWebhook interface {
	Defaulter
	sharedmain.WebhookSetup
	sharedmain.WebhookRegisterSetup
	WithTransformer(transformers ...TransformFunc) DefaulterWebhook
	WithLoggerName(loggerName string) DefaulterWebhook
}

func NewDefaulterWebhook

func NewDefaulterWebhook(defaulter Defaulter) DefaulterWebhook

type TransformFunc

type TransformFunc func(context.Context, runtime.Object, admission.Request)

TransformFunc used to make common defaulting logic amongst multiple resource using a context, an object and a request

func WithCreatedBy

func WithCreatedBy() TransformFunc

WithCreatedBy adds a createdBy annotation to the object using the request information when an object already has the createdBy annotation it will only increment missing data

func WithUpdateTime

func WithUpdateTime() TransformFunc

WithUpdateTime adds a updateTime annotation to the object

func WithUpdatedBy

func WithUpdatedBy() TransformFunc

WithUpdatedBy adds a updatedBy annotation to the object using the request information when an object already has the updatedBy annotation it will cover old data

type ValidateCreateFunc

type ValidateCreateFunc func(ctx context.Context, obj runtime.Object, req admission.Request) error

ValidateCreateFunc function to add validation functions when operation is create using a context, an object and a request

type ValidateDeleteFunc

type ValidateDeleteFunc func(ctx context.Context, obj runtime.Object, req admission.Request) error

ValidateDeleteFunc function to add validation functions when operation is delete using a context, an object and a request

type ValidateUpdateFunc

type ValidateUpdateFunc func(ctx context.Context, obj runtime.Object, old runtime.Object, req admission.Request) error

ValidateUpdateFunc function to add validation functions when operation is update using a context, the current object, the old object and a request

type Validator

type Validator interface {
	runtime.Object
	metav1.Object
	ValidateCreate(ctx context.Context) error
	ValidateUpdate(ctx context.Context, old runtime.Object) error
	ValidateDelete(ctx context.Context) error
}

Validator defines functions for validating an operation

type ValidatorWebhook

type ValidatorWebhook interface {
	Validator
	sharedmain.WebhookSetup
	sharedmain.WebhookRegisterSetup
	WithValidateCreate(creates ...ValidateCreateFunc) ValidatorWebhook
	WithValidateUpdate(updates ...ValidateUpdateFunc) ValidatorWebhook
	WithValidateDelete(deletes ...ValidateDeleteFunc) ValidatorWebhook
	WithLoggerName(loggerName string) ValidatorWebhook
}

func NewValidatorWebhook

func NewValidatorWebhook(validator Validator) ValidatorWebhook

Jump to

Keyboard shortcuts

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