krt

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const EnableAssertions = false

EnableAssertions, if true, will enable assertions. These typically are violations of the krt collection requirements.

Variables

View Source
var GlobalDebugHandler = new(DebugHandler)

Functions

func Equal

func Equal[O any](a, b O) bool

func Fetch

func Fetch[T any](ctx HandlerContext, cc Collection[T], opts ...FetchOption) []T

func FetchOne

func FetchOne[T any](ctx HandlerContext, c Collection[T], opts ...FetchOption) *T

func GetApplyConfigKey

func GetApplyConfigKey[O any](a O) *string

GetApplyConfigKey returns the key for the ApplyConfig. If there is none, this will return nil.

func GetKey

func GetKey[O any](a O) string

GetKey returns the key for the provided object. If there is none, this will panic.

func GetStop

func GetStop(opts ...CollectionOption) <-chan struct{}

Types

type BuilderOption

type BuilderOption func(opt CollectionOption) OptionsBuilder

type Collection

type Collection[T any] interface {
	GetKey(k string) *T
	List() []T
	EventStream[T]
	Metadata() Metadata
}

func NewCollection

func NewCollection[I, O any](c Collection[I], hf TransformationSingle[I, O], opts ...CollectionOption) Collection[O]

NewCollection transforms a Collection[I] to a Collection[O] by applying the provided transformation function. This applies for one-to-one relationships between I and O. For zero-to-one, use NewSingleton. For one-to-many, use NewManyCollection.

type CollectionDump

type CollectionDump struct {
	// Map of output key -> output
	Outputs map[string]any `json:"outputs,omitempty"`
	// Name of the input collection
	InputCollection string `json:"inputCollection,omitempty"`
	// Map of input key -> info
	Inputs map[string]InputDump `json:"inputs,omitempty"`
	// Synced returns whether the collection is synced or not
	Synced bool `json:"synced"`
}

type CollectionOption

type CollectionOption func(*collectionOptions)

func WithDebugging

func WithDebugging(handler *DebugHandler) CollectionOption

func WithName

func WithName(name string) CollectionOption

func WithObjectAugmentation

func WithObjectAugmentation(fn func(o any) any) CollectionOption

func WithStop

func WithStop(stop <-chan struct{}) CollectionOption

type DebugCollection

type DebugCollection struct {
	// contains filtered or unexported fields
}

func (DebugCollection) MarshalJSON

func (p DebugCollection) MarshalJSON() ([]byte, error)

type DebugHandler

type DebugHandler struct {
	// contains filtered or unexported fields
}

DebugHandler allows attaching a variety of collections to it and then dumping them

func (*DebugHandler) MarshalJSON

func (p *DebugHandler) MarshalJSON() ([]byte, error)

type Equaler

type Equaler[K any] interface {
	Equals(k K) bool
}

type Event

type Event[T any] struct {
	Old   *T
	New   *T
	Event controllers.EventType
}

func (Event[T]) Items

func (e Event[T]) Items() []T

func (Event[T]) Latest

func (e Event[T]) Latest() T

type EventStream

type EventStream[T any] interface {
	Syncer
	Register(f func(o Event[T])) HandlerRegistration
	RegisterBatch(f func(o []Event[T]), runExistingState bool) HandlerRegistration
}

type FetchOption

type FetchOption func(*dependency)

func FilterKey

func FilterKey(k string) FetchOption

type HandlerContext

type HandlerContext interface {
	DiscardResult()
	// contains filtered or unexported methods
}

type HandlerRegistration

type HandlerRegistration interface {
	Syncer
	UnregisterHandler()
}

type Index

type Index[K comparable, O any] interface {
	Lookup(k K) []O
	AsCollection(opts ...CollectionOption) Collection[IndexObject[K, O]]
	// contains filtered or unexported methods
}

func NewIndex

func NewIndex[K comparable, O any](
	c Collection[O],
	name string,
	extract func(o O) []K,
) Index[K, O]

type IndexObject

type IndexObject[K comparable, O any] struct {
	Key     K
	Objects []O
}

func (IndexObject[K, O]) ResourceName

func (i IndexObject[K, O]) ResourceName() string

type InputDump

type InputDump struct {
	Outputs      []string `json:"outputs,omitempty"`
	Dependencies []string `json:"dependencies,omitempty"`
}

type Key

type Key[O any] string

type LabelSelectorer

type LabelSelectorer interface {
	GetLabelSelector() map[string]string
}

type Labeler

type Labeler interface {
	GetLabels() map[string]string
}

type Metadata

type Metadata map[string]any

type Named

type Named struct {
	Name, Namespace string
}

Named is a convenience struct. It is ideal to be embedded into a type that has a name and namespace, and will automatically implement the various interfaces to return the name, namespace, and a key based on these two.

func (Named) GetName

func (n Named) GetName() string

func (Named) GetNamespace

func (n Named) GetNamespace() string

func (Named) ResourceName

func (n Named) ResourceName() string

type ObjectDecorator

type ObjectDecorator interface {
	GetObjectKeyable() any
}

type OptionsBuilder

type OptionsBuilder struct {
	// contains filtered or unexported fields
}

func NewOptionsBuilder

func NewOptionsBuilder(stop <-chan struct{}, namePrefix string, debugger *DebugHandler) OptionsBuilder

func (OptionsBuilder) Debugger

func (k OptionsBuilder) Debugger() *DebugHandler

func (OptionsBuilder) Stop

func (k OptionsBuilder) Stop() <-chan struct{}

func (OptionsBuilder) With

func (OptionsBuilder) WithName

func (k OptionsBuilder) WithName(n string) []CollectionOption

type RecomputeProtected

type RecomputeProtected[T any] struct {
	// contains filtered or unexported fields
}

func NewRecomputeProtected

func NewRecomputeProtected[T any](initialData T, startSynced bool, opts ...CollectionOption) RecomputeProtected[T]

NewRecomputeProtected builds a RecomputeProtected which wraps some data, ensuring it is always MarkDependant when accessed

func (RecomputeProtected[T]) AccessUnprotected

func (c RecomputeProtected[T]) AccessUnprotected() T

AccessUnprotected returns the data without marking as dependant. This must be used with caution; any use within a collection is likely broken

func (RecomputeProtected[T]) Get

func (c RecomputeProtected[T]) Get(ctx HandlerContext) T

Get marks us as dependent on the value and fetches it.

func (RecomputeProtected[T]) MarkSynced

func (c RecomputeProtected[T]) MarkSynced()

MarkSynced marks this trigger as ready. Before this is called, dependant collections will be blocked. This ensures initial state is populated.

func (RecomputeProtected[T]) Modify

func (c RecomputeProtected[T]) Modify(fn func(*T))

Modify modifies the object and triggers a recompution.

func (RecomputeProtected[T]) TriggerRecomputation

func (c RecomputeProtected[T]) TriggerRecomputation()

TriggerRecomputation tells all dependants to recompute

type RecomputeTrigger

type RecomputeTrigger struct {
	// contains filtered or unexported fields
}

RecomputeTrigger trigger provides an escape hatch to allow krt transformations to depend on external state and recompute correctly when those change. Typically, all state is registered and fetched through krt.Fetch. Through this mechanism, any changes are automatically propagated through the system to dependencies. In some cases, it may not be feasible to get all state into krt; hopefully, this is a temporary state. RecomputeTrigger works around this by allowing an explicit call to recompute a collection; the caller must be sure to call Trigger() any time the state changes.

func NewRecomputeTrigger

func NewRecomputeTrigger(startSynced bool, opts ...CollectionOption) *RecomputeTrigger

func (*RecomputeTrigger) MarkDependant

func (r *RecomputeTrigger) MarkDependant(ctx HandlerContext)

MarkDependant marks the given context as depending on this trigger. This registers it to be recomputed when TriggerRecomputation is called.

func (*RecomputeTrigger) MarkSynced

func (r *RecomputeTrigger) MarkSynced()

MarkSynced marks this trigger as ready. Before this is called, dependant collections will be blocked. This ensures initial state is populated.

func (*RecomputeTrigger) TriggerRecomputation

func (r *RecomputeTrigger) TriggerRecomputation()

TriggerRecomputation tells all dependants to recompute

type ResourceNamer

type ResourceNamer interface {
	ResourceName() string
}

type Singleton

type Singleton[T any] interface {
	Get() *T
	Register(f func(o Event[T])) HandlerRegistration
	AsCollection() Collection[T]
	Metadata() Metadata
}

func NewSingleton

func NewSingleton[O any](hf TransformationEmpty[O], opts ...CollectionOption) Singleton[O]

type StaticSingleton

type StaticSingleton[T any] interface {
	Singleton[T]
	Set(*T)
	MarkSynced()
}

func NewStatic

func NewStatic[T any](initial *T, startSynced bool, opts ...CollectionOption) StaticSingleton[T]

type Syncer

type Syncer interface {
	WaitUntilSynced(stop <-chan struct{}) bool
	HasSynced() bool
}

type TransformationEmpty

type TransformationEmpty[T any] func(ctx HandlerContext) *T

type TransformationMulti

type TransformationMulti[I, O any] func(ctx HandlerContext, i I) []O

type TransformationSingle

type TransformationSingle[I, O any] func(ctx HandlerContext, i I) *O

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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