Documentation
¶
Index ¶
- Constants
- Variables
- func Equal[O any](a, b O) bool
- func Fetch[T any](ctx HandlerContext, cc Collection[T], opts ...FetchOption) []T
- func FetchOne[T any](ctx HandlerContext, c Collection[T], opts ...FetchOption) *T
- func GetApplyConfigKey[O any](a O) *string
- func GetKey[O any](a O) string
- func GetStop(opts ...CollectionOption) <-chan struct{}
- type BuilderOption
- type Collection
- type CollectionDump
- type CollectionOption
- type DebugCollection
- type DebugHandler
- type Equaler
- type Event
- type EventStream
- type FetchOption
- type HandlerContext
- type HandlerRegistration
- type Index
- type IndexObject
- type InputDump
- type Key
- type LabelSelectorer
- type Labeler
- type Metadata
- type Named
- type ObjectDecorator
- type OptionsBuilder
- type RecomputeProtected
- type RecomputeTrigger
- type ResourceNamer
- type Singleton
- type StaticSingleton
- type Syncer
- type TransformationEmpty
- type TransformationMulti
- type TransformationSingle
Constants ¶
const EnableAssertions = false
EnableAssertions, if true, will enable assertions. These typically are violations of the krt collection requirements.
Variables ¶
var GlobalDebugHandler = new(DebugHandler)
Functions ¶
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 ¶
GetApplyConfigKey returns the key for the ApplyConfig. If there is none, this will return nil.
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.
func WrapClient ¶
func WrapClient[I controllers.ComparableObject](c kclient.Informer[I], opts ...CollectionOption) Collection[I]
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 Event ¶
type Event[T any] struct { Old *T New *T Event controllers.EventType }
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 LabelSelectorer ¶
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) GetNamespace ¶
func (Named) ResourceName ¶
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 (k OptionsBuilder) With(opts ...CollectionOption) []CollectionOption
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 ¶
func NewStatic ¶
func NewStatic[T any](initial *T, startSynced bool, opts ...CollectionOption) StaticSingleton[T]
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