Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apis/common/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,15 @@ type Condition struct { //nolint:recvcheck // False positive - only has non-poin
}

// Equal returns true if the condition is identical to the supplied condition,
// ignoring the LastTransitionTime.
// ignoring the LastTransitionTime. If one or both conditions have not
// provided the ObservedGeneration it is not considered in the comparison.
func (c Condition) Equal(other Condition) bool {
if c.ObservedGeneration == 0 || other.ObservedGeneration == 0 {
return c.Type == other.Type &&
c.Status == other.Status &&
c.Reason == other.Reason &&
c.Message == other.Message
}
return c.Type == other.Type &&
c.Status == other.Status &&
c.Reason == other.Reason &&
Expand Down
20 changes: 19 additions & 1 deletion apis/common/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,27 @@ func TestConditionEqual(t *testing.T) {
b: Condition{Message: "uncool"},
want: false,
},
"IdenticalWithMissingObservedGeneration": {
a: Condition{
Type: TypeReady,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: ReasonCreating,
Message: "UnitTest",
ObservedGeneration: 1,
},
b: Condition{
Type: TypeReady,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: ReasonCreating,
Message: "UnitTest",
},
want: true,
},
"DifferentObservedGeneration": {
a: Condition{ObservedGeneration: 1},
b: Condition{},
b: Condition{ObservedGeneration: 2},
want: false,
},
"CheckReconcilePaused": {
Expand Down