safe

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MPL-2.0 Imports: 11 Imported by: 33 modules, 47 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package safe provides a safe wrappers around the cosi runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupOutputs added in v0.3.1

func CleanupOutputs[R generic.ResourceWithRD](ctx context.Context, tracker controller.OutputTracker) error

CleanupOutputs wraps the controller.OutputTracker.CleanupOutputs method.

func Input added in v0.3.1

Input returns a controller.Input for the given resource.

func Map added in v0.3.1

func Map[T resource.Resource, R any](list List[T], fn func(T) (R, error)) ([]R, error)

Map applies the given function to each element of the list and returns a new slice with the results. It returns an error if the given function had returned an error.

func ReaderGet

func ReaderGet[T resource.Resource](ctx context.Context, rdr controller.Reader, ptr resource.Pointer) (T, error)

ReaderGet is a type safe wrapper around reader.Get.

func ReaderGetByID added in v0.3.1

func ReaderGetByID[T generic.ResourceWithRD](ctx context.Context, rdr controller.Reader, id resource.ID) (T, error)

ReaderGetByID is a type safe wrapper around reader.Get.

func StateGet

func StateGet[T resource.Resource](ctx context.Context, st state.CoreStateReader, ptr resource.Pointer, options ...state.GetOption) (T, error)

StateGet is a type safe wrapper around state.Get.

func StateGetByID added in v0.3.1

func StateGetByID[T generic.ResourceWithRD](ctx context.Context, st state.CoreStateReader, id resource.ID, options ...state.GetOption) (T, error)

StateGetByID is a type safe wrapper around state.Get.

func StateGetResource

func StateGetResource[T resource.Resource](ctx context.Context, st state.CoreStateReader, r T, options ...state.GetOption) (T, error)

StateGetResource is a type safe wrapper around state.Get which accepts typed resource.Resource and gets the metadata from it.

func StateModify added in v0.10.6

func StateModify[T resource.Resource](ctx context.Context, st state.StateWriter, r T, fn func(T) error, options ...state.UpdateOption) error

StateModify is a type safe wrapper around state.Modify.

func StateModifyWithResult added in v0.10.6

func StateModifyWithResult[T resource.Resource](ctx context.Context, st state.StateWriter, r T, fn func(T) error, options ...state.UpdateOption) (T, error)

StateModifyWithResult is a type safe wrapper around state.ModifyWithResult.

func StateUpdateWithConflicts

func StateUpdateWithConflicts[T resource.Resource](ctx context.Context, st state.StateWriter, ptr resource.Pointer, updateFn func(T) error, options ...state.UpdateOption) (T, error)

StateUpdateWithConflicts is a type safe wrapper around state.UpdateWithConflicts.

func StateWatch

func StateWatch[T resource.Resource](ctx context.Context, st state.CoreStateWatcher, ptr resource.Pointer, eventCh chan<- WrappedStateEvent[T], opts ...state.WatchOption) error

StateWatch is a type safe wrapper around State.Watch.

func StateWatchFor

func StateWatchFor[T resource.Resource](ctx context.Context, st state.StateWatcher, ptr resource.Pointer, opts ...state.WatchForConditionFunc) (T, error)

StateWatchFor is a type safe wrapper around State.WatchFor.

func StateWatchKind

func StateWatchKind[T resource.Resource](ctx context.Context, st state.CoreStateWatcher, kind resource.Kind, eventCh chan<- WrappedStateEvent[T], opts ...state.WatchKindOption) error

StateWatchKind is a type safe wrapper around State.WatchKind.

func ToSlice added in v0.5.1

func ToSlice[T resource.Resource, R any](list List[T], fn func(T) R) []R

ToSlice applies the given function to each element of the list and returns a new slice with the results.

func WithResourceCache added in v0.4.0

func WithResourceCache[R generic.ResourceWithRD]() options.Option

WithResourceCache returns a controller runtime options.WithResourceCache.

func WriterModify

func WriterModify[T resource.Resource](ctx context.Context, writer controller.Writer, r T, fn func(T) error, options ...controller.ModifyOption) error

WriterModify is a type safe wrapper around writer.Modify.

func WriterModifyWithResult added in v0.3.14

func WriterModifyWithResult[T resource.Resource](ctx context.Context, writer controller.Writer, r T, fn func(T) error, options ...controller.ModifyOption) (T, error)

WriterModifyWithResult is a type safe wrapper around writer.ModifyWithResult.

Types

type List

type List[T ListedResource] struct {
	// contains filtered or unexported fields
}

List is a type safe wrapper around resource.List.

func NewList

func NewList[T ListedResource](list resource.List) List[T]

NewList creates a new List.

func ReaderList

func ReaderList[T resource.Resource](ctx context.Context, rdr controller.Reader, kind resource.Kind, opts ...state.ListOption) (List[T], error)

ReaderList is a type safe wrapper around Reader.List.

func ReaderListAll added in v0.3.1

func ReaderListAll[T generic.ResourceWithRD](ctx context.Context, rdr controller.Reader, opts ...state.ListOption) (List[T], error)

ReaderListAll is a type safe wrapper around Reader.List that uses default namespace and type from ResourceDefinitionProvider.

func StateList

func StateList[T resource.Resource](ctx context.Context, st state.CoreStateReader, ptr resource.Pointer, options ...state.ListOption) (List[T], error)

StateList is a type safe wrapper around state.List.

func StateListAll added in v0.3.1

func StateListAll[T generic.ResourceWithRD](ctx context.Context, st state.CoreStateReader, opts ...state.ListOption) (List[T], error)

StateListAll is a type safe wrapper around state.List that uses default namespace and type from ResourceDefinitionProvider.

func (*List[T]) All added in v0.6.0

func (l *List[T]) All() iter.Seq[T]

All returns a new rangefunc iterator over the list.

func (*List[T]) FilterLabelQuery added in v0.3.1

func (l *List[T]) FilterLabelQuery(opts ...resource.LabelQueryOption) List[T]

FilterLabelQuery returns a new list applying the resource label query.

func (*List[T]) Find added in v0.3.1

func (l *List[T]) Find(fn func(T) bool) (T, bool)

Find returns the first item in the list that matches the given predicate.

func (*List[T]) ForEach added in v0.3.1

func (l *List[T]) ForEach(fn func(T))

ForEach iterates over the given list and calls the given function for each element.

func (*List[T]) ForEachErr added in v0.3.1

func (l *List[T]) ForEachErr(fn func(T) error) error

ForEachErr iterates over the given list and calls the given function for each element. If the function returns an error, the iteration stops and the error is returned.

func (*List[T]) Get

func (l *List[T]) Get(index int) T

Get returns the item at the given index.

func (*List[T]) Index added in v0.3.1

func (l *List[T]) Index(fn func(T) bool) int

Index returns the index of the given item in the list.

func (*List[T]) Iterator deprecated added in v0.3.4

func (l *List[T]) Iterator() ListIterator[T]

Iterator returns a new iterator over the list.

Deprecated: use List.All instead.

func (*List[T]) Len

func (l *List[T]) Len() int

Len returns the number of items in the list.

func (*List[T]) Pointers added in v0.10.4

func (l *List[T]) Pointers() iter.Seq[resource.Pointer]

Pointers returns a new rangefunc iterator over each resource pointer in the list.

func (*List[T]) SortFunc added in v0.5.3

func (l *List[T]) SortFunc(cmp func(T, T) int)

SortFunc is a function that sorts the list.

func (*List[T]) Swap added in v0.5.1

func (l *List[T]) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type ListIterator

type ListIterator[T ListedResource] struct {
	// contains filtered or unexported fields
}

ListIterator is a generic iterator over resource.Resource slice.

func IteratorFromList deprecated

func IteratorFromList[T ListedResource](list List[T]) ListIterator[T]

IteratorFromList returns a new iterator over the given list.

Deprecated: use List.All instead.

func (*ListIterator[T]) Next

func (it *ListIterator[T]) Next() bool

Next returns the next element of the iterator.

func (*ListIterator[T]) Value

func (it *ListIterator[T]) Value() T

Value returns the current element of the iterator.

type ListedResource added in v1.10.7

type ListedResource interface {
	Metadata() *resource.Metadata
}

ListedResource is an interface that represents a resource in a list.

It is a subset of resource.Resource that only exposes required methods.

type WrappedStateEvent

type WrappedStateEvent[T resource.Resource] struct {
	// contains filtered or unexported fields
}

WrappedStateEvent holds a state.Event that can be cast to its original Resource type when accessed with Event().

func (*WrappedStateEvent[T]) Error added in v0.2.0

func (wse *WrappedStateEvent[T]) Error() error

Error returns the error of wrapped event.

func (*WrappedStateEvent[T]) Old

func (wse *WrappedStateEvent[T]) Old() (T, error)

Old returns the typed Old resource of the wrapped event.

func (*WrappedStateEvent[T]) Resource

func (wse *WrappedStateEvent[T]) Resource() (T, error)

Resource returns the typed resource of the wrapped event.

func (*WrappedStateEvent[T]) Type

func (wse *WrappedStateEvent[T]) Type() state.EventType

Type returns the EventType of the wrapped event.

Jump to

Keyboard shortcuts

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