mirror of https://github.com/knative/pkg.git
Realized a corner case on ordering and False > Unknown states. (#1110)
* Realized a corner case on ordering and False > Unknown states. * add test with unknown fall through.
This commit is contained in:
parent
5c9bc970ce
commit
d38e1f8bde
|
@ -261,13 +261,7 @@ func (r conditionsImpl) MarkTrue(t ConditionType) {
|
|||
// Update the happy condition if the current ready condition is
|
||||
// marked not ready because of this condition.
|
||||
if org.Reason == orgTL.Reason && org.Message == orgTL.Message {
|
||||
r.SetCondition(Condition{
|
||||
Type: r.happy,
|
||||
Status: c.Status,
|
||||
Reason: c.Reason,
|
||||
Message: c.Message,
|
||||
Severity: r.severity(r.happy),
|
||||
})
|
||||
r.propagateFailure(org, orgTL)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -281,6 +275,38 @@ func (r conditionsImpl) MarkTrue(t ConditionType) {
|
|||
})
|
||||
}
|
||||
|
||||
func (r conditionsImpl) propagateFailure(org, orgTL *Condition) {
|
||||
// First check the dependents with Status == False.
|
||||
for _, cond := range r.dependents {
|
||||
c := r.GetCondition(cond)
|
||||
// False conditions trump Unknown.
|
||||
if c.IsFalse() {
|
||||
r.SetCondition(Condition{
|
||||
Type: r.happy,
|
||||
Status: c.Status,
|
||||
Reason: c.Reason,
|
||||
Message: c.Message,
|
||||
Severity: r.severity(r.happy),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
// Second check for dependents with Status == Unknown.
|
||||
for _, cond := range r.dependents {
|
||||
c := r.GetCondition(cond)
|
||||
if c.IsUnknown() {
|
||||
r.SetCondition(Condition{
|
||||
Type: r.happy,
|
||||
Status: c.Status,
|
||||
Reason: c.Reason,
|
||||
Message: c.Message,
|
||||
Severity: r.severity(r.happy),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MarkUnknown sets the status of t to Unknown and also sets the happy condition
|
||||
// to Unknown if no other dependent condition is in an error state.
|
||||
func (r conditionsImpl) MarkUnknown(t ConditionType, reason, messageFormat string, messageA ...interface{}) {
|
||||
|
|
|
@ -548,6 +548,68 @@ func TestMarkTrue(t *testing.T) {
|
|||
Reason: "BarReason",
|
||||
Message: "BarMsg",
|
||||
},
|
||||
}, {
|
||||
name: "update dep 1/3, mixed status, still not happy",
|
||||
conditions: Conditions{{
|
||||
Type: ConditionReady,
|
||||
Status: corev1.ConditionFalse,
|
||||
Reason: "FooReason",
|
||||
Message: "FooMsg",
|
||||
}, {
|
||||
Type: "Foo",
|
||||
Status: corev1.ConditionFalse,
|
||||
Reason: "FooReason",
|
||||
Message: "FooMsg",
|
||||
}, {
|
||||
Type: "Bar",
|
||||
Status: corev1.ConditionUnknown,
|
||||
Reason: "BarReason",
|
||||
Message: "BarMsg",
|
||||
}, {
|
||||
Type: "Baz",
|
||||
Status: corev1.ConditionFalse,
|
||||
Reason: "BazReason",
|
||||
Message: "BazMsg",
|
||||
}},
|
||||
mark: "Foo",
|
||||
happy: false,
|
||||
happyWant: &Condition{
|
||||
Type: ConditionReady,
|
||||
Status: corev1.ConditionFalse,
|
||||
Reason: "BazReason",
|
||||
Message: "BazMsg",
|
||||
},
|
||||
}, {
|
||||
name: "update dep 1/3, unknown status, still not happy",
|
||||
conditions: Conditions{{
|
||||
Type: ConditionReady,
|
||||
Status: corev1.ConditionFalse,
|
||||
Reason: "FooReason",
|
||||
Message: "FooMsg",
|
||||
}, {
|
||||
Type: "Foo",
|
||||
Status: corev1.ConditionFalse,
|
||||
Reason: "FooReason",
|
||||
Message: "FooMsg",
|
||||
}, {
|
||||
Type: "Bar",
|
||||
Status: corev1.ConditionUnknown,
|
||||
Reason: "BarReason",
|
||||
Message: "BarMsg",
|
||||
}, {
|
||||
Type: "Baz",
|
||||
Status: corev1.ConditionUnknown,
|
||||
Reason: "BazReason",
|
||||
Message: "BazMsg",
|
||||
}},
|
||||
mark: "Foo",
|
||||
happy: false,
|
||||
happyWant: &Condition{
|
||||
Type: ConditionReady,
|
||||
Status: corev1.ConditionUnknown,
|
||||
Reason: "BarReason",
|
||||
Message: "BarMsg",
|
||||
},
|
||||
}}
|
||||
doTestMarkTrueAccessor(t, cases)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue