mirror of
https://github.com/rancher/types.git
synced 2025-06-23 12:17:03 +00:00
Look for conditions in annotation
Check cattle.io/status annotation for storing status on resources that dont support it natively.
This commit is contained in:
parent
db757b8925
commit
fd5df5220e
@ -5,10 +5,17 @@ import (
|
||||
|
||||
"time"
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rancher/norman/types/convert"
|
||||
"github.com/rancher/norman/types/values"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type status struct {
|
||||
Conditions []condition `json:"conditions"`
|
||||
}
|
||||
|
||||
type condition struct {
|
||||
Type string
|
||||
Status string
|
||||
@ -44,6 +51,7 @@ var transitioningMap = map[string]string{
|
||||
"Saved": "saving",
|
||||
"Updated": "updating",
|
||||
"Updating": "updating",
|
||||
"InitialRolesPopulated": "activating",
|
||||
}
|
||||
|
||||
// True == error
|
||||
@ -93,6 +101,21 @@ func Set(data map[string]interface{}) {
|
||||
var conditions []condition
|
||||
convert.ToObj(val, &conditions)
|
||||
|
||||
statusAnn, annOK := values.GetValue(data, "metadata", "annotations", "cattle.io/status")
|
||||
if annOK {
|
||||
status := &status{}
|
||||
s, ok := statusAnn.(string)
|
||||
if ok {
|
||||
err := json.Unmarshal([]byte(s), status)
|
||||
if err != nil {
|
||||
logrus.Warnf("Unable to unmarshal cattle status %v. Error: %v", s, err)
|
||||
}
|
||||
}
|
||||
if len(status.Conditions) > 0 {
|
||||
conditions = append(conditions, status.Conditions...)
|
||||
}
|
||||
}
|
||||
|
||||
val, ok := values.GetValue(data, "metadata", "removed")
|
||||
if ok && val != "" && val != nil {
|
||||
data["state"] = "removing"
|
||||
|
Loading…
Reference in New Issue
Block a user