From e21ff6bb726487dca9172ff57c9ab028a196af41 Mon Sep 17 00:00:00 2001 From: Bob Haddleton Date: Mon, 19 Jan 2026 19:12:44 -0600 Subject: [PATCH] Handle null observedGeneration in condition Equal() Signed-off-by: Bob Haddleton (cherry picked from commit 940b55294fa0992406b658d8becc86082dd3a93b) --- apis/common/condition.go | 9 ++++++++- apis/common/condition_test.go | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/apis/common/condition.go b/apis/common/condition.go index f1c91b809..03f67110c 100644 --- a/apis/common/condition.go +++ b/apis/common/condition.go @@ -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 && diff --git a/apis/common/condition_test.go b/apis/common/condition_test.go index 50b052ce4..6e0846e33 100644 --- a/apis/common/condition_test.go +++ b/apis/common/condition_test.go @@ -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": {