admission

package
v0.3.2-rc19 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package admission holds definitions and functions for admissionWebhook.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidRequest error returned when the requested operation with the requested fields are invalid.
	ErrInvalidRequest = fmt.Errorf("invalid request")
	// ErrUnsupportedOperation error returned when a validator is unable to validate the received operation.
	ErrUnsupportedOperation = fmt.Errorf("unsupported operation")
	// SlowTraceDuration duration to use when determining if a webhookHandler is slow.
	SlowTraceDuration = time.Second * 2
)

Functions

func NewDefaultMutatingWebhook

func NewDefaultMutatingWebhook(handler WebhookHandler, clientConfig v1.WebhookClientConfig, scope v1.ScopeType) *v1.MutatingWebhook

NewDefaultMutatingWebhook creates a new MutatingWebhook based on the WebhookHandler provided. The path set on the client config will be appended with the webhooks path. The return webhook will not be nil.

func NewDefaultValidatingWebhook

func NewDefaultValidatingWebhook(handler WebhookHandler, clientConfig v1.WebhookClientConfig, scope v1.ScopeType) *v1.ValidatingWebhook

NewDefaultValidatingWebhook creates a new ValidatingWebhook based on the WebhookHandler provided. The path set on the client config will be appended with the webhooks path. The return webhook will not be nil.

func NewHandlerFunc

func NewHandlerFunc(handler WebhookHandler) http.HandlerFunc

NewHandlerFunc returns a new HandlerFunc that will call the WebhookHandler's admit function.

func Path

func Path(basePath string, handler WebhookHandler) string

Path returns the path of the webhook joined with the given basePath.

func Ptr

func Ptr[T ~string](str T) *T

Ptr is a generic function that returns the pointer of a string.

func ResponseAllowed

func ResponseAllowed() *admissionv1.AdmissionResponse

ResponseAllowed returns a minimal AdmissionResponse in which Allowed is true

func ResponseBadRequest

func ResponseBadRequest(message string) *admissionv1.AdmissionResponse

ResponseBadRequest returns an AdmissionResponse for BadRequest(err code 400) the message is used as the message in the response

func SubPath

func SubPath(gvr schema.GroupVersionResource) string

SubPath returns the subpath to use for the given gvr.

Types

type MutatingAdmissionHandler

type MutatingAdmissionHandler interface {
	WebhookHandler

	// MutatingWebhook returns the configuration information for a ValidatingWebhook.
	// This functions allows MutatingAdmissionHandler to perform and modifications to the default configuration if needed.
	// A default configuration can be made using NewDefaultMutatingWebhook(...)
	MutatingWebhook(clientConfig v1.WebhookClientConfig) *v1.MutatingWebhook
}

MutatingAdmissionHandler is a handler used for creating a MutatingAdmission Webhook.

type Request

type Request struct {
	admissionv1.AdmissionRequest
	Context context.Context
}

Request is a simple wrapper for an AdmissionRequest that includes the context from the original http.Request.

type ValidatingAdmissionHandler

type ValidatingAdmissionHandler interface {
	WebhookHandler

	// ValidatingWebhook returns the configuration information for a ValidatingWebhook.
	// This functions allows ValidatingAdmissionHandler to perform and modifications to the default configuration if needed.
	// A default configuration can be made using NewDefaultValidatingWebhook(...)
	ValidatingWebhook(clientConfig v1.WebhookClientConfig) *v1.ValidatingWebhook
}

ValidatingAdmissionHandler is a handler used for creating a ValidationAdmission Webhook.

type WebhookHandler

type WebhookHandler interface {
	// GVR returns GroupVersionResource that the Webhook reviews.
	// The returned GVR is used to define the route for accessing this webhook as well as creating the Webhooks Name.
	// Thus the GVR returned must be unique from other WebhookHandlers of the same type e.g.(Mutating or Validating).
	// If a WebhookHandler desires to monitor all resources in a group the Resource defined int he GVR should be "*".
	// If a WebhookHandler desires to monitor a core type the Group can be left empty "".
	GVR() schema.GroupVersionResource

	// Operations returns list of operations that this WebhookHandler supports.
	// Handlers will only be sent request with operations that are contained in the provided list.
	Operations() []v1.OperationType

	// Admit handles the webhook admission request sent to this webhook.
	// The response returned by the WebhookHandler will be forwarded to the kube-api server.
	// If the WebhookHandler can not accurately evaluate the request it should return an error.
	Admit(*Request) (*admissionv1.AdmissionResponse, error)
}

WebhookHandler base interface for both ValidatingAdmissionHandler and MutatingAdmissionHandler. WebhookHandler is used for creating new http.HandlerFunc for each Webhook.

Jump to

Keyboard shortcuts

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