1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-03 16:25:09 +00:00

Always set message on conditions

and default reason to "Error" if no specific reason is specified
This commit is contained in:
Craig Jellick
2017-12-27 13:58:02 -07:00
parent 0d05740f8d
commit 0b2c60dc92

View File

@@ -42,22 +42,16 @@ func (c Cond) Reason(obj runtime.Object, reason string) {
func (c Cond) Message(obj runtime.Object, message string) { func (c Cond) Message(obj runtime.Object, message string) {
cond := findOrCreateCond(obj, string(c)) cond := findOrCreateCond(obj, string(c))
v := getFieldValue(cond, "Message") getFieldValue(cond, "Message").SetString(message)
if v.IsValid() {
v.SetString(message)
}
} }
func (c Cond) ReasonError(obj runtime.Object, err error) { func (c Cond) ReasonAndMessageFromError(obj runtime.Object, err error) {
cond := findOrCreateCond(obj, string(c)) cond := findOrCreateCond(obj, string(c))
getFieldValue(cond, "Message").SetString(err.Error())
if ce, ok := err.(*conditionError); ok { if ce, ok := err.(*conditionError); ok {
getFieldValue(cond, "Reason").SetString(ce.reason) getFieldValue(cond, "Reason").SetString(ce.reason)
v := getFieldValue(cond, "Message")
if v.IsValid() {
v.SetString(ce.Error())
}
} else { } else {
getFieldValue(cond, "Reason").SetString(err.Error()) getFieldValue(cond, "Reason").SetString("Error")
} }
touchTS(cond) touchTS(cond)
} }
@@ -86,7 +80,7 @@ func (c Cond) Once(obj runtime.Object, f func() (runtime.Object, error)) (runtim
if err != nil { if err != nil {
c.False(obj) c.False(obj)
c.ReasonError(obj, err) c.ReasonAndMessageFromError(obj, err)
return obj, err return obj, err
} }
c.True(obj) c.True(obj)
@@ -102,7 +96,7 @@ func (c Cond) Do(obj runtime.Object, f func() (runtime.Object, error)) (runtime.
if err != nil { if err != nil {
c.False(obj) c.False(obj)
c.ReasonError(obj, err) c.ReasonAndMessageFromError(obj, err)
return obj, err return obj, err
} }
c.True(obj) c.True(obj)