Documentation ¶
Overview ¶
Package condition simplifies condition handling with any structurally compatible condition (comparable to a sort of duck-typing) via go reflection.
Index ¶
- Constants
- Variables
- type Accessor
- func (a *Accessor) FindSlice(condSlice interface{}, typ string, intoPtr interface{}) (ok bool, err error)
- func (a *Accessor) FindSliceStatus(condSlice interface{}, typ string) (corev1.ConditionStatus, error)
- func (a *Accessor) HasLastTransitionTime(cond interface{}) (bool, error)
- func (a *Accessor) HasLastUpdateTime(cond interface{}) (bool, error)
- func (a *Accessor) HasObservedGeneration(cond interface{}) (bool, error)
- func (a *Accessor) LastTransitionTime(cond interface{}) (metav1.Time, error)
- func (a *Accessor) LastUpdateTime(cond interface{}) (metav1.Time, error)
- func (a *Accessor) Message(cond interface{}) (string, error)
- func (a *Accessor) MustFindSlice(condSlice interface{}, typ string, intoPtr interface{}) bool
- func (a *Accessor) MustFindSliceStatus(condSlice interface{}, typ string) corev1.ConditionStatus
- func (a *Accessor) MustHasLastTransitionTime(cond interface{}) bool
- func (a *Accessor) MustHasLastUpdateTime(cond interface{}) bool
- func (a *Accessor) MustHasObservedGeneration(cond interface{}) bool
- func (a *Accessor) MustLastTransitionTime(cond interface{}) metav1.Time
- func (a *Accessor) MustLastUpdateTime(cond interface{}) metav1.Time
- func (a *Accessor) MustMessage(cond interface{}) string
- func (a *Accessor) MustObservedGeneration(cond interface{}) int64
- func (a *Accessor) MustReason(cond interface{}) string
- func (a *Accessor) MustSetLastTransitionTime(condPtr interface{}, lastTransitionTime metav1.Time)
- func (a *Accessor) MustSetLastTransitionTimeIfExists(condPtr interface{}, lastTransitionTime metav1.Time)
- func (a *Accessor) MustSetLastUpdateTime(condPtr interface{}, lastUpdateTime metav1.Time)
- func (a *Accessor) MustSetLastUpdateTimeIfExists(condPtr interface{}, lastUpdateTime metav1.Time)
- func (a *Accessor) MustSetMessage(condPtr interface{}, message string)
- func (a *Accessor) MustSetObservedGeneration(condPtr interface{}, gen int64)
- func (a *Accessor) MustSetReason(condPtr interface{}, reason string)
- func (a *Accessor) MustSetStatus(condPtr interface{}, status corev1.ConditionStatus)
- func (a *Accessor) MustSetType(condPtr interface{}, typ string)
- func (a *Accessor) MustStatus(cond interface{}) corev1.ConditionStatus
- func (a *Accessor) MustType(cond interface{}) string
- func (a *Accessor) MustUpdate(condPtr interface{}, opts ...UpdateOption)
- func (a *Accessor) MustUpdateSlice(condSlicePtr interface{}, typ string, opts ...UpdateOption)
- func (a *Accessor) ObservedGeneration(cond interface{}) (int64, error)
- func (a *Accessor) Reason(cond interface{}) (string, error)
- func (a *Accessor) SetLastTransitionTime(condPtr interface{}, lastTransitionTime metav1.Time) error
- func (a *Accessor) SetLastTransitionTimeIfExists(condPtr interface{}, lastTransitionTime metav1.Time) error
- func (a *Accessor) SetLastUpdateTime(condPtr interface{}, lastUpdateTime metav1.Time) error
- func (a *Accessor) SetLastUpdateTimeIfExists(condPtr interface{}, lastUpdateTime metav1.Time) error
- func (a *Accessor) SetMessage(condPtr interface{}, message string) error
- func (a *Accessor) SetObservedGeneration(condPtr interface{}, gen int64) error
- func (a *Accessor) SetReason(condPtr interface{}, reason string) error
- func (a *Accessor) SetStatus(condPtr interface{}, status corev1.ConditionStatus) error
- func (a *Accessor) SetType(condPtr interface{}, typ string) error
- func (a *Accessor) Status(cond interface{}) (corev1.ConditionStatus, error)
- func (a *Accessor) Type(cond interface{}) (string, error)
- func (a *Accessor) Update(condPtr interface{}, opts ...UpdateOption) error
- func (a *Accessor) UpdateSlice(condSlicePtr interface{}, typ string, opts ...UpdateOption) error
- type AccessorOptions
- type UpdateMessage
- type UpdateObservedGeneration
- type UpdateOption
- type UpdateReason
- type UpdateStatus
Constants ¶
const ( // DefaultTypeField is the default name for a condition's type field. DefaultTypeField = "Type" // DefaultStatusField is the default name for a condition's status field. DefaultStatusField = "Status" // DefaultLastUpdateTimeField field is the default name for a condition's last update time field. DefaultLastUpdateTimeField = "LastUpdateTime" // DefaultLastTransitionTimeField field is the default name for a condition's last transition time field. DefaultLastTransitionTimeField = "LastTransitionTime" // DefaultReasonField field is the default name for a condition's reason field. DefaultReasonField = "Reason" // DefaultMessageField field is the default name for a condition's message field. DefaultMessageField = "Message" // DefaultObservedGenerationField field is the default name for a condition's observed generation field. DefaultObservedGenerationField = "ObservedGeneration" )
Variables ¶
var ( // DefaultAccessor is an Accessor initialized with the default fields. // See NewAccessor for more. DefaultAccessor = NewAccessor(AccessorOptions{}) // Update updates the condition with the given options. // See Accessor.Update for more. Update = DefaultAccessor.Update // MustUpdate updates the condition with the given options. // See Accessor.MustUpdate for more. MustUpdate = DefaultAccessor.MustUpdate // UpdateSlice updates the slice with the given options. // See Accessor.UpdateSlice for more. UpdateSlice = DefaultAccessor.UpdateSlice // MustUpdateSlice updates the slice with the given options. // See Accessor.MustUpdateSlice for more. MustUpdateSlice = DefaultAccessor.MustUpdateSlice // FindSlice finds the target condition in the given slice. // See Accessor.FindSlice for more. FindSlice = DefaultAccessor.FindSlice // MustFindSlice finds the target condition in the given slice. // See Accessor.MustFindSlice for more. MustFindSlice = DefaultAccessor.MustFindSlice // FindSliceStatus finds the condition status in the given slice. // See Accessor.FindSliceStatus for more. FindSliceStatus = DefaultAccessor.FindSliceStatus // MustFindSliceStatus finds the condition status in the given slice. // See Accessor.MustFindSliceStatus for more. MustFindSliceStatus = DefaultAccessor.MustFindSliceStatus )
Functions ¶
This section is empty.
Types ¶
type Accessor ¶
type Accessor struct {
// contains filtered or unexported fields
}
func NewAccessor ¶
func NewAccessor(opts AccessorOptions) *Accessor
NewAccessor creates a new Accessor with the given AccessorOptions.
func (*Accessor) FindSlice ¶
func (a *Accessor) FindSlice(condSlice interface{}, typ string, intoPtr interface{}) (ok bool, err error)
FindSlice finds the condition with the given type from the given slice and updates the target value with it.
If the target type is not found, false is returned and the target value is not updated. FindSlice errors if condSlice is not a slice, intoPtr is not a pointer to a struct and if intoPtr's target value is not settable with an element of condSlice.
func (*Accessor) FindSliceStatus ¶
func (a *Accessor) FindSliceStatus(condSlice interface{}, typ string) (corev1.ConditionStatus, error)
FindSliceStatus finds the status of the condition with the given type. If the condition cannot be found, corev1.ConditionUnknown is returned.
FindSliceStatus errors if the given condSlice is not a slice of structs or if any of the conditions does not support access.
func (*Accessor) HasLastTransitionTime ¶
HasLastTransitionTime checks if the given condition has a 'LastTransitionTime' field.
It errors if the given value is not a struct.
func (*Accessor) HasLastUpdateTime ¶
HasLastUpdateTime checks if the given condition has a 'LastUpdateTime' field.
It errors if the given value is not a struct.
func (*Accessor) HasObservedGeneration ¶
HasObservedGeneration checks if the given condition has a observed generation field.
It errors if the given value is not a struct.
func (*Accessor) LastTransitionTime ¶
LastTransitionTime extracts the last transition time of the given condition.
It errors if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) LastUpdateTime ¶
LastUpdateTime extracts the last update time of the given condition.
It errors if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) Message ¶
Message gets the message of the given condition.
It errors if the given value is not a struct or does not have a field that can be converted to the input format.
func (*Accessor) MustFindSlice ¶
MustFindSlice finds the condition with the given type from the given slice and updates the target value with it.
If the target type is not found, false is returned and the target value is not updated. FindSlice panics if condSlice is not a slice, intoPtr is not a pointer to a struct and if intoPtr's target value is not settable with an element of condSlice.
func (*Accessor) MustFindSliceStatus ¶
func (a *Accessor) MustFindSliceStatus(condSlice interface{}, typ string) corev1.ConditionStatus
MustFindSliceStatus finds the status of the condition with the given type. If the condition cannot be found, corev1.ConditionUnknown is returned.
MustFindSliceStatus errors if the given condSlice is not a slice of structs or if any of the conditions does not support access.
func (*Accessor) MustHasLastTransitionTime ¶
MustHasLastTransitionTime checks if the given condition has a 'LastTransitionTime' field.
It panics if the given value is not a struct.
func (*Accessor) MustHasLastUpdateTime ¶
MustHasLastUpdateTime checks if the given condition has a 'LastUpdateTime' field.
It panics if the given value is not a struct.
func (*Accessor) MustHasObservedGeneration ¶
MustHasObservedGeneration checks if the given condition has a observed generation field.
It panics if the given value is not a struct.
func (*Accessor) MustLastTransitionTime ¶
MustLastTransitionTime extracts the last transition time of the given condition.
It panics if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) MustLastUpdateTime ¶
MustLastUpdateTime extracts the last update time of the given condition.
It panics if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) MustMessage ¶
MustMessage gets the message of the given condition.
It panics if the given value is not a struct or does not have a field that can be converted to the input format.
func (*Accessor) MustObservedGeneration ¶
MustObservedGeneration gets the observed generation of the given condition.
It panics if the given value is not a struct or does not have a field that can be converted to the input format.
func (*Accessor) MustReason ¶
MustReason extracts the reason of the given condition.
It panics if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) MustSetLastTransitionTime ¶
MustSetLastTransitionTime sets the last transition time of the given condition.
It panics if the given value is not a pointer to a struct or does not have a field that can be converted to the output format.
func (*Accessor) MustSetLastTransitionTimeIfExists ¶
func (a *Accessor) MustSetLastTransitionTimeIfExists(condPtr interface{}, lastTransitionTime metav1.Time)
MustSetLastTransitionTimeIfExists sets the last transition time of the given condition.
It panics if the given value is not a pointer to a struct or the field value cannot be converted to the given format.
func (*Accessor) MustSetLastUpdateTime ¶
MustSetLastUpdateTime sets the last update time of the given condition.
It errors if the given value is not a pointer to a struct or does not have a field that can be converted to the given format.
func (*Accessor) MustSetLastUpdateTimeIfExists ¶
MustSetLastUpdateTimeIfExists sets the last update time of the given condition if the field exists.
It panics if the given value is not a pointer to a struct or the field value cannot be converted to the given format.
func (*Accessor) MustSetMessage ¶
MustSetMessage sets the message of the given condition.
It panics if the given value is not a struct or does not have a field that can be converted to the given format.
func (*Accessor) MustSetObservedGeneration ¶
MustSetObservedGeneration sets the observed generation of the given condition.
It panics if the given value is not a pointer to a struct or does not have a field that can be converted to the given format.
func (*Accessor) MustSetReason ¶
MustSetReason sets the reason of the given condition.
It panics if the given value is not a struct or does not have a field that can be converted to the given format.
func (*Accessor) MustSetStatus ¶
func (a *Accessor) MustSetStatus(condPtr interface{}, status corev1.ConditionStatus)
MustSetStatus sets the status of the given condition.
It panics if the given value is not a pointer to a struct or does not have a field that can be converted to the given format.
func (*Accessor) MustSetType ¶
MustSetType sets the type of the given condition to the given value.
It panics if the given value is not a pointer to a struct or does not have a field that can be converted to the given format.
func (*Accessor) MustStatus ¶
func (a *Accessor) MustStatus(cond interface{}) corev1.ConditionStatus
MustStatus extracts the status of the given condition.
It panics if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) MustType ¶
MustType extracts the type of the given condition.
It panics if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) MustUpdate ¶
func (a *Accessor) MustUpdate(condPtr interface{}, opts ...UpdateOption)
MustUpdate updates the condition with the given options, setting transition- and update time accordingly.
MustUpdate panics if the given condPtr is not a pointer to a struct supporting the required condition fields.
func (*Accessor) MustUpdateSlice ¶
func (a *Accessor) MustUpdateSlice(condSlicePtr interface{}, typ string, opts ...UpdateOption)
MustUpdateSlice finds and updates the condition with the given target type.
MustUpdateSlice panics if condSlicePtr is not a pointer to a slice of structs that can be accessed with this Accessor. If no condition with the given type can be found, a new one is appended with the given type and updates applied. The last update time and last transition time of the new / existing condition is correctly updated: For new conditions, it's always set to the current time while for existing conditions, it's checked whether the status changed and then updated.
func (*Accessor) ObservedGeneration ¶
ObservedGeneration gets the observed generation of the given condition.
It errors if the given value is not a struct or does not have a field that can be converted to the input format.
func (*Accessor) Reason ¶
Reason extracts the reason of the given condition.
It errors if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) SetLastTransitionTime ¶
SetLastTransitionTime sets the last transition time of the given condition if the field exists.
It errors if the given value is not a pointer to a struct or does not have a field that can be converted to the output format.
func (*Accessor) SetLastTransitionTimeIfExists ¶
func (a *Accessor) SetLastTransitionTimeIfExists(condPtr interface{}, lastTransitionTime metav1.Time) error
SetLastTransitionTimeIfExists sets the last transition time of the given condition.
It errors if the given value is not a pointer to a struct or the field value cannot be converted to the given format.
func (*Accessor) SetLastUpdateTime ¶
SetLastUpdateTime sets the last update time of the given condition.
It errors if the given value is not a pointer to a struct or does not have a field that can be converted to the given format.
func (*Accessor) SetLastUpdateTimeIfExists ¶
SetLastUpdateTimeIfExists sets the last update time of the given condition if the field exists.
It errors if the given value is not a pointer to a struct or the field value cannot be converted to the given format.
func (*Accessor) SetMessage ¶
SetMessage sets the message of the given condition.
It errors if the given value is not a struct or does not have a field that can be converted to the given format.
func (*Accessor) SetObservedGeneration ¶
SetObservedGeneration sets the observed generation of the given condition.
It errors if the given value is not a pointer to a struct or does not have a field that can be converted to the given format.
func (*Accessor) SetReason ¶
SetReason sets the reason of the given condition.
It errors if the given value is not a struct or does not have a field that can be converted to the given format.
func (*Accessor) SetStatus ¶
func (a *Accessor) SetStatus(condPtr interface{}, status corev1.ConditionStatus) error
SetStatus sets the status of the given condition.
It errors if the given value is not a pointer to a struct or does not have a field that can be converted to the given format.
func (*Accessor) SetType ¶
SetType sets the type of the given condition to the given value.
It errors if the given value is not a pointer to a struct or does not have a field that can be converted to the given format.
func (*Accessor) Status ¶
func (a *Accessor) Status(cond interface{}) (corev1.ConditionStatus, error)
Status extracts the status of the given condition.
It errors if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) Type ¶
Type extracts the type of the given condition.
It errors if the given value is not a struct or does not have a field that can be converted to the output format.
func (*Accessor) Update ¶
func (a *Accessor) Update(condPtr interface{}, opts ...UpdateOption) error
Update updates the condition with the given options, setting transition- and update time accordingly.
Update errors if the given condPtr is not a pointer to a struct supporting the required condition fields.
func (*Accessor) UpdateSlice ¶
func (a *Accessor) UpdateSlice(condSlicePtr interface{}, typ string, opts ...UpdateOption) error
UpdateSlice finds and updates the condition with the given target type.
UpdateSlice errors if condSlicePtr is not a pointer to a slice of structs that can be accessed with this Accessor. If no condition with the given type can be found, a new one is appended with the given type and updates applied. The last update time and last transition time of the new / existing condition is correctly updated: For new conditions, it's always set to the current time while for existing conditions, it's checked whether the status changed and then updated.
type AccessorOptions ¶
type AccessorOptions struct { TypeField string StatusField string LastUpdateTimeField string LastTransitionTimeField string ReasonField string MessageField string ObservedGenerationField string Clock clock.Clock }
AccessorOptions are options to create an Accessor.
If left blank, defaults are being used via AccessorOptions.SetDefaults.
func (*AccessorOptions) SetDefaults ¶
func (o *AccessorOptions) SetDefaults()
SetDefaults sets default values for AccessorOptions.
type UpdateMessage ¶
type UpdateMessage string
UpdateMessage implements UpdateOption to set the message.
func (UpdateMessage) ApplyUpdate ¶
func (u UpdateMessage) ApplyUpdate(a *Accessor, condPtr interface{}) error
ApplyUpdate implements UpdateOption.
type UpdateObservedGeneration ¶
type UpdateObservedGeneration int64
UpdateObservedGeneration implements UpdateOption to set the observed generation.
func UpdateObserved ¶
func UpdateObserved(obj metav1.Object) UpdateObservedGeneration
UpdateObserved is a shorthand for updating the observed generation from a metav1.Object's generation.
func (UpdateObservedGeneration) ApplyUpdate ¶
func (u UpdateObservedGeneration) ApplyUpdate(a *Accessor, condPtr interface{}) error
ApplyUpdate implements UpdateOption.
type UpdateOption ¶
type UpdateOption interface { // ApplyUpdate applies the update, given a condition pointer. ApplyUpdate(a *Accessor, condPtr interface{}) error }
UpdateOption is an option given to Accessor.UpdateSlice that updates an individual condition.
type UpdateReason ¶
type UpdateReason string
UpdateReason implements UpdateOption to set the reason.
func (UpdateReason) ApplyUpdate ¶
func (u UpdateReason) ApplyUpdate(a *Accessor, condPtr interface{}) error
ApplyUpdate implements UpdateOption.
type UpdateStatus ¶
type UpdateStatus corev1.ConditionStatus
UpdateStatus implements UpdateOption to set a corev1.ConditionStatus.
func (UpdateStatus) ApplyUpdate ¶
func (u UpdateStatus) ApplyUpdate(a *Accessor, condPtr interface{}) error
ApplyUpdate implements UpdateOption.