Documentation
¶
Overview ¶
Package builder wraps other multicluster-runtime libraries and exposes simple patterns for building common Controllers.
This is a fork of the controller-runtime builder package, adapted to´ mult-cluster use.
Projects built with the builder package can trivially be rebased on top of the underlying packages if the project requires more customized behavior in the future.
Index ¶
- Variables
- type Builder
- type EngageOptions
- type ForInput
- type ForOption
- type OwnsInput
- type OwnsOption
- type Predicates
- type TypedBuilder
- func (blder *TypedBuilder[request]) Build(r reconcile.TypedReconciler[request]) (mccontroller.TypedController[request], error)
- func (blder *TypedBuilder[request]) Complete(r reconcile.TypedReconciler[request]) error
- func (blder *TypedBuilder[request]) For(object client.Object, opts ...ForOption) *TypedBuilder[request]
- func (blder *TypedBuilder[request]) Named(name string) *TypedBuilder[request]
- func (blder *TypedBuilder[request]) Owns(object client.Object, opts ...OwnsOption) *TypedBuilder[request]
- func (blder *TypedBuilder[request]) Watches(object client.Object, ...) *TypedBuilder[request]
- func (blder *TypedBuilder[request]) WatchesMetadata(object client.Object, ...) *TypedBuilder[request]
- func (blder *TypedBuilder[request]) WatchesRawSource(src source.TypedSource[request]) *TypedBuilder[request]
- func (blder *TypedBuilder[request]) WithEventFilter(p predicate.Predicate) *TypedBuilder[request]
- func (blder *TypedBuilder[request]) WithLogConstructor(logConstructor func(*request) logr.Logger) *TypedBuilder[request]
- func (blder *TypedBuilder[request]) WithOptions(options controller.TypedOptions[request]) *TypedBuilder[request]
- type WatchesInput
- type WatchesOption
- type WebhookBuilder
- func (blder *WebhookBuilder) Complete() error
- func (blder *WebhookBuilder) For(apiType runtime.Object) *WebhookBuilder
- func (blder *WebhookBuilder) RecoverPanic(recoverPanic bool) *WebhookBuilder
- func (blder *WebhookBuilder) WithCustomPath(customPath string) *WebhookBuilder
- func (blder *WebhookBuilder) WithDefaulter(defaulter admission.CustomDefaulter, opts ...admission.DefaulterOption) *WebhookBuilder
- func (blder *WebhookBuilder) WithLogConstructor(logConstructor func(base logr.Logger, req *admission.Request) logr.Logger) *WebhookBuilder
- func (blder *WebhookBuilder) WithValidator(validator admission.CustomValidator) *WebhookBuilder
Constants ¶
This section is empty.
Variables ¶
var MatchEveryOwner = &matchEveryOwner{}
MatchEveryOwner determines whether the watch should be filtered based on controller ownership. As in, when the OwnerReference.Controller field is set.
If passed as an option, the handler receives notification for every owner of the object with the given type. If unset (default), the handler receives notification only for the first OwnerReference with `Controller: true`.
var ( // OnlyMetadata tells the controller to *only* cache metadata, and to watch // the API server in metadata-only form. This is useful when watching // lots of objects, really big objects, or objects for which you only know // the GVK, but not the structure. You'll need to pass // metav1.PartialObjectMetadata to the client when fetching objects in your // reconciler, otherwise you'll end up with a duplicate structured or // unstructured cache. // // When watching a resource with OnlyMetadata, for example the v1.Pod, you // should not Get and List using the v1.Pod type. Instead, you should use // the special metav1.PartialObjectMetadata type. // // ❌ Incorrect: // // pod := &v1.Pod{} // mgr.GetClient().Get(ctx, nsAndName, pod) // // ✅ Correct: // // pod := &metav1.PartialObjectMetadata{} // pod.SetGroupVersionKind(schema.GroupVersionKind{ // Group: "", // Version: "v1", // Kind: "Pod", // }) // mgr.GetClient().Get(ctx, nsAndName, pod) // // In the first case, controller-runtime will create another cache for the // concrete type on top of the metadata cache; this increases memory // consumption and leads to race conditions as caches are not in sync. OnlyMetadata = projectAs(projectAsMetadata) )
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder = TypedBuilder[mcreconcile.Request]
Builder builds a Controller.
func ControllerManagedBy ¶
ControllerManagedBy returns a new controller builder that will be started by the provided Manager.
type EngageOptions ¶
type EngageOptions struct {
// contains filtered or unexported fields
}
EngageOptions configures how the controller should engage with clusters when a provider is configured.
func WithEngageWithLocalCluster ¶
func WithEngageWithLocalCluster(engage bool) EngageOptions
WithEngageWithLocalCluster configures whether the controller should engage with the local cluster of the manager (empty string). This defaults to false if a cluster provider is configured, and to true otherwise.
func WithEngageWithProviderClusters ¶
func WithEngageWithProviderClusters(engage bool) EngageOptions
WithEngageWithProviderClusters configured whether the controller should engage with the provider clusters of the manager. This defaults to true if a cluster provider is set, and has no effect otherwise.
func (EngageOptions) ApplyToFor ¶
func (w EngageOptions) ApplyToFor(opts *ForInput)
ApplyToFor applies this configuration to the given ForInput options.
func (EngageOptions) ApplyToOwns ¶
func (w EngageOptions) ApplyToOwns(opts *OwnsInput)
ApplyToOwns applies this configuration to the given OwnsInput options.
func (EngageOptions) ApplyToWatches ¶
func (w EngageOptions) ApplyToWatches(opts untypedWatchesInput)
ApplyToWatches applies this configuration to the given WatchesInput options.
type ForInput ¶
type ForInput struct { EngageOptions // contains filtered or unexported fields }
ForInput represents the information set by the For method.
type ForOption ¶
type ForOption interface { // ApplyToFor applies this configuration to the given for input. ApplyToFor(*ForInput) }
ForOption is some configuration that modifies options for a For request.
type OwnsInput ¶
type OwnsInput struct { EngageOptions // contains filtered or unexported fields }
OwnsInput represents the information set by Owns method.
type OwnsOption ¶
type OwnsOption interface { // ApplyToOwns applies this configuration to the given owns input. ApplyToOwns(*OwnsInput) }
OwnsOption is some configuration that modifies options for an owns request.
type Predicates ¶
type Predicates struct {
// contains filtered or unexported fields
}
Predicates filters events before enqueuing the keys.
func WithPredicates ¶
func WithPredicates(predicates ...predicate.Predicate) Predicates
WithPredicates sets the given predicates list.
func (Predicates) ApplyToFor ¶
func (w Predicates) ApplyToFor(opts *ForInput)
ApplyToFor applies this configuration to the given ForInput options.
func (Predicates) ApplyToOwns ¶
func (w Predicates) ApplyToOwns(opts *OwnsInput)
ApplyToOwns applies this configuration to the given OwnsInput options.
func (Predicates) ApplyToWatches ¶
func (w Predicates) ApplyToWatches(opts untypedWatchesInput)
ApplyToWatches applies this configuration to the given WatchesInput options.
type TypedBuilder ¶
type TypedBuilder[request mcreconcile.ClusterAware[request]] struct { // contains filtered or unexported fields }
TypedBuilder builds a Controller. The request is the request type that is passed to the workqueue and then to the Reconciler. The workqueue de-duplicates identical requests.
func TypedControllerManagedBy ¶
func TypedControllerManagedBy[request mcreconcile.ClusterAware[request]](m mcmanager.Manager) *TypedBuilder[request]
TypedControllerManagedBy returns a new typed controller builder that will be started by the provided Manager.
func (*TypedBuilder[request]) Build ¶
func (blder *TypedBuilder[request]) Build(r reconcile.TypedReconciler[request]) (mccontroller.TypedController[request], error)
Build builds the Application Controller and returns the Controller it created.
Note: use context.ReconcilerWithClusterInContext to inject the cluster name into the and to use Manager.GetClusterInContext to retrieve the cluster.
func (*TypedBuilder[request]) Complete ¶
func (blder *TypedBuilder[request]) Complete(r reconcile.TypedReconciler[request]) error
Complete builds the Application Controller.
Note: use context.ReconcilerWithClusterInContext to inject the cluster name into the and to use Manager.GetClusterInContext to retrieve the cluster.
func (*TypedBuilder[request]) For ¶
func (blder *TypedBuilder[request]) For(object client.Object, opts ...ForOption) *TypedBuilder[request]
For defines the type of Object being *reconciled*, and configures the ControllerManagedBy to respond to create / delete / update events by *reconciling the object*.
This is the equivalent of calling Watches(source.Kind(cache, &Type{}, &handler.EnqueueRequestForObject{})).
func (*TypedBuilder[request]) Named ¶
func (blder *TypedBuilder[request]) Named(name string) *TypedBuilder[request]
Named sets the name of the controller to the given name. The name shows up in metrics, among other things, and thus should be a prometheus compatible name (underscores and alphanumeric characters only).
By default, controllers are named using the lowercase version of their kind.
The name must be unique as it is used to identify the controller in metrics and logs.
func (*TypedBuilder[request]) Owns ¶
func (blder *TypedBuilder[request]) Owns(object client.Object, opts ...OwnsOption) *TypedBuilder[request]
Owns defines types of Objects being *generated* by the ControllerManagedBy, and configures the ControllerManagedBy to respond to create / delete / update events by *reconciling the owner object*.
The default behavior reconciles only the first controller-type OwnerReference of the given type. Use Owns(object, builder.MatchEveryOwner) to reconcile all owners.
By default, this is the equivalent of calling Watches(source.Kind(cache, &Type{}, handler.EnqueueRequestForOwner([...], &OwnerType{}, OnlyControllerOwner()))).
func (*TypedBuilder[request]) Watches ¶
func (blder *TypedBuilder[request]) Watches( object client.Object, eventHandler mchandler.TypedEventHandlerFunc[client.Object, request], opts ...WatchesOption, ) *TypedBuilder[request]
Watches defines the type of Object to watch, and configures the ControllerManagedBy to respond to create / delete / update events by *reconciling the object* with the given EventHandler.
This is the equivalent of calling WatchesRawSource(source.Kind(cache, object, eventHandler, predicates...)).
func (*TypedBuilder[request]) WatchesMetadata ¶
func (blder *TypedBuilder[request]) WatchesMetadata( object client.Object, eventHandler mchandler.TypedEventHandlerFunc[client.Object, request], opts ...WatchesOption, ) *TypedBuilder[request]
WatchesMetadata is the same as Watches, but forces the internal cache to only watch PartialObjectMetadata.
This is useful when watching lots of objects, really big objects, or objects for which you only know the GVK, but not the structure. You'll need to pass metav1.PartialObjectMetadata to the client when fetching objects in your reconciler, otherwise you'll end up with a duplicate structured or unstructured cache.
When watching a resource with metadata only, for example the v1.Pod, you should not Get and List using the v1.Pod type. Instead, you should use the special metav1.PartialObjectMetadata type.
❌ Incorrect:
pod := &v1.Pod{} mgr.GetClient().Get(ctx, nsAndName, pod)
✅ Correct:
pod := &metav1.PartialObjectMetadata{} pod.SetGroupVersionKind(schema.GroupVersionKind{ Group: "", Version: "v1", Kind: "Pod", }) mgr.GetClient().Get(ctx, nsAndName, pod)
In the first case, controller-runtime will create another cache for the concrete type on top of the metadata cache; this increases memory consumption and leads to race conditions as caches are not in sync.
func (*TypedBuilder[request]) WatchesRawSource ¶
func (blder *TypedBuilder[request]) WatchesRawSource(src source.TypedSource[request]) *TypedBuilder[request]
WatchesRawSource exposes the lower-level ControllerManagedBy Watches functions through the builder.
WatchesRawSource does not respect predicates configured through WithEventFilter.
WatchesRawSource makes it possible to use typed handlers and predicates with `source.Kind` as well as custom source implementations.
func (*TypedBuilder[request]) WithEventFilter ¶
func (blder *TypedBuilder[request]) WithEventFilter(p predicate.Predicate) *TypedBuilder[request]
WithEventFilter sets the event filters, to filter which create/update/delete/generic events eventually trigger reconciliations. For example, filtering on whether the resource version has changed. Given predicate is added for all watched objects and thus must be able to deal with the type of all watched objects.
Defaults to the empty list.
func (*TypedBuilder[request]) WithLogConstructor ¶
func (blder *TypedBuilder[request]) WithLogConstructor(logConstructor func(*request) logr.Logger) *TypedBuilder[request]
WithLogConstructor overrides the controller options's LogConstructor.
func (*TypedBuilder[request]) WithOptions ¶
func (blder *TypedBuilder[request]) WithOptions(options controller.TypedOptions[request]) *TypedBuilder[request]
WithOptions overrides the controller options used in doController. Defaults to empty.
type WatchesInput ¶
type WatchesInput[request mcreconcile.ClusterAware[request]] struct { EngageOptions // contains filtered or unexported fields }
WatchesInput represents the information set by Watches method.
type WatchesOption ¶
type WatchesOption interface {
// ApplyToWatches applies this configuration to the given watches options.
ApplyToWatches(untypedWatchesInput)
}
WatchesOption is some configuration that modifies options for a watches request.
type WebhookBuilder ¶
type WebhookBuilder struct {
// contains filtered or unexported fields
}
WebhookBuilder builds a Webhook.
func WebhookManagedBy ¶
func WebhookManagedBy(m manager.Manager) *WebhookBuilder
WebhookManagedBy returns a new webhook builder.
func (*WebhookBuilder) Complete ¶
func (blder *WebhookBuilder) Complete() error
Complete builds the webhook.
func (*WebhookBuilder) For ¶
func (blder *WebhookBuilder) For(apiType runtime.Object) *WebhookBuilder
For takes a runtime.Object which should be a CR. If the given object implements the admission.Defaulter interface, a MutatingWebhook will be wired for this type. If the given object implements the admission.Validator interface, a ValidatingWebhook will be wired for this type.
func (*WebhookBuilder) RecoverPanic ¶
func (blder *WebhookBuilder) RecoverPanic(recoverPanic bool) *WebhookBuilder
RecoverPanic indicates whether panics caused by the webhook should be recovered. Defaults to true.
func (*WebhookBuilder) WithCustomPath ¶
func (blder *WebhookBuilder) WithCustomPath(customPath string) *WebhookBuilder
WithCustomPath overrides the webhook's default path by the customPath
func (*WebhookBuilder) WithDefaulter ¶
func (blder *WebhookBuilder) WithDefaulter(defaulter admission.CustomDefaulter, opts ...admission.DefaulterOption) *WebhookBuilder
WithDefaulter takes an admission.CustomDefaulter interface, a MutatingWebhook with the provided opts (admission.DefaulterOption) will be wired for this type.
func (*WebhookBuilder) WithLogConstructor ¶
func (blder *WebhookBuilder) WithLogConstructor(logConstructor func(base logr.Logger, req *admission.Request) logr.Logger) *WebhookBuilder
WithLogConstructor overrides the webhook's LogConstructor.
func (*WebhookBuilder) WithValidator ¶
func (blder *WebhookBuilder) WithValidator(validator admission.CustomValidator) *WebhookBuilder
WithValidator takes a admission.CustomValidator interface, a ValidatingWebhook will be wired for this type.