Documentation ¶
Overview ¶
Package psbinding provides facilities to make authoring Bindings that work with "Pod Spec"-able subjects easier. There are two key components
- The AdmissionController, which lives in psbinding.go (controller.go) sets it up.
- The BaseReconciler, which lives in reconciler.go and can either be used directly as a Reconciler, or it can be wrapped as a base implementation for a customized reconciler that wants to take advantage of its facilities (e.g. for updating status and manipulating finalizers).
The core concept to consuming psbinding is the Bindable interface. By implementing Bindable on your binding resource, you enable the BaseReconciler to take over a significant amount of the boilerplate reconciliation (maybe all of it). A lot of the interface methods will seem pretty standard to Knative folks, but the two key methods to call our are Do and Undo. These "mutation" methods carry the business logic for the "Pod Spec"-able binding.
The mutation methods have the signature:
func(context.Context, *v1alpha1.WithPod)
These methods are called to have the Binding perform its mutation on the supplied WithPod (our "Pod Spec"-able wrapper type). However, in some cases the binding may need additional context. Similar to apis.Validatable and apis.Defaultable these mutations take a context.Context, and similar to our "resourcesemantics" webhook, the "psbinding" package provides a hook to allow consumers to infuse this context.Context with additional... context. The signature of these hooks is BindableContext, and they may be supplied to both the AdmissionController and the BaseReconciler.
Index ¶
- Variables
- func HasOptOutSelector(ctx context.Context) bool
- func NewAdmissionController(ctx context.Context, name, path string, gla GetListAll, ...) *controller.Impl
- func WithOptOutSelector(ctx context.Context) context.Context
- type BaseReconciler
- func (r *BaseReconciler) EnsureFinalizer(ctx context.Context, fb kmeta.Accessor) error
- func (r *BaseReconciler) IsFinalizing(ctx context.Context, fb kmeta.Accessor) bool
- func (r *BaseReconciler) Reconcile(ctx context.Context, key string) error
- func (r *BaseReconciler) ReconcileDeletion(ctx context.Context, fb Bindable) error
- func (r *BaseReconciler) ReconcileSubject(ctx context.Context, fb Bindable, mutation Mutation) error
- func (r *BaseReconciler) RemoveFinalizer(ctx context.Context, fb kmeta.Accessor) error
- func (r *BaseReconciler) UpdateStatus(ctx context.Context, desired Bindable) error
- type Bindable
- type BindableContext
- type GetListAll
- type ListAll
- type Mutation
- type Reconciler
Constants ¶
This section is empty.
Variables ¶
var ( ExclusionSelector = metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{{ Key: duck.BindingExcludeLabel, Operator: metav1.LabelSelectorOpNotIn, Values: []string{"true"}, }}, } InclusionSelector = metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{{ Key: duck.BindingIncludeLabel, Operator: metav1.LabelSelectorOpIn, Values: []string{"true"}, }}, } )
We need to specifically exclude our deployment(s) from consideration, but this provides a way of excluding other things as well.
Functions ¶
func HasOptOutSelector ¶
HasOptOutSelector checks to see whether the given context has been marked as having opted-out behaviour for bindings webhook.
func NewAdmissionController ¶
func NewAdmissionController( ctx context.Context, name, path string, gla GetListAll, WithContext BindableContext, ) *controller.Impl
NewAdmissionController constructs the webhook portion of the pair of reconcilers that implement the semantics of our Binding.
Types ¶
type BaseReconciler ¶
type BaseReconciler struct { // The GVR of the "primary key" resource for this reconciler. // This is used along with the DynamicClient for updating the status // and managing finalizers of the resources being reconciled. GVR schema.GroupVersionResource // Get is a callback that fetches the Bindable with the provided name // and namespace (for this GVR). Get func(namespace string, name string) (Bindable, error) // WithContext is a callback that infuses the context supplied to // Do/Undo with additional context to enable them to complete their // respective tasks. WithContext BindableContext // DynamicClient is used to patch subjects and apply mutations to // Bindable resources (determined by GVR) to reflect status updates. DynamicClient dynamic.Interface // Factory is used for producing listers for the object references we // encounter. Factory duck.InformerFactory // The tracker builds an index of what resources are watching other // resources so that we can immediately react to changes to changes in // tracked resources. Tracker tracker.Interface // Recorder is an event recorder for recording Event resources to the // Kubernetes API. Recorder record.EventRecorder }
BaseReconciler helps implement controller.Reconciler for Binding resources.
func (*BaseReconciler) EnsureFinalizer ¶
EnsureFinalizer makes sure that the provided resource has a finalizer in the form of this BaseReconciler's GVR's stringified GroupResource.
func (*BaseReconciler) IsFinalizing ¶
IsFinalizing determines whether it is our reconciler's turn to finalize a resource in the process of being deleted. This means that our finalizer is at the head of the metadata.finalizers list.
func (*BaseReconciler) Reconcile ¶
func (r *BaseReconciler) Reconcile(ctx context.Context, key string) error
Reconcile implements controller.Reconciler
func (*BaseReconciler) ReconcileDeletion ¶
func (r *BaseReconciler) ReconcileDeletion(ctx context.Context, fb Bindable) error
ReconcileDeletion handles reconcile a resource that is being deleted, which amounts to properly finalizing the resource.
func (*BaseReconciler) ReconcileSubject ¶
func (r *BaseReconciler) ReconcileSubject(ctx context.Context, fb Bindable, mutation Mutation) error
ReconcileSubject handles applying the provided Binding "mutation" (Do or Undo) to the Binding's subject(s).
func (*BaseReconciler) RemoveFinalizer ¶
RemoveFinalizer is the dual of EnsureFinalizer, it removes our finalizer from the Binding resource
func (*BaseReconciler) UpdateStatus ¶
func (r *BaseReconciler) UpdateStatus(ctx context.Context, desired Bindable) error
UpdateStatus updates the status of the resource. Caller is responsible for checking for semantic differences before calling.
type Bindable ¶
type Bindable interface { duck.Bindable // Do performs this binding's mutation with the specified context on the // provided PodSpecable. The provided context may be decorated by // passing a BindableContext to both NewAdmissionController and // BaseReconciler. Do(context.Context, *duckv1.WithPod) // Undo is the dual of Do, it undoes the binding. Undo(context.Context, *duckv1.WithPod) }
Bindable is implemented by Binding resources whose subjects are PodSpecable and that want to leverage this shared logic to simplify binding authorship.
type BindableContext ¶
BindableContext is the type of context decorator methods that may be supplied to NewAdmissionController and BaseReconciler.
type GetListAll ¶
type GetListAll func(context.Context, cache.ResourceEventHandler) ListAll
GetListAll is a factory method for the ListAll method, which may also be supplied with a ResourceEventHandler to register a callback with the Informer that sits behind the returned ListAll so that the handler can queue work whenever the result of ListAll changes.
type ListAll ¶
ListAll is the type of methods for enumerating all of the Bindables on the cluster in order to index the covered types to program the admission webhook.
type Reconciler ¶
type Reconciler struct { Name string HandlerPath string SecretName string Client kubernetes.Interface MWHLister admissionlisters.MutatingWebhookConfigurationLister SecretLister corelisters.SecretLister ListAll ListAll // WithContext is a callback that infuses the context supplied to // Do/Undo with additional context to enable them to complete their // respective tasks. WithContext BindableContext // contains filtered or unexported fields }
Reconciler implements an AdmissionController for altering PodSpecable resources that are the subject of a particular type of Binding. The two key methods are:
- reconcileMutatingWebhook: which enumerates all of the Bindings and compiles a list of resource types that should be intercepted by our webhook. It also builds an index that can be used to efficiently handle Admit requests.
- Admit: which leverages the index built by the Reconciler to apply mutations to resources.
func (*Reconciler) Admit ¶
func (ac *Reconciler) Admit(ctx context.Context, request *admissionv1beta1.AdmissionRequest) *admissionv1beta1.AdmissionResponse
Admit implements AdmissionController