conditions

package
v1.9.0-p01 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReadyConditionType indicates a resource is ready.
	ReadyConditionType = "Ready"
)

Variables

View Source
var (
	ErrUnstructuredFieldNotFound = fmt.Errorf("field not found")
)

Functions

func Delete

func Delete(to Setter, t string)

Delete deletes the condition with the given type.

func FalseCondition

func FalseCondition(t string, reason string, messageFormat string, messageArgs ...interface{}) *metav1.Condition

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

func Get

func Get(from Getter, t string) *metav1.Condition

Get returns the condition with the given type, otherwise nil is returned.

func GetLastTransitionTime

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

GetLastTransitionTime returns the condition's last transition time or a nil value if the condition does not exist.

func GetMessage

func GetMessage(from Getter, t string) string

GetMessage returns the condition's message or an empty string if the condition does not exist.

func GetReason

func GetReason(from Getter, t string) string

GetReason returns the condition's reason or an empty string if the condition does not exist.

func Has

func Has(from Getter, t string) bool

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

func IsFalse

func IsFalse(from Getter, t string) bool

IsFalse returns true if the condition with the given type exists and is False, otherwise false is returned.

func IsTrue

func IsTrue(from Getter, t string) bool

IsTrue returns true if the condition with the given type exists and is True, otherwise false is returned.

func IsUnknown

func IsUnknown(from Getter, t string) bool

IsUnknown returns true if the condition with the given type exists and is Unknown, otherwise false is returned.

func MarkError added in v1.10.0

func MarkError(to Setter, t string, reason string, err error)

MarkError sets Status=False and the error message for the condition with the given type.

func MarkFalse

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

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

func MarkTrue

func MarkTrue(to Setter, t string)

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

func MarkUnknown

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

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

func MatchCondition

func MatchCondition(expected metav1.Condition) types.GomegaMatcher

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

func MatchConditions

func MatchConditions(expected []metav1.Condition) types.GomegaMatcher

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

func Set

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

Set sets the given condition. If a condition with the same type already exists, its LastTransitionTime is only updated if a change is detected in one of the following fields: Status, Reason, or Message.

func SetAggregate

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

SetAggregate creates a new condition by aggregating all of the Ready conditions from a list of source objects. If a source object is missing the Ready condition, that object is excluded from aggregation. If none of the source objects have a Ready condition, the target is not modified.

func SetMirror

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

SetMirror creates a new condition by mirroring the Ready condition from a source object. If the source object does not have a Ready condition, the target is not modified.

func SetSummary

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

SetSummary sets a Ready condition with a summary of all the existing conditions. If there are no existing conditions, no summary condition is generated.

func TrueCondition

func TrueCondition(t string) *metav1.Condition

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

func UnknownCondition

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

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

func UnstructuredUnmarshalField

func UnstructuredUnmarshalField(obj *unstructured.Unstructured, v interface{}, fields ...string) error

UnstructuredUnmarshalField is a wrapper around json and unstructured objects to decode and copy a specific field value into an object.

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 ...string) 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 Conditions added in v1.9.0

type Conditions []metav1.Condition

Conditions is an alias for a slice of metav1.Condition objects and provides helpful functions.

func (Conditions) Delete added in v1.9.0

func (l Conditions) Delete(t string) Conditions

Delete removes the condition with the given type.

func (Conditions) Get added in v1.9.0

func (l Conditions) Get(t string) *metav1.Condition

Get returns the condition with the given type, otherwise nil is returned.

func (Conditions) GetConditions added in v1.9.0

func (l Conditions) GetConditions() []metav1.Condition

GetConditions allows the Conditions type to implement the Getter interface.

func (Conditions) GetLastTransitionTime added in v1.9.0

func (l Conditions) GetLastTransitionTime(t string) *metav1.Time

GetLastTransitionTime returns the condition's last transition time or a nil value if the condition does not exist.

func (Conditions) GetMessage added in v1.9.0

func (l Conditions) GetMessage(t string) string

GetMessage returns the condition's message or an empty string if the condition does not exist.

func (Conditions) GetReason added in v1.9.0

func (l Conditions) GetReason(t string) string

GetReason returns the condition's reason or an empty string if the condition does not exist.

func (Conditions) Has added in v1.9.0

func (l Conditions) Has(t string) bool

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

func (Conditions) IsFalse added in v1.9.0

func (l Conditions) IsFalse(t string) bool

IsFalse returns true if the condition with the given type exists and is False, otherwise false is returned.

func (Conditions) IsTrue added in v1.9.0

func (l Conditions) IsTrue(t string) bool

IsTrue returns true if the condition with the given type exists and is True, otherwise false is returned.

func (Conditions) IsUnknown added in v1.9.0

func (l Conditions) IsUnknown(t string) bool

IsUnknown returns true if the condition with the given type exists and is Unknown, otherwise false is returned.

func (Conditions) MarkError added in v1.10.0

func (l Conditions) MarkError(
	t, reason string, err error) Conditions

MarkError sets Status=False and the error message for the condition with the given type.

func (Conditions) MarkFalse added in v1.9.0

func (l Conditions) MarkFalse(
	t, reason, messageFormat string, messageArgs ...any) Conditions

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

func (Conditions) MarkTrue added in v1.9.0

func (l Conditions) MarkTrue(t string) Conditions

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

func (Conditions) MarkUnknown added in v1.9.0

func (l Conditions) MarkUnknown(
	t, reason, messageFormat string, messageArgs ...any) Conditions

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

func (Conditions) Set added in v1.9.0

Set sets the given condition. If a condition with the same type already exists, its LastTransitionTime is only updated if a change is detected in one of the following fields: Status, Reason, or Message.

func (Conditions) SetAggregate added in v1.9.0

func (l Conditions) SetAggregate(
	targetCondition string,
	from []Getter,
	options ...MergeOption) Conditions

SetAggregate creates a new condition by aggregating all of the Ready conditions from a list of source objects. If a source object is missing the Ready condition, that object is excluded from aggregation. If none of the source objects have a Ready condition, the target is not modified.

func (Conditions) SetMirror added in v1.9.0

func (l Conditions) SetMirror(
	targetCondition string,
	from Getter,
	options ...MirrorOptions) Conditions

SetMirror creates a new condition by mirroring the Ready condition from a source object. If the source object does not have a Ready condition, the target is not modified.

func (Conditions) SetSummary added in v1.9.0

func (l Conditions) SetSummary(options ...MergeOption) Conditions

SetSummary sets a Ready condition with a summary of all the existing conditions. If there are no existing conditions, no summary condition is generated.

type Getter

type Getter interface {
	// GetConditions returns the list of conditions for a cluster API object.
	GetConditions() []metav1.Condition
}

Getter interface defines methods that an 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 ...string) 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 ...string) 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, 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

NewPatch returns the list of 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 has no changes.

type PatchOperation

type PatchOperation struct {
	Before *metav1.Condition
	After  *metav1.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([]metav1.Condition)
}

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