filter

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidFilterParams describes an error where invalid parameters were given
	// to a filter.
	ErrInvalidFilterParams = errors.New("invalid parameters given to filter")
)

Functions

This section is empty.

Types

type ListFilter

type ListFilter interface {
	// Filter walks through all objects in obj, assesses whether the object
	// matches the filter parameters, and conditionally adds it to the return
	// slice or not. This method can be thought of like an UNIX pipe.
	Filter(objs ...runtime.Object) ([]runtime.Object, error)
}

ListFilter is an interface for pipe-like list filtering behavior.

func ObjectToListFilter

func ObjectToListFilter(of ObjectFilter) ListFilter

ObjectToListFilter transforms an ObjectFilter into a ListFilter. If of is nil, this function panics.

type ListOption

type ListOption interface {
	// ApplyToListOptions applies the configuration of the current object into a target ListOptions struct.
	ApplyToListOptions(target *ListOptions) error
}

ListOption is an interface which can be passed into e.g. List() methods as a variadic-length argument list.

type ListOptions

type ListOptions struct {
	// Filters contains a chain of ListFilters, which will be processed in order and pipe the
	// available objects through before returning.
	Filters []ListFilter
}

ListOptions is a generic struct for listing options.

func MakeListOptions

func MakeListOptions(opts ...ListOption) (*ListOptions, error)

MakeListOptions makes a completed ListOptions struct from a list of ListOption implementations.

type NameFilter

type NameFilter struct {
	// Name matches the object by .metadata.name.
	// +required
	Name string
	// Namespace matches the object by .metadata.namespace. If left as
	// an empty string, it is ignored when filtering.
	// +optional
	Namespace string
	// MatchPrefix whether the name (not namespace) matching should be exact, or prefix-based.
	// +optional
	MatchPrefix bool
}

NameFilter is an ObjectFilter that compares runtime.Object.GetName() to the Name field by either equality or prefix.

func (NameFilter) ApplyToListOptions

func (f NameFilter) ApplyToListOptions(target *ListOptions) error

ApplyToListOptions implements ListOption, and adds itself converted to a ListFilter to ListOptions.Filters.

func (NameFilter) Filter

func (f NameFilter) Filter(obj runtime.Object) (bool, error)

Filter implements ObjectFilter

type ObjectFilter

type ObjectFilter interface {
	// Filter takes in one object (at once, per invocation), and returns a
	// boolean whether the object matches the filter parameters, or not.
	Filter(obj runtime.Object) (bool, error)
}

ObjectFilter is an interface for filtering objects one-by-one.

type UIDFilter

type UIDFilter struct {
	// UID matches the object by .metadata.uid.
	// +required
	UID types.UID
	// MatchPrefix whether the UID-matching should be exact, or prefix-based.
	// +optional
	MatchPrefix bool
}

UIDFilter is an ObjectFilter that compares runtime.Object.GetUID() to the UID field by either equality or prefix. The UID field is required, otherwise ErrInvalidFilterParams is returned.

func (UIDFilter) ApplyToListOptions

func (f UIDFilter) ApplyToListOptions(target *ListOptions) error

ApplyToListOptions implements ListOption, and adds itself converted to a ListFilter to ListOptions.Filters.

func (UIDFilter) Filter

func (f UIDFilter) Filter(obj runtime.Object) (bool, error)

Filter implements ObjectFilter

Jump to

Keyboard shortcuts

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