1
0
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:
Craig Jellick 2018-03-04 22:02:09 -07:00 committed by Darren Shepherd
parent db757b8925
commit fd5df5220e

View File

@ -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"