reflector

package
v1.16.0-pre.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

The reflector package provides a set of utilities to reflect external data into a statedb table.

Index

Constants

View Source
const (
	// DefaultBufferSize is the maximum number of objects to commit to the table in one write transaction.
	DefaultBufferSize = 64

	// DefaultBufferWaitTime is the amount of time to wait to fill the buffer before committing objects.
	DefaultBufferWaitTime = 50 * time.Millisecond
)

Variables

This section is empty.

Functions

func KubernetesCell

func KubernetesCell[Obj any]() cell.Cell

KubernetesCell constructs a cell that constructs a Kubernetes source and adds it to the application lifecycle. If you need dynamic control over if and when to start or stop the reflection, use Kubernetes and call Reflector.Start and Reflector.Stop manually.

For dependencies needed by this cell see KubernetesParams.

Types

type KubernetesConfig

type KubernetesConfig[Obj any] struct {
	BufferSize     int                  // Maximum number of objects to commit in one transaction. Uses default if left zero.
	BufferWaitTime time.Duration        // The amount of time to wait for the buffer to fill. Uses default if left zero.
	ListerWatcher  cache.ListerWatcher  // The ListerWatcher to use to retrieve the objects
	Transform      TransformFunc[Obj]   // Optional function to transform the objects given by the ListerWatcher
	QueryAll       QueryAllFunc[Obj]    // Optional function to query all objects
	Table          statedb.RWTable[Obj] // The table to populate
}

type KubernetesParams

type KubernetesParams[Obj any] struct {
	cell.In

	Config KubernetesConfig[Obj]
	Jobs   job.Registry
	Health cell.Health
	DB     *statedb.DB
}

type QueryAllFunc

type QueryAllFunc[Obj any] func(statedb.ReadTxn, statedb.Table[Obj]) statedb.Iterator[Obj]

QueryAllFunc is an optional function to give to the Kubernetes reflector to query all objects in the table that are managed by the reflector. It is used to delete all objects when the underlying cache.Reflector needs to Replace() all items for a resync.

type Reflector

type Reflector[Obj any] interface {
	cell.HookInterface // Can be started and stopped.
}

Reflector reflects external data into a statedb table

func Kubernetes

func Kubernetes[Obj any](p KubernetesParams[Obj]) Reflector[Obj]

Kubernetes synchronizes statedb table with an external Kubernetes resource. Returns a 'Reflector' for starting and stopping it. If the source can be started unconditionally, consider using KubernetesCell instead.

type TransformFunc

type TransformFunc[Obj any] func(any) (obj Obj, ok bool)

TransformFunc is an optional function to give to the Kubernetes reflector to transform the object returned by the ListerWatcher to the desired target object. If the function returns false the object is silently skipped.

Jump to

Keyboard shortcuts

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