Documentation
¶
Overview ¶
Package conditions provides utilities for manipulating the status conditions of Kubernetes resource objects that implement the Getter and/or Setter interfaces.
Usage of this package within GitOps Toolkit components working with conditions is RECOMMENDED, as it provides a wide range of helpers to work around common reconciler problems, like setting a Condition status based on a summarization of other conditions, producing an aggregate Condition based on the conditions of a list of Kubernetes resources objects, recognition of negative polarity or "abnormal-true" conditions, etc.
Index ¶
- Variables
- func Delete(to Setter, t string)
- func FalseCondition(t, reason, messageFormat string, messageArgs ...interface{}) *metav1.Condition
- func Get(from Getter, t string) *metav1.Condition
- func GetLastTransitionTime(from Getter, t string) *metav1.Time
- func GetMessage(from Getter, t string) string
- func GetObservedGeneration(from Getter, t string) int64
- func GetReason(from Getter, t string) string
- func Has(from Getter, t string) bool
- func HasAny(from Getter, t []string) bool
- func HasAnyReason(from Getter, t string, r ...string) bool
- func HaveSameStateOf(expected *metav1.Condition) types.GomegaMatcher
- func IsFalse(from Getter, t string) bool
- func IsReady(from Getter) bool
- func IsReconciling(from Getter) bool
- func IsStalled(from Getter) bool
- func IsTrue(from Getter, t string) bool
- func IsUnknown(from Getter, t string) bool
- func MarkFalse(to Setter, t, reason, messageFormat string, messageArgs ...interface{})
- func MarkReconciling(to Setter, reason, messageFormat string, messageArgs ...interface{})
- func MarkStalled(to Setter, reason, messageFormat string, messageArgs ...interface{})
- func MarkTrue(to Setter, t, reason, messageFormat string, messageArgs ...interface{})
- func MarkUnknown(to Setter, t, reason, messageFormat string, messageArgs ...interface{})
- func MatchCondition(expected metav1.Condition) types.GomegaMatcher
- func MatchConditions(expected []metav1.Condition) types.GomegaMatcher
- func Set(to Setter, condition *metav1.Condition)
- func SetAggregate(to Setter, targetCondition string, from []Getter, options ...MergeOption)
- func SetMirror(to Setter, targetCondition string, from Getter, options ...MirrorOptions)
- func SetSummary(to Setter, targetCondition string, options ...MergeOption)
- func TrueCondition(t, reason, messageFormat string, messageArgs ...interface{}) *metav1.Condition
- func UnknownCondition(t, reason, messageFormat string, messageArgs ...interface{}) *metav1.Condition
- func UnstructuredUnmarshalField(u *unstructured.Unstructured, v interface{}, fields ...string) error
- type ApplyOption
- type ConditionMatcher
- type Getter
- type MergeOption
- func WithConditions(t ...string) MergeOption
- func WithCounter() MergeOption
- func WithCounterIfOnly(t ...string) MergeOption
- func WithLatestGeneration() MergeOption
- func WithNegativePolarityConditions(t ...string) MergeOption
- func WithSourceRef() MergeOption
- func WithSourceRefIf(t ...string) MergeOption
- func WithStepCounter() MergeOption
- func WithStepCounterIf(value bool) MergeOption
- func WithStepCounterIfOnly(t ...string) MergeOption
- type MirrorOptions
- type Patch
- type PatchOperation
- type PatchOperationType
- type Setter
Constants ¶
This section is empty.
Variables ¶
var (
ErrUnstructuredFieldNotFound = fmt.Errorf("field not found")
)
Functions ¶
func FalseCondition ¶
FalseCondition returns a condition with Status=False and the given type, reason and message.
func Get ¶
Get returns the condition with the given type, if the condition does not exists, it returns nil.
func GetLastTransitionTime ¶
GetLastTransitionTime returns the LastTransitionType or nil if the condition does not exist (is nil).
func GetMessage ¶
GetMessage returns a nil safe string of Message for the condition with the given type.
func GetObservedGeneration ¶
GetObservedGeneration returns a nil safe int64 of ObservedGeneration for the condition with the given type.
func GetReason ¶
GetReason returns a nil safe string of Reason for the condition with the given type.
func HasAny ¶ added in v0.28.0
HasAny returns true if a condition with any of the given types exist.
func HasAnyReason ¶ added in v0.44.1
HasAnyReason returns true if a condition with the given type exists and any of the given reasons exist.
func HaveSameStateOf ¶
func HaveSameStateOf(expected *metav1.Condition) types.GomegaMatcher
HaveSameStateOf returns a custom matcher to check equality of a metav1.Condition, the condition message is checked for a subset string match.
func IsFalse ¶
IsFalse is true if the condition with the given type is False, otherwise it is false if the condition is not False or if the condition does not exist (is nil).
func IsReady ¶
IsReady is true if IsStalled and IsReconciling are False, and meta.ReadyCondition is True, otherwise it is false if the condition is not True or if it does not exist (is nil).
func IsReconciling ¶
IsReconciling is true if meta.ReconcilingCondition is True and meta.StalledCondition is False or does not exist, otherwise it is false.
func IsStalled ¶
IsStalled is true if meta.StalledCondition is True and meta.ReconcilingCondition is False or does not exist, otherwise it is false.
func IsTrue ¶
IsTrue is true if the condition with the given type is True, otherwise it is false if the condition is not True or if the condition does not exist (is nil).
func IsUnknown ¶
IsUnknown is true if the condition with the given type is Unknown or if the condition does not exist (is nil).
func MarkFalse ¶
MarkFalse sets Status=False for the condition with the given type, reason and message.
func MarkReconciling ¶
MarkReconciling sets meta.ReconcilingCondition=True with the given reason and message, and deletes the meta.StalledCondition. This is normally called at the beginning of a reconcile run for an object. For more information about the condition types, see the kstatus spec: https://github.com/kubernetes-sigs/cli-utils/blob/e351b2bc43cec2107ba1d874c3dec54fd0956c59/pkg/kstatus/README.md#conditions
func MarkStalled ¶
MarkStalled sets meta.StalledCondition=True with the given reason and message, and deletes the meta.ReconcilingCondition. This is normally deferred and conditionally called at the end of a reconcile run for an object. A common approach is to mark the object stalled if the object is not requeued as a reconcile result. For more information about the condition types, see the kstatus spec: https://github.com/kubernetes-sigs/cli-utils/blob/e351b2bc43cec2107ba1d874c3dec54fd0956c59/pkg/kstatus/README.md#conditions
func MarkTrue ¶
MarkTrue sets Status=True for the condition with the given type, reason and message.
func MarkUnknown ¶
MarkUnknown sets Status=Unknown for the condition with the given type, reason and message.
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 a metav1.Condition slice, the condition messages are checked for a subset string match.
func Set ¶
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, and Message. The ObservedGeneration is always updated.
func SetAggregate ¶
func SetAggregate(to Setter, targetCondition string, from []Getter, options ...MergeOption)
SetAggregate creates a new condition with the aggregation of all the conditions from a list of dependency objects, or a subset using WithConditions; if none of the source objects have a condition within the scope of the merge operation, no target condition is generated.
func SetMirror ¶
func SetMirror(to Setter, targetCondition string, from Getter, options ...MirrorOptions)
SetMirror creates a new condition by mirroring the 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, targetCondition string, options ...MergeOption)
SetSummary creates a new summary 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 ¶
TrueCondition returns a condition with Status=True and the given type, reason and message.
func UnknownCondition ¶
func UnknownCondition(t, reason, messageFormat string, messageArgs ...interface{}) *metav1.Condition
UnknownCondition returns a condition with Status=Unknown and the given type, reason and message.
func UnstructuredUnmarshalField ¶
func UnstructuredUnmarshalField(u *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 instructs the patch helper to always use the value provided by the controller in case of conflicts for the owned conditions.
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 ConditionMatcher ¶
func (*ConditionMatcher) FailureMessage ¶
func (matcher *ConditionMatcher) FailureMessage(actual interface{}) (message string)
func (*ConditionMatcher) Match ¶
func (matcher *ConditionMatcher) Match(actual interface{}) (success bool, err error)
func (*ConditionMatcher) NegatedFailureMessage ¶
func (matcher *ConditionMatcher) NegatedFailureMessage(actual interface{}) (message string)
type Getter ¶
type Getter interface { client.Object meta.ObjectWithConditions }
Getter interface defines methods that a Kubernetes resource 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 status conditions with a metav1.Condition type.
type MergeOption ¶
type MergeOption func(*mergeOptions)
MergeOption defines an option for computing a summary of conditions.
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 (except Ready, Stalled, and Reconciling) 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 a Summary or Aggregated condition.
func WithCounter ¶
func WithCounter() MergeOption
WithCounter instructs merge to add a "x of y Type" string to the message, where x is the number of conditions in the top group, y is the number of objects in scope, and Type is the top group condition type.
func WithCounterIfOnly ¶
func WithCounterIfOnly(t ...string) MergeOption
WithCounterIfOnly ensures a counter is show only if a subset of condition exists. This may apply when you want to use a step counter while reconciling the resource, but then want to move away from this notation as soon as the resource has been reconciled, and e.g. a health check condition is generated.
IMPORTANT: This options requires WithStepCounter or WithStepCounterIf to be set. IMPORTANT: This option works only while generating the Aggregated condition.
func WithLatestGeneration ¶
func WithLatestGeneration() MergeOption
WithLatestGeneration instructs merge to consider the conditions with the latest observed generation only.
func WithNegativePolarityConditions ¶
func WithNegativePolarityConditions(t ...string) MergeOption
WithNegativePolarityConditions instructs merge about the condition types that adhere to a "normal-false" or "abnormal-true" pattern, i.e. that conditions are present with a value of True whenever something unusual happens.
NOTE: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties IMPORTANT: This option works only while generating the Summary or Aggregated condition.
func WithSourceRef ¶
func WithSourceRef() MergeOption
WithSourceRef instructs merge to add info about the originating object to the target Reason and in summaries.
func WithSourceRefIf ¶
func WithSourceRefIf(t ...string) MergeOption
WithSourceRefIf ensures a source ref is show only if one of the types in the set exists.
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.
IMPORTANT: This option works only while generating the Summary or Aggregated condition.
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 option works only while generating the Summary or Aggregated condition.
func WithStepCounterIfOnly ¶
func WithStepCounterIfOnly(t ...string) MergeOption
WithStepCounterIfOnly ensures a step counter is show only if a subset of condition exists. This may apply when you want to use a step counter while reconciling the resource, but then want to move away from this notation as soon as the resource has been reconciled, and e.g. a health check condition is generated.
IMPORTANT: This options requires WithStepCounter or WithStepCounterIf to be set. IMPORTANT: This option works only while generating the Summary or Aggregated 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 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 ¶
NewPatch returns the list of Patch required to align source conditions to after conditions.
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 meta.ObjectWithConditionsSetter }
Setter is an interface that defines methods a Kubernetes 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 status conditions with a metav1.Condition type.