engine

package
v0.29.4 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: Apache-2.0 Imports: 11 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterReader

type ClusterReader interface {
	// Get looks up the resource identifier by the key and the GVK in the provided obj reference. If something
	// goes wrong or the resource doesn't exist, an error is returned.
	Get(ctx context.Context, key client.ObjectKey, obj *unstructured.Unstructured) error
	// ListNamespaceScoped looks up the resources of the GVK given in the list and matches the namespace and
	// selector provided.
	ListNamespaceScoped(ctx context.Context, list *unstructured.UnstructuredList,
		namespace string, selector labels.Selector) error
	// ListClusterScoped looks up the resources of the GVK given in the list and that matches the selector
	// provided.
	ListClusterScoped(ctx context.Context, list *unstructured.UnstructuredList, selector labels.Selector) error
	// Sync is called by the engine before every polling loop, which provides an opportunity for the Reader
	// to sync caches.
	Sync(ctx context.Context) error
}

ClusterReader is the interface provided to the statusReaders to talk to the cluster. Implementations of this interface allows different caching strategies, for example by pre-fetching resources using LIST calls rather than letting each engine run multiple GET calls against the cluster. This can significantly reduce the number of requests.

type ClusterReaderFactory added in v0.28.0

type ClusterReaderFactory interface {
	New(reader client.Reader, mapper meta.RESTMapper, identifiers object.ObjMetadataSet) (ClusterReader, error)
}

ClusterReaderFactory provides an interface that can be implemented to provide custom ClusterReader implementations in the StatusPoller.

type ClusterReaderFactoryFunc

type ClusterReaderFactoryFunc func(client.Reader, meta.RESTMapper, object.ObjMetadataSet) (ClusterReader, error)

func (ClusterReaderFactoryFunc) New added in v0.28.0

type Options added in v0.3.0

type Options struct {

	// PollInterval defines how often the PollerEngine should poll the cluster for the latest
	// state of the resources.
	PollInterval time.Duration
}

Options contains the different parameters that can be used to adjust the behavior of the PollerEngine. Timeout is not one of the options here as this should be accomplished by setting a timeout on the context: https://golang.org/pkg/context/

type PollerEngine

type PollerEngine struct {
	Reader               client.Reader
	Mapper               meta.RESTMapper
	StatusReaders        []StatusReader
	DefaultStatusReader  StatusReader
	ClusterReaderFactory ClusterReaderFactory
}

PollerEngine provides functionality for polling a cluster for status of a set of resources.

func (*PollerEngine) Poll

func (s *PollerEngine) Poll(ctx context.Context, identifiers object.ObjMetadataSet, options Options) <-chan event.Event

Poll will create a new statusPollerRunner that will poll all the resources provided and report their status back on the event channel returned. The statusPollerRunner can be cancelled at any time by cancelling the context passed in. The context can be used to stop the polling process by using timeout, deadline or cancellation.

type StatusReader

type StatusReader interface {
	// Supports tells the caller whether the StatusReader can compute status for
	// the provided GroupKind.
	Supports(schema.GroupKind) bool

	// ReadStatus will fetch the resource identified by the given identifier
	// from the cluster and return an ResourceStatus that will contain
	// information about the latest state of the resource, its computed status
	// and information about any generated resources. Errors would usually be
	// added to the event.ResourceStatus, but in the case of fatal errors
	// that aren't connected to the particular resource, an error can also
	// be returned. Currently, only context cancellation and deadline exceeded
	// will cause an error to be returned.
	ReadStatus(ctx context.Context, reader ClusterReader, resource object.ObjMetadata) (*event.ResourceStatus, error)

	// ReadStatusForObject is similar to ReadStatus, but instead of looking up the
	// resource based on an identifier, it will use the passed-in resource.
	// Errors would usually be added to the event.ResourceStatus, but in the case
	// of fatal errors that aren't connected to the particular resource, an error
	// can also be returned. Currently, only context cancellation and deadline exceeded
	// will cause an error to be returned.
	ReadStatusForObject(ctx context.Context, reader ClusterReader, object *unstructured.Unstructured) (*event.ResourceStatus, error)
}

StatusReader is the main interface for computing status for resources. In this context, a status reader is an object that can fetch a resource of a specific GroupKind from the cluster and compute its status. For resources that can own generated resources, the engine might also have knowledge about how to identify these generated resources and how to compute status for these generated resources.

Jump to

Keyboard shortcuts

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