k8s

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResource

func NewResource[T k8sRuntime.Object](rootCtx context.Context, lw cache.ListerWatcher) (src stream.Observable[Event[T]], run func())

NewResource creates a stream of events from a ListerWatcher. The initial set of objects is emitted first as UpdateEvents, followed by a SyncEvent, after which updates follow. Returns the observable and the function to run the resource.

func NewResourceFromClient

func NewResourceFromClient[T k8sRuntime.Object](
	ctx context.Context,
	resource string,
	namespace string,
	client rest.Interface,
) (src stream.Observable[Event[T]], run func())

NewResourceFromClient creates a stream of events from a k8s REST client for the given resource and namespace.

func NewResourceFromListWatch

func NewResourceFromListWatch[ObjT k8sRuntime.Object, ListT k8sRuntime.Object](ctx context.Context, lw TypedListerWatcher[ListT]) (src stream.Observable[Event[ObjT]], run func())

NewResourceFromListWatch creates a stream of events from the typed client, e.g. (kubernetes.Interface).Pods() etc.

Types

type DeleteEvent

type DeleteEvent[T k8sRuntime.Object] struct {
	Key Key
}

DeleteEvent is emitted when an object has been deleted

func (*DeleteEvent[T]) Dispatch

func (ev *DeleteEvent[T]) Dispatch(onSync func(), onUpdate func(Key, T), onDelete func(Key))

type Event

type Event[T k8sRuntime.Object] interface {

	// Dispatch dispatches to the right event handler. Prefer this over
	// type switch on event.
	Dispatch(
		onSync func(),
		onUpdate func(Key, T),
		onDelete func(Key),
	)
	// contains filtered or unexported methods
}

Event emitted from resource. One of SyncEvent, UpdateEvent or DeleteEvent.

type Key

type Key struct {
	// Name is the name of the object
	Name string

	// Namespace is the namespace, or empty if object is not namespaced.
	Namespace string
}

Key of an K8s object, e.g. name and optional namespace.

func NewKey

func NewKey(obj any) Key

func (Key) String

func (k Key) String() string

type SyncEvent

type SyncEvent[T k8sRuntime.Object] struct{}

SyncEvent is emitted when the store has completed the initial synchronization with the cluster.

func (*SyncEvent[T]) Dispatch

func (*SyncEvent[T]) Dispatch(onSync func(), onUpdate func(Key, T), onDelete func(Key))

type TypedListerWatcher

type TypedListerWatcher[ListT k8sRuntime.Object] interface {
	List(context.Context, metav1.ListOptions) (ListT, error)
	Watch(context.Context, metav1.ListOptions) (watch.Interface, error)
}

TypedListerWatcher is the interface implemented by the generated clients.

type UpdateEvent

type UpdateEvent[T k8sRuntime.Object] struct {
	Key    Key
	Object T
}

UpdateEvent is emitted when an object has been added or updated

func (*UpdateEvent[T]) Dispatch

func (ev *UpdateEvent[T]) Dispatch(onSync func(), onUpdate func(Key, T), onDelete func(Key))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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