webhook

package
v0.0.0-...-cd07ea3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package webhook provides a version of the controller-runtime webhook(https://github.com/kubernetes-sigs/controller-runtime/tree/master/pkg/webhook) package. This version passes the [`admission.Request`](https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/webhook/admission/webhook.go#L48-L50) object into the `Default()`, `ValidateCreate()`, `ValidateUpdate()` and `ValidateDelete()` functions to provide more context to these functions for making their decisions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterContextualDefaulter

func RegisterContextualDefaulter(
	obj IContextuallyDefaultableObject,
	mgr ctrl.Manager,
) error

RegisterContextualDefaulter leverages many of the patterns and code from the Controller-Runtime Admission package, but is one level _less_ abstracted. Rather than calling the `Default()` function on the target resource type,

func RegisterContextualValidator

func RegisterContextualValidator(
	obj IContextuallyValidatableObject,
	mgr ctrl.Manager,
) error

RegisterContextualValidator leverages many of the patterns and code from the Controller-Runtime Admission package, but is one level _less_ abstracted. Rather than calling the `Default()` function on the target resource type,

Types

type IContextuallyDefaultableObject

type IContextuallyDefaultableObject interface {
	runtime.Object
	Default(req admission.Request) error
}

IContextuallyDefaultableObject implements a similar pattern to the [`controller-runtime`](https://github.com/kubernetes-sigs/controller-runtime/tree/v0.15.0/pkg/webhook) webhook pattern. The difference is that the `Default()` function is not only supplied the request resource, but also the request context in the form of an [`admission.Request`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.15.0/pkg/webhook/admission/webhook.go#L43-L66) object.

Modified from https://github.com/kubernetes-sigs/controller-runtime/blob/v0.15.0/pkg/webhook/admission/defaulter_custom.go#L31-L34

type IContextuallyValidatableObject

type IContextuallyValidatableObject interface {
	runtime.Object
	// ValidateCreate validates the object on creation.
	// The optional warnings will be added to the response as warning messages.
	// Return an error if the object is invalid.
	ValidateCreate(req admission.Request) (warnings admission.Warnings, err error)

	// ValidateUpdate validates the object on update. The oldObj is the object before the update.
	// The optional warnings will be added to the response as warning messages.
	// Return an error if the object is invalid.
	ValidateUpdate(req admission.Request, old runtime.Object) (warnings admission.Warnings, err error)

	// ValidateDelete validates the object on deletion.
	// The optional warnings will be added to the response as warning messages.
	// Return an error if the object is invalid.
	ValidateDelete(req admission.Request) (warnings admission.Warnings, err error)
}

IContextuallyValidatableObject implements a similar pattern to the [`controller-runtime`](https://github.com/kubernetes-sigs/controller-runtime/tree/v0.15.0/pkg/webhook) webhook pattern. The difference is that the `Default()` function is not only supplied the request resource, but also the request context in the form of an [`admission.Request`](https://github.com/kubernetes-sigs/controller-runtime/blob/v0.15.0/pkg/webhook/admission/webhook.go#L42C1-L65) object.

Modified from https://github.com/kubernetes-sigs/controller-runtime/blob/v0.15.0/pkg/webhook/admission/defaulter_custom.go#L31-L34

Jump to

Keyboard shortcuts

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