conditions

package
v1.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package conditions implements condition utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(to Setter, t clusterv1.ConditionType)

Delete deletes the condition with the given type.

func FalseCondition

func FalseCondition(t clusterv1.ConditionType, reason string, severity clusterv1.ConditionSeverity, messageFormat string, messageArgs ...interface{}) *clusterv1.Condition

FalseCondition returns a condition with Status=False and the given type.

func Get

Get returns the condition with the given type, if the condition does not exists, it returns nil.

func GetLastTransitionTime

func GetLastTransitionTime(from Getter, t clusterv1.ConditionType) *metav1.Time

GetLastTransitionTime returns the condition Severity or nil if the condition does not exist (is nil).

func GetMessage

func GetMessage(from Getter, t clusterv1.ConditionType) string

GetMessage returns a nil safe string of Message.

func GetReason

func GetReason(from Getter, t clusterv1.ConditionType) string

GetReason returns a nil safe string of Reason for the condition with the given type.

func GetSeverity

GetSeverity returns the condition Severity or nil if the condition does not exist (is nil).

func Has

func Has(from Getter, t clusterv1.ConditionType) bool

Has returns true if a condition with the given type exists.

func HaveSameStateOf

func HaveSameStateOf(expected *clusterv1.Condition) types.GomegaMatcher

HaveSameStateOf matches a condition to have the same state of another.

func IsFalse

func IsFalse(from Getter, t clusterv1.ConditionType) bool

IsFalse is true if the condition with the given type is False, otherwise it return false if the condition is not False or if the condition does not exist (is nil).

func IsTrue

func IsTrue(from Getter, t clusterv1.ConditionType) bool

IsTrue is true if the condition with the given type is True, otherwise it return false if the condition is not True or if the condition does not exist (is nil).

func IsUnknown

func IsUnknown(from Getter, t clusterv1.ConditionType) bool

IsUnknown is true if the condition with the given type is Unknown or if the condition does not exist (is nil).

func MarkFalse

func MarkFalse(to Setter, t clusterv1.ConditionType, reason string, severity clusterv1.ConditionSeverity, messageFormat string, messageArgs ...interface{})

MarkFalse sets Status=False for the condition with the given type.

func MarkTrue

func MarkTrue(to Setter, t clusterv1.ConditionType)

MarkTrue sets Status=True for the condition with the given type.

func MarkUnknown

func MarkUnknown(to Setter, t clusterv1.ConditionType, reason, messageFormat string, messageArgs ...interface{})

MarkUnknown sets Status=Unknown for the condition with the given type.

func MatchCondition

func MatchCondition(expected clusterv1.Condition) types.GomegaMatcher

MatchCondition returns a custom matcher to check equality of clusterv1.Condition.

func MatchConditions

func MatchConditions(expected clusterv1.Conditions) types.GomegaMatcher

MatchConditions returns a custom matcher to check equality of clusterv1.Conditions.

func Set

func Set(to Setter, condition *clusterv1.Condition)

Set sets the given condition.

NOTE: If a condition already exists, the LastTransitionTime is updated only if a change is detected in any of the following fields: Status, Reason, Severity and Message.

func SetAggregate

func SetAggregate(to Setter, targetCondition clusterv1.ConditionType, from []Getter, options ...MergeOption)

SetAggregate creates a new condition with the aggregation of all the Ready condition from a list of dependent objects; if the Ready condition does not exists in one of the source object, the object is excluded from the aggregation; if none of the source object have ready condition, no target conditions is generated.

func SetMirror

func SetMirror(to Setter, targetCondition clusterv1.ConditionType, from Getter, options ...MirrorOptions)

SetMirror creates a new condition by mirroring the Ready condition from a dependent object; if the Ready condition does not exists in the source object, no target conditions is generated.

func SetSummary

func SetSummary(to Setter, options ...MergeOption)

SetSummary sets a Ready condition with the summary of all the conditions existing on an object. If the object does not have other conditions, no summary condition is generated.

func TrueCondition

func TrueCondition(t clusterv1.ConditionType) *clusterv1.Condition

TrueCondition returns a condition with Status=True and the given type.

func UnknownCondition

func UnknownCondition(t clusterv1.ConditionType, reason string, messageFormat string, messageArgs ...interface{}) *clusterv1.Condition

UnknownCondition returns a condition with Status=Unknown and the given type.

Types

type ApplyOption

type ApplyOption func(*applyOptions)

ApplyOption defines an option for applying a condition patch.

func WithForceOverwrite

func WithForceOverwrite(v bool) ApplyOption

WithForceOverwrite In case of conflicts for the owned conditions, the patch helper will always use the value provided by the controller.

func WithOwnedConditions

func WithOwnedConditions(t ...clusterv1.ConditionType) ApplyOption

WithOwnedConditions allows to define condition types owned by the controller. In case of conflicts for the owned conditions, the patch helper will always use the value provided by the controller.

type Getter

type Getter interface {
	client.Object

	// GetConditions returns the list of conditions for a cluster API object.
	GetConditions() clusterv1.Conditions
}

Getter interface defines methods that a Cluster API object should implement in order to use the conditions package for getting conditions.

func UnstructuredGetter

func UnstructuredGetter(u *unstructured.Unstructured) Getter

UnstructuredGetter return a Getter object that can read conditions from an Unstructured object. Important. This method should be used only with types implementing Cluster API conditions.

type MergeOption

type MergeOption func(*mergeOptions)

MergeOption defines an option for computing a summary of conditions.

func AddSourceRef

func AddSourceRef() MergeOption

AddSourceRef instructs merge to add info about the originating object to the target Reason.

func WithConditions

func WithConditions(t ...clusterv1.ConditionType) MergeOption

WithConditions instructs merge about the condition types to consider when doing a merge operation; if this option is not specified, all the conditions (excepts Ready) will be considered. This is required so we can provide some guarantees about the semantic of the target condition without worrying about side effects if someone or something adds custom conditions to the objects.

NOTE: The order of conditions types defines the priority for determining the Reason and Message for the target condition. IMPORTANT: This options works only while generating the Summary condition.

func WithStepCounter

func WithStepCounter() MergeOption

WithStepCounter instructs merge to add a "x of y completed" string to the message, where x is the number of conditions with Status=true and y is the number of conditions in scope.

func WithStepCounterIf

func WithStepCounterIf(value bool) MergeOption

WithStepCounterIf adds a step counter if the value is true. This can be used e.g. to add a step counter only if the object is not being deleted.

IMPORTANT: This options works only while generating the Summary condition.

func WithStepCounterIfOnly

func WithStepCounterIfOnly(t ...clusterv1.ConditionType) MergeOption

WithStepCounterIfOnly ensure a step counter is show only if a subset of condition exists. This applies for example on Machines, where we want to use the step counter notation while provisioning the machine, but then we want to move away from this notation as soon as the machine is provisioned and e.g. a Machine health check condition is generated

IMPORTANT: This options requires WithStepCounter or WithStepCounterIf to be set. IMPORTANT: This options works only while generating the Summary condition.

type MirrorOptions

type MirrorOptions func(*mirrorOptions)

MirrorOptions defines an option for mirroring conditions.

func WithFallbackValue

func WithFallbackValue(fallbackValue bool, reason string, severity clusterv1.ConditionSeverity, message string) MirrorOptions

WithFallbackValue specify a fallback value to use in case the mirrored condition does not exists; in case the fallbackValue is false, given values for reason, severity and message will be used.

type Patch

type Patch []PatchOperation

Patch defines a list of operations to change a list of conditions into another.

func NewPatch

func NewPatch(before Getter, after Getter) (Patch, error)

NewPatch returns the Patch required to align source conditions to after conditions.

func (Patch) Apply

func (p Patch) Apply(latest Setter, options ...ApplyOption) error

Apply executes a three-way merge of a list of Patch. When merge conflicts are detected (latest deviated from before in an incompatible way), an error is returned.

func (Patch) IsZero

func (p Patch) IsZero() bool

IsZero returns true if the patch is nil or has no changes.

type PatchOperation

type PatchOperation struct {
	Before *clusterv1.Condition
	After  *clusterv1.Condition
	Op     PatchOperationType
}

PatchOperation define an operation that changes a single condition.

type PatchOperationType

type PatchOperationType string

PatchOperationType defines patch operation types.

const (
	// AddConditionPatch defines an add condition patch operation.
	AddConditionPatch PatchOperationType = "Add"

	// ChangeConditionPatch defines an change condition patch operation.
	ChangeConditionPatch PatchOperationType = "Change"

	// RemoveConditionPatch defines a remove condition patch operation.
	RemoveConditionPatch PatchOperationType = "Remove"
)

type Setter

type Setter interface {
	Getter
	SetConditions(clusterv1.Conditions)
}

Setter interface defines methods that a Cluster API object should implement in order to use the conditions package for setting conditions.

func UnstructuredSetter

func UnstructuredSetter(u *unstructured.Unstructured) Setter

UnstructuredSetter return a Setter object that can set conditions from an Unstructured object. Important. This method should be used only with types implementing Cluster API conditions.

Jump to

Keyboard shortcuts

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