controller-runtime: sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder Index | Files

package builder

import "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder"

Package builder provides methods to build admission webhooks.

The following are 2 examples for building mutating webhook and validating webhook.

webhook1 := NewWebhookBuilder().
	Mutating().
	Path("/mutatepods").
	ForType(&corev1.Pod{}).
	Handlers(mutatingHandler11, mutatingHandler12).
	Build()

webhook2 := NewWebhookBuilder().
	Validating().
	Path("/validatepods").
	ForType(&appsv1.Deployment{}).
	Handlers(validatingHandler21).
	Build()

Note: To build a webhook for a CRD, you need to ensure the manager uses the scheme that understands your CRD. This is necessary, because if the scheme doesn't understand your CRD types, the decoder won't be able to decode the CR object from the admission review request.

The following snippet shows how to register CRD types with manager's scheme.

mgr, err := manager.New(cfg, manager.Options{})
if err != nil {
	// handle error
}
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "crew.k8s.io", Version: "v1"}
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
// Register your CRD types.
SchemeBuilder.Register(&Kraken{}, &KrakenList{})
// Register your CRD types with the manager's scheme.
err = SchemeBuilder.AddToScheme(mgr.GetScheme())
if err != nil {
	// handle error
}

Index

Package Files

builder.go doc.go

type WebhookBuilder Uses

type WebhookBuilder struct {
    // contains filtered or unexported fields
}

WebhookBuilder builds a webhook based on the provided options.

func NewWebhookBuilder Uses

func NewWebhookBuilder() *WebhookBuilder

NewWebhookBuilder creates an empty WebhookBuilder.

func (*WebhookBuilder) Build Uses

func (b *WebhookBuilder) Build() *admission.Webhook

Build creates the Webhook based on the options provided.

func (*WebhookBuilder) Handlers Uses

func (b *WebhookBuilder) Handlers(handlers ...admission.Handler) *WebhookBuilder

Handlers sets the handlers of the webhook.

func (*WebhookBuilder) Mutating Uses

func (b *WebhookBuilder) Mutating() *WebhookBuilder

Mutating sets the type to mutating admission webhook Only one of Mutating and Validating can be invoked.

func (*WebhookBuilder) Name Uses

func (b *WebhookBuilder) Name(name string) *WebhookBuilder

Name sets the name of the webhook. This is optional

func (*WebhookBuilder) Path Uses

func (b *WebhookBuilder) Path(path string) *WebhookBuilder

Path sets the path for the webhook. Path needs to be unique among different webhooks. This is required. If not set, it will be built from the type and resource name. For example, a webhook that mutates pods has a default path of "/mutate-pods" If the defaulting logic can't find a unique path for it, user need to set it manually.

func (*WebhookBuilder) Validating Uses

func (b *WebhookBuilder) Validating() *WebhookBuilder

Validating sets the type to validating admission webhook Only one of Mutating and Validating can be invoked.

Package builder imports 2 packages (graph) and is imported by 5 packages. Updated 2019-02-18. Refresh now. Tools for package owners.