conditions

package
Version: v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoOperatorCondition indicates that the operator condition CRD is nil
	ErrNoOperatorCondition = fmt.Errorf("operator Condition CRD is nil")
)

Functions

func GetNamespacedName deprecated

func GetNamespacedName() (*types.NamespacedName, error)

GetNamespacedName returns the NamespacedName of the CR. It returns an error when the name of the CR cannot be found from the environment variable set by OLM. Hence, GetNamespacedName() can provide the NamespacedName when the operator is running on cluster and is being managed by OLM. If running locally, operator writers are encouraged to skip this method or gracefully handle the errors by logging a message.

Deprecated: InClusterFactory{}.GetNamespacedName().

Types

type Condition

type Condition interface {
	// Get fetches the condition on the operator's
	// OperatorCondition. It returns an error if there are problems getting
	// the OperatorCondition object or if the specific condition type does not
	// exist.
	Get(ctx context.Context) (*metav1.Condition, error)

	// Set sets the specific condition on the operator's
	// OperatorCondition to the provided status. If the condition is not
	// present, it is added to the CR.
	// To set a new condition, the user can call this method and provide optional
	// parameters if required. It returns an error if there are problems getting or
	// updating the OperatorCondition object.
	Set(ctx context.Context, status metav1.ConditionStatus, option ...Option) error
}

Condition can Get and Set a conditionType in an Operator Condition custom resource associated with the operator.

func NewCondition deprecated

func NewCondition(cl client.Client, condType apiv2.ConditionType) (Condition, error)

NewCondition returns a new Condition interface using the provided client for the specified conditionType. The condition will internally fetch the namespacedName of the operatorConditionCRD.

Deprecated: Use InClusterFactory{cl}.NewCondition() instead.

type Factory added in v0.8.0

type Factory interface {
	NewCondition(apiv2.ConditionType) (Condition, error)
	GetNamespacedName() (*types.NamespacedName, error)
}

Factory define the interface for building Conditions.

type InClusterFactory added in v0.8.0

type InClusterFactory struct {
	Client client.Client
}

InClusterFactory is a conditions factory that can build conditions and get the namespaced name of the operator's condition based on an in-cluster configuration.

func (InClusterFactory) GetNamespacedName added in v0.8.0

func (f InClusterFactory) GetNamespacedName() (*types.NamespacedName, error)

GetNamespacedName returns the NamespacedName of the CR. It returns an error when the name of the CR cannot be found from the environment variable set by OLM. Hence, GetNamespacedName() can provide the NamespacedName when the operator is running on cluster and is being managed by OLM.

func (InClusterFactory) NewCondition added in v0.8.0

func (f InClusterFactory) NewCondition(condType apiv2.ConditionType) (Condition, error)

NewCondition creates a new Condition using the provided client and condition type. The condition's name and namespace are determined by the Factory's GetName and GetNamespace functions.

type Option

type Option func(*metav1.Condition)

Option is a function that applies a change to a condition. This can be used to set optional condition fields, like reasons and messages.

func WithMessage

func WithMessage(message string) Option

WithMessage is an Option, which adds the reason to the condition.

func WithReason

func WithReason(reason string) Option

WithReason is an Option, which adds the reason to the condition.

Jump to

Keyboard shortcuts

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