@@ -17,105 +17,34 @@ limitations under the License.
17
17
package applyset
18
18
19
19
import (
20
- "encoding/json"
21
20
"strings"
22
21
23
22
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24
- "k8s.io/apimachinery/pkg/runtime/schema"
25
23
"k8s.io/klog/v2"
24
+ "sigs.k8s.io/kustomize/kstatus/status"
26
25
)
27
26
28
27
// isHealthy reports whether the object should be considered "healthy"
29
28
// TODO: Replace with kstatus library
30
29
func isHealthy (u * unstructured.Unstructured ) bool {
31
- // Check if the resource is scheduled for deletion
32
- deletionTimestamp := u .GetDeletionTimestamp ()
33
- if deletionTimestamp != nil {
34
- klog .Infof ("object %s is scheduled for deletion" , humanName (u ))
30
+ result , err := status .Compute (u )
31
+ if err != nil {
32
+ klog .Infof ("unable to compute condition for %s" , humanName (u ))
35
33
return false
36
34
}
37
-
38
- gvk := u .GroupVersionKind ()
39
- switch gvk {
40
- case schema.GroupVersionKind {Group : "" , Version : "v1" , Kind : "ConfigMap" },
41
- schema.GroupVersionKind {Group : "" , Version : "v1" , Kind : "ServiceAccount" }:
42
- // No ready signal; assume ready
43
- return true
44
- case schema.GroupVersionKind {Group : "rbac.authorization.k8s.io" , Version : "v1" , Kind : "ClusterRole" },
45
- schema.GroupVersionKind {Group : "rbac.authorization.k8s.io" , Version : "v1" , Kind : "ClusterRoleBinding" },
46
- schema.GroupVersionKind {Group : "rbac.authorization.k8s.io" , Version : "v1" , Kind : "Role" },
47
- schema.GroupVersionKind {Group : "rbac.authorization.k8s.io" , Version : "v1" , Kind : "RoleBinding" }:
48
- // No ready signal; assume ready
49
- return true
50
- case schema.GroupVersionKind {Group : "scheduling.k8s.io" , Version : "v1" , Kind : "PriorityClass" }:
51
- // No ready signal; assume ready
52
- return true
53
- case schema.GroupVersionKind {Group : "storage.k8s.io" , Version : "v1" , Kind : "StorageClass" }:
54
- // No ready signal; assume ready
55
- return true
56
- }
57
-
58
- ready := true
59
- statusConditions , found , err := unstructured .NestedFieldNoCopy (u .Object , "status" , "conditions" )
60
- if err != nil || ! found {
61
- klog .Infof ("status conditions not found for %s" , humanName (u ))
62
- return true
63
- }
64
-
65
- statusConditionsList , ok := statusConditions .([]interface {})
66
- if ! ok {
67
- klog .Warningf ("expected status.conditions to be list, got %T" , statusConditions )
35
+ switch result .Status {
36
+ case status .InProgressStatus :
37
+ return false
38
+ case status .FailedStatus :
39
+ return false
40
+ case status .TerminatingStatus :
41
+ return false
42
+ case status .UnknownStatus :
43
+ klog .Warningf ("unknown status for %s" , humanName (u ))
44
+ return false
45
+ default : // status.CurrentStatus:
68
46
return true
69
47
}
70
- for i := range statusConditionsList {
71
- condition := statusConditionsList [i ]
72
- conditionMap , ok := condition .(map [string ]interface {})
73
- if ! ok {
74
- klog .Warningf ("expected status.conditions[%d] to be map, got %T" , i , condition )
75
- return true
76
- }
77
-
78
- conditionType := ""
79
- conditionStatus := ""
80
- for k , v := range conditionMap {
81
- switch k {
82
- case "type" :
83
- s , ok := v .(string )
84
- if ! ok {
85
- klog .Warningf ("expected status.conditions[].type to be string, got %T" , v )
86
- } else {
87
- conditionType = s
88
- }
89
- case "status" :
90
- s , ok := v .(string )
91
- if ! ok {
92
- klog .Warningf ("expected status.conditions[].status to be string, got %T" , v )
93
- } else {
94
- conditionStatus = s
95
- }
96
- }
97
- }
98
-
99
- // TODO: Check conditionType?
100
-
101
- switch conditionStatus {
102
- case "True" :
103
- // ready
104
-
105
- case "False" :
106
- j , _ := json .Marshal (condition )
107
- klog .Infof ("status.conditions indicates object %s is not ready: %v" , humanName (u ), string (j ))
108
- ready = false
109
-
110
- case "" :
111
- klog .Warningf ("ignoring status.conditions[] type %q with unknown status %q" , conditionType , conditionStatus )
112
- }
113
- }
114
-
115
- if ! ready {
116
- klog .Infof ("object %s is not ready" , humanName (u ))
117
- }
118
- return ready
119
48
}
120
49
121
50
// humanName returns an identifier for the object suitable for printing in log messages
0 commit comments