conditions

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 19 Imported by: 265

Documentation

Overview

Package conditions implements condition utilities.

Index

Constants

View Source
const (
	// PositivePolarity describe a condition with positive polarity (Status=True good).
	PositivePolarity conditionPolarity = "Positive"

	// NegativePolarity describe a condition with negative polarity (Status=False good).
	NegativePolarity conditionPolarity = "Negative"
)

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 FalseConditionWithNegativePolarity added in v1.8.0

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

FalseConditionWithNegativePolarity returns a condition with negative polarity, Status=false and the given type (Status=False has a positive meaning).

func Get

Get returns the condition with the given type, if the condition does not exist, 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 HasSameState added in v1.9.0

func HasSameState(i, j *clusterv1.Condition) bool

HasSameState returns true if a condition has the same state of another; state is defined by the union of following fields: Type, Status, Reason, Severity and Message (it excludes LastTransitionTime).

func HaveSameStateOf added in v0.4.0

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 returns 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 returns 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 MarkFalseWithNegativePolarity added in v1.8.0

func MarkFalseWithNegativePolarity(to Setter, t clusterv1.ConditionType)

MarkFalseWithNegativePolarity sets Status=False for a condition with negative polarity and the given type (Status=False has a positive meaning).

func MarkTrue

func MarkTrue(to Setter, t clusterv1.ConditionType)

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

func MarkTrueWithNegativePolarity added in v1.8.0

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

MarkTrueWithNegativePolarity sets Status=True for a condition with negative polarity and the given type (Status=True has a negative meaning).

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 added in v0.3.11

func MatchCondition(expected clusterv1.Condition) types.GomegaMatcher

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

func MatchConditions added in v0.3.11

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 exist 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 exist 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 SetWithCustomLastTransitionTime added in v1.9.0

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

SetWithCustomLastTransitionTime is similar to Set function which sets the given condition but following changes for LastTransitionTime.

  1. if the condition of the specified type already exists (all fields of the existing condition are updated to new condition, LastTransitionTime is set to current time if unset and new status differs from the old status)
  2. if a condition of the specified type does not exist (LastTransitionTime is set to current time if unset, and newCondition is appended)

func TrueCondition

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

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

func TrueConditionWithNegativePolarity added in v1.8.0

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

TrueConditionWithNegativePolarity returns a condition with negative polarity, Status=True and the given type (Status=True has a negative meaning).

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 added in v0.3.10

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 WithNegativePolarityConditions added in v1.8.0

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

WithNegativePolarityConditions instruct merge about which conditions should be considered having negative polarity. IMPORTANT: this must be a subset of WithConditions.

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 added in v0.3.9

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 exist; 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.

Directories

Path Synopsis
Package v1beta2 implements utils for metav1.Conditions that will be used starting with the v1beta2 API.
Package v1beta2 implements utils for metav1.Conditions that will be used starting with the v1beta2 API.

Jump to

Keyboard shortcuts

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