kubeutil

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLinkedResourceHandler

func NewLinkedResourceHandler(
	cacheCtx context.Context,
	logger logr.Logger,
	scheme *runtime.Scheme,
	cache cache.Cache,
	objType client.Object,
	toId func(obj client.Object) []string,
	addToQueue func(q workqueue.RateLimitingInterface, req reconcile.Request),
) (handler.EventHandler, error)

NewLinkedResourceHandler returns a `handler.EventHandler` that can be passed to a `ctrl.Watch` function. Such a hander transforms the watch events that originate from the `source.Source` that was passed to `ctrl.Watch`. This LinkedResourceHandler transforms a watch event for a watched resource to events for all resources that link to this watched resource.

eg.: resources A1, A2 and A3 all have a spec field that contains the B1 resource
name. Now, we watch the B1 resource for changes and translate a watch event for
this resource to an event for resource A1, an event for A2 and an event for A3

To achieve this result performantly, we use a cache with an index. This cache contains all resources (A1, A2, ...) that reference resources we receive events for. We also register an index which is kept up-to-date by the cache when a resource (A1, A2, ...) is added, removed or update. This index contains unique "<namespace>/<name>" identifiers generated by the provided `toId` function. These identifiers represent what resource (B1, B2, ...) the resources in the cache (A1, A2, ...) link to. Lastly, the `addToQueue` function can be used to alter the operation that adds an item to the working queue. This makes it possible to, instead of adding the event in the queue, post events on a channel. The default nil value for `addToQueue` results in just using the `q.Add(req)` function to add events to the queue.

func NewListObject

func NewListObject(scheme *runtime.Scheme, gvk schema.GroupVersionKind) (client.ObjectList, error)

func SetGroupVersionKind

func SetGroupVersionKind(scheme *runtime.Scheme, obj client.Object) error

setGroupVersionKind populates the Group and Kind fields of obj using the scheme type registry. Inspired by https://github.com/kubernetes-sigs/controller-runtime/issues/1735#issuecomment-984763173

Types

type EventSource

type EventSource interface {
	AddConsumer(gvk schema.GroupVersionKind) source.Source
	ReportError(gvk schema.GroupVersionKind, namespacedName types.NamespacedName, err error) error
	HasReportedError(gvk schema.GroupVersionKind, namespacedName types.NamespacedName) error
}

func NewEventStore

func NewEventStore() EventSource

Jump to

Keyboard shortcuts

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