admission

package
Version: v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: Apache-2.0 Imports: 23 Imported by: 877

Documentation

Overview

Package admission provides functions to build and bootstrap an admission webhook server for a k8s cluster.

Build webhooks

webhook1, err := NewWebhookBuilder().
	Name("foo.k8s.io").
	Mutating().
	Operations(admissionregistrationv1beta1.Create).
	ForType(&corev1.Pod{}).
	WithManager(mgr).
	Build(mutatingHandler1, mutatingHandler2)
if err != nil {
	// handle error
}

webhook2, err := NewWebhookBuilder().
	Name("bar.k8s.io").
	Validating().
	Operations(admissionregistrationv1beta1.Create, admissionregistrationv1beta1.Update).
	ForType(&appsv1.Deployment{}).
	WithManager(mgr).
	Build(validatingHandler1)
if err != nil {
	// handle error
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorResponse

func ErrorResponse(code int32, err error) types.Response

ErrorResponse creates a new Response for error-handling a request.

func NewDecoder

func NewDecoder(scheme *runtime.Scheme) (types.Decoder, error)

NewDecoder creates a Decoder given the runtime.Scheme

func PatchResponse

func PatchResponse(original, current runtime.Object) types.Response

PatchResponse returns a new response with json patch.

func ValidationResponse

func ValidationResponse(allowed bool, reason string) types.Response

ValidationResponse returns a response for admitting a request.

Types

type DecodeFunc

type DecodeFunc func(types.Request, runtime.Object) error

DecodeFunc is a function that implements the Decoder interface.

func (DecodeFunc) Decode

func (f DecodeFunc) Decode(req types.Request, obj runtime.Object) error

Decode implements the Decoder interface.

type Handler

type Handler interface {
	Handle(context.Context, atypes.Request) atypes.Response
}

Handler can handle an AdmissionRequest.

type HandlerFunc

type HandlerFunc func(context.Context, atypes.Request) atypes.Response

HandlerFunc implements Handler interface using a single function.

func (HandlerFunc) Handle

Handle process the AdmissionRequest by invoking the underlying function.

type Webhook

type Webhook struct {
	// Name is the name of the webhook
	Name string
	// Type is the webhook type, i.e. mutating, validating
	Type types.WebhookType
	// Path is the path this webhook will serve.
	Path string
	// Rules maps to the Rules field in admissionregistrationv1beta1.Webhook
	Rules []admissionregistrationv1beta1.RuleWithOperations
	// FailurePolicy maps to the FailurePolicy field in admissionregistrationv1beta1.Webhook
	// This optional. If not set, will be defaulted to Ignore (fail-open) by the server.
	// More details: https://github.com/kubernetes/api/blob/f5c295feaba2cbc946f0bbb8b535fc5f6a0345ee/admissionregistration/v1beta1/types.go#L144-L147
	FailurePolicy *admissionregistrationv1beta1.FailurePolicyType
	// NamespaceSelector maps to the NamespaceSelector field in admissionregistrationv1beta1.Webhook
	// This optional.
	NamespaceSelector *metav1.LabelSelector
	// Handlers contains a list of handlers. Each handler may only contains the business logic for its own feature.
	// For example, feature foo and bar can be in the same webhook if all the other configurations are the same.
	// The handler will be invoked sequentially as the order in the list.
	// Note: if you are using mutating webhook with multiple handlers, it's your responsibility to
	// ensure the handlers are not generating conflicting JSON patches.
	Handlers []Handler
	// contains filtered or unexported fields
}

Webhook represents each individual webhook.

func (*Webhook) Add

func (w *Webhook) Add(handlers ...Handler)

Add adds additional handler(s) in the webhook

func (*Webhook) GetName

func (w *Webhook) GetName() string

GetName returns the name of the webhook.

func (*Webhook) GetPath

func (w *Webhook) GetPath() string

GetPath returns the path that the webhook registered.

func (*Webhook) GetType

func (w *Webhook) GetType() types.WebhookType

GetType returns the type of the webhook.

func (*Webhook) Handle

func (w *Webhook) Handle(ctx context.Context, req atypes.Request) atypes.Response

Handle processes AdmissionRequest. If the webhook is mutating type, it delegates the AdmissionRequest to each handler and merge the patches. If the webhook is validating type, it delegates the AdmissionRequest to each handler and deny the request if anyone denies.

func (*Webhook) Handler

func (w *Webhook) Handler() http.Handler

Handler returns a http.Handler for the webhook

func (*Webhook) InjectClient

func (w *Webhook) InjectClient(c client.Client) error

InjectClient injects the client into the handlers

func (*Webhook) InjectDecoder

func (w *Webhook) InjectDecoder(d atypes.Decoder) error

InjectDecoder injects the decoder into the handlers

func (*Webhook) ServeHTTP

func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Webhook) Validate

func (w *Webhook) Validate() error

Validate validates if the webhook is valid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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