-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.go
More file actions
54 lines (49 loc) · 1.25 KB
/
status.go
File metadata and controls
54 lines (49 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"encoding/json"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/klog"
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
)
type ReadyStatus string // True False Unknown or ""
type Reason string
func extractStatus(obj unstructured.Unstructured) (ReadyStatus, Reason, status.Status) {
jsonVal, _ := json.Marshal(obj.Object["status"])
klog.V(6).Infof("status for object=%s/%s: %s", obj.GetKind(), obj.GetName(), string(jsonVal))
result, err := status.Compute(&obj)
if err != nil {
return "", "", ""
}
statusF, ok := obj.Object["status"]
if !ok {
return "", "", ""
}
statusV, ok := statusF.(map[string]interface{})
if !ok {
return "", "", ""
}
conditionsF, ok := statusV["conditions"]
if !ok {
return "", "", ""
}
conditionsV, ok := conditionsF.([]interface{})
if !ok {
return "", "", ""
}
for _, cond := range conditionsV {
condM, ok := cond.(map[string]interface{})
if !ok {
return "", "", ""
}
condType, ok := condM["type"].(string)
if !ok {
return "", "", ""
}
if condType == "Ready" {
condStatus, _ := condM["status"].(string)
condReason, _ := condM["reason"].(string)
return ReadyStatus(condStatus), Reason(condReason), status.Status(result.Status.String())
}
}
return "", "", ""
}