Skip to content

Commit

Permalink
Merge pull request fluxcd#254 from fluxcd/fix-lexicographicless
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco authored Mar 29, 2022
2 parents 391f780 + bb1f335 commit 357066b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions runtime/conditions/setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ var conditionWeights = map[string]int{
meta.ReadyCondition: 2,
}

// lexicographicLess returns true if a condition is less than another in regard to the to order of conditions
// 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. The condition types in conditionWeights always go first,
// sorted by their defined weight, followed by all the other conditions sorted by highest observedGeneration and
// lexicographically by Type.
Expand All @@ -208,8 +208,10 @@ func lexicographicLess(i, j *metav1.Condition) bool {
return w1 < w2
case ok1, ok2:
return !ok2
case i.ObservedGeneration == j.ObservedGeneration:
return i.Type < j.Type
default:
return i.ObservedGeneration >= j.ObservedGeneration && i.Type < j.Type
return i.ObservedGeneration > j.ObservedGeneration
}
}

Expand Down
7 changes: 7 additions & 0 deletions runtime/conditions/setter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func TestLexicographicLess(t *testing.T) {
b.ObservedGeneration = 0
g.Expect(lexicographicLess(a, b)).To(BeTrue())

// Disregard Type when observed generations aren't equal.
c := TrueCondition("C", "", "")
c.ObservedGeneration = 1
b = TrueCondition("B", "", "")
b.ObservedGeneration = 0
g.Expect(lexicographicLess(c, b)).To(BeTrue())

// Stalled, Ready, and Reconciling conditions are threaded as an
// exception and always go first.
stalled := TrueCondition(meta.StalledCondition, "", "")
Expand Down

0 comments on commit 357066b

Please sign in to comment.