eval

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analyzer

type Analyzer interface {
	Analyze(obj *status.Object) status.ObjectStatus
	// Supports should return true if the particular analyzer supports
	// the given resource.
	//
	// It's used when searching the appropriate analyzer in the register.
	Supports(obj *status.Object) bool
}

Analyzer calculates status for the object.

type AnalyzerInit

type AnalyzerInit func(*Evaluator) Analyzer

AnalyzerInit is a function that initializes an Analyzer and can optionally pass an Evaluator reference to it.

type Evaluator

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

Evaluator is the entry structure for the status evaluation cycle.

It peformes the following steps:

  • Loading fresh data for the object (though the Loader struct).
  • Finding an appropriate Analyzer for the object.
  • Evaluating the Analyzer on the object.

func NewEvaluator

func NewEvaluator(ctx context.Context, analyzerInits []AnalyzerInit, config RESTClientGetter) (*Evaluator, error)

NewEvaluator creates a new Evaluator instance.

func (*Evaluator) Eval

func (e *Evaluator) Eval(obj *status.Object) status.ObjectStatus

Evaluates the status of the object. It gets the most recent version of the object and runs the appropriate analyzer on it.

func (*Evaluator) EvalQuery

func (e *Evaluator) EvalQuery(q QuerySpec, analyzer Analyzer) ([]status.ObjectStatus, error)

EvalQuery loads the objects specified by the query and runs the analyzer. If the analyzer is not provided, it tries to find the appropriate one in the register.

func (*Evaluator) Load

func (e *Evaluator) Load(q QuerySpec) ([]*status.Object, error)

Load loads the objects specified by the query.

func (*Evaluator) Reset

func (e *Evaluator) Reset()

Reset clears the cache of the evaluator.

type GroupKindMatcher

type GroupKindMatcher struct {
	// IncludeAll specifies whether all kinds should be included.
	// If true, the IncludedKinds are ignored.
	IncludeAll bool

	// IncludedKinds specifies the kinds to include. It's mutually exclusive
	// with IncludeAll.
	IncludedKinds []schema.GroupKind

	// ExcludedKinds specifies the kinds to exclude. It's only used with
	// IncludeAll.
	ExcludedKinds []schema.GroupKind
}

GroupKindMatcher allows specifying a set of kinds to match.

func NewGroupKindMatcherSingle

func NewGroupKindMatcherSingle(kind schema.GroupKind) GroupKindMatcher

NewGroupKindMatcherSingle returns a new GroupKindMatcher that matches only a single kind.

func (GroupKindMatcher) Equal

func (m GroupKindMatcher) Equal(other GroupKindMatcher) bool

func (GroupKindMatcher) Match

func (m GroupKindMatcher) Match(gk schema.GroupKind) bool

func (GroupKindMatcher) Merge

Merge returns a new GroupKindMatcher that matches the union of the kinds matched by the receiver and the other matcher.

type LabelQuerySpec

type LabelQuerySpec struct {
	Object   *status.Object
	GK       GroupKindMatcher
	Selector labels.Selector
}

LabelQuerySpec is a query that returns objects based on the labels selector. The namespace is taken from the Object.

func NewSelectorLabelEqualityQuerySpec

func NewSelectorLabelEqualityQuerySpec(obj *status.Object, gk schema.GroupKind) LabelQuerySpec

func NewSelectorLabelQuerySpec

func NewSelectorLabelQuerySpec(obj *status.Object, gk schema.GroupKind) LabelQuerySpec

func (LabelQuerySpec) Eval

func (qs LabelQuerySpec) Eval(l *Loader) []*status.Object

func (LabelQuerySpec) GroupKindMatcher

func (qs LabelQuerySpec) GroupKindMatcher() GroupKindMatcher

func (LabelQuerySpec) Namespace

func (qs LabelQuerySpec) Namespace() string

type Loader

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

Loader is responsible for loading and caching the objects from the cluster. It also allows finding objects based on their ownership relations.

func NewLoader

func NewLoader(config RESTClientGetter) (*Loader, error)

func (*Loader) Filter

func (l *Loader) Filter(ns string, matcher GroupKindMatcher) []*status.Object

Filter returns the objects from the cache that match the matcher. It expects the objects to be in the cache. This methods is intended to run during evaluation of the Load method in the following order:

  1. The Load method runs preloadQuery to fill in the cache.
  2. The Load method runs Eval on the query spec to get the objects.
  3. The Eval method runs Filter to get the objects from the cache.

We need to run the preloadQuery before the Eval method to support searching for objects based on the ownership relations.

func (*Loader) Get

func (l *Loader) Get(ctx context.Context, obj *status.Object) (*status.Object, error)

Get returns the updated version of the object. If the object is not in the cache, it loads it from the cluster first.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context, q QuerySpec) ([]*status.Object, error)

Load loads the objects specified by the query. It uses the cache to avoid loading the same objects multiple times.

type OwnerQuerySpec

type OwnerQuerySpec struct {
	Object *status.Object
	GK     GroupKindMatcher
	// NamespaceOverride specifies the namespace of the child object.
	// If nil, the namespace of the Object is used.
	NamespaceOverride *string
}

OwnerQuerySpec is a query that returns objects owned by the specified object.

func (OwnerQuerySpec) Eval

func (qs OwnerQuerySpec) Eval(l *Loader) []*status.Object

func (OwnerQuerySpec) GroupKindMatcher

func (qs OwnerQuerySpec) GroupKindMatcher() GroupKindMatcher

func (OwnerQuerySpec) Namespace

func (qs OwnerQuerySpec) Namespace() string

type PodLogQuerySpec

type PodLogQuerySpec struct {
	Object    *status.Object
	Container string
}

PodLogQuerySpec is a query that returns logs of the specified pod.

func (PodLogQuerySpec) Eval

func (qs PodLogQuerySpec) Eval(l *Loader) []*status.Object

func (PodLogQuerySpec) GroupKindMatcher

func (qs PodLogQuerySpec) GroupKindMatcher() GroupKindMatcher

func (PodLogQuerySpec) Namespace

func (qs PodLogQuerySpec) Namespace() string

type QuerySpec

type QuerySpec interface {
	// GroupKindMatcher specifies the kinds of objects to load.
	GroupKindMatcher() GroupKindMatcher

	// Namespace specifies the namespace of the objects to load.
	// Together with the GroupKindMatcher, it's used to preload the objects
	// into the Loader's cache.
	Namespace() string

	// Eval evaluates the query and returns the objects.
	// If applicable, the loader is already preloaded with the objects based
	// on the GroupKindMatcher and Namespace. It's still the repsonsibility
	// of the Eval method to do the final filtering.
	Eval(l *Loader) []*status.Object
}

QuerySpec is a specification of a query for objects.

It's a generic interface Loader understands to load objects. The methods are used for preloading the objects before the actual evaluation.

type RESTClientGetter

type RESTClientGetter interface {
	ToRESTConfig() (*rest.Config, error)
	ToDiscoveryClient() (discoveryclient.CachedDiscoveryInterface, error)
	ToRESTMapper() (meta.RESTMapper, error)
}

RESTClientGetter is an interface with a subset of k8s.io/cli-runtime/pkg/genericclioptions.RESTClientGetter, We reduce it only to the methods we need.

type RefQuerySpec

type RefQuerySpec struct {
	Object    *status.Object
	RefObject corev1.ObjectReference
}

RefQuerySpec is a query that returns objects referenced by the specified object. It assumes the reference to be in the same namespace.

func (RefQuerySpec) Eval

func (qs RefQuerySpec) Eval(l *Loader) []*status.Object

func (RefQuerySpec) GroupKindMatcher

func (qs RefQuerySpec) GroupKindMatcher() GroupKindMatcher

func (RefQuerySpec) Namespace

func (qs RefQuerySpec) Namespace() string

type StatusPoller

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

StatusPoller polls the status of a set of objects at a regular interval.

func NewStatusPoller

func NewStatusPoller(interval time.Duration, evaluator *Evaluator, objects []*status.Object) *StatusPoller

func (*StatusPoller) Start

func (s *StatusPoller) Start(ctx context.Context) <-chan StatusUpdate

Start starts the poller and returns a channel that will receive status updates. The poller will run until the context is canceled. The channel will be closed when the context is canceled.

type StatusUpdate

type StatusUpdate struct {
	Statuses []status.ObjectStatus
	Error    error
}

Jump to

Keyboard shortcuts

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