diff --git a/util/conditions/setter.go b/util/conditions/setter.go index c387f0fc410c..dde10400f259 100644 --- a/util/conditions/setter.go +++ b/util/conditions/setter.go @@ -186,11 +186,17 @@ func Delete(to Setter, t clusterv1.ConditionType) { to.SetConditions(newConditions) } -// lexicographicLess returns true if a condition is less than another with regards to the -// to order of conditions designed for convenience of the consumer, i.e. kubectl. +// lexicographicLess returns true if a condition is less than another in regard to +// the order of conditions designed for convenience of the consumer, i.e. kubectl. // According to this order the Ready condition always goes first, followed by all the other // conditions sorted by Type. func lexicographicLess(i, j *clusterv1.Condition) bool { + if i == nil { + return true + } + if j == nil { + return false + } return (i.Type == clusterv1.ReadyCondition || i.Type < j.Type) && j.Type != clusterv1.ReadyCondition } diff --git a/util/conditions/setter_test.go b/util/conditions/setter_test.go index 57c3a770e629..8828ce9e13a2 100644 --- a/util/conditions/setter_test.go +++ b/util/conditions/setter_test.go @@ -84,6 +84,12 @@ func TestLexicographicLess(t *testing.T) { a = TrueCondition("A") b = TrueCondition(clusterv1.ReadyCondition) g.Expect(lexicographicLess(a, b)).To(BeFalse()) + + a = TrueCondition("A") + g.Expect(lexicographicLess(a, nil1)).To(BeFalse()) + + b = TrueCondition("A") + g.Expect(lexicographicLess(nil1, b)).To(BeTrue()) } func TestSet(t *testing.T) {