-
Notifications
You must be signed in to change notification settings - Fork 258
/
health.go
611 lines (571 loc) · 20.5 KB
/
health.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
package health
import (
"fmt"
"strings"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
coreV1 "k8s.io/api/core/v1"
extv1beta1 "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
apiregistrationv1beta1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
)
// Represents resource health status
type HealthStatusCode string
const (
// Indicates that health assessment failed and actual health status is unknown
HealthStatusUnknown HealthStatusCode = "Unknown"
// Progressing health status means that resource is not healthy but still have a chance to reach healthy state
HealthStatusProgressing HealthStatusCode = "Progressing"
// Resource is 100% healthy
HealthStatusHealthy HealthStatusCode = "Healthy"
// Assigned to resources that are suspended or paused. The typical example is a
// [suspended](https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#suspend) CronJob.
HealthStatusSuspended HealthStatusCode = "Suspended"
// Degrade status is used if resource status indicates failure or resource could not reach healthy state
// within some timeout.
HealthStatusDegraded HealthStatusCode = "Degraded"
// Indicates that resource is missing in the cluster.
HealthStatusMissing HealthStatusCode = "Missing"
)
// Implements custom health assessment that overrides built-in assessment
type HealthOverride interface {
GetResourceHealth(obj *unstructured.Unstructured) (*HealthStatus, error)
}
// Holds health assessment results
type HealthStatus struct {
Status HealthStatusCode `json:"status,omitempty"`
Message string `json:"message,omitempty"`
}
// healthOrder is a list of health codes in order of most healthy to least healthy
var healthOrder = []HealthStatusCode{
HealthStatusHealthy,
HealthStatusSuspended,
HealthStatusProgressing,
HealthStatusDegraded,
HealthStatusMissing,
HealthStatusUnknown,
}
// IsWorse returns whether or not the new health status code is a worser condition than the current
func IsWorse(current, new HealthStatusCode) bool {
currentIndex := 0
newIndex := 0
for i, code := range healthOrder {
if current == code {
currentIndex = i
}
if new == code {
newIndex = i
}
}
return newIndex > currentIndex
}
// GetResourceHealth returns the health of a k8s resource
func GetResourceHealth(obj *unstructured.Unstructured, healthOverride HealthOverride) (health *HealthStatus, err error) {
if obj.GetDeletionTimestamp() != nil {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: "Pending deletion",
}, nil
}
if healthOverride != nil {
health, err := healthOverride.GetResourceHealth(obj)
if err != nil {
health = &HealthStatus{
Status: HealthStatusUnknown,
Message: err.Error(),
}
return health, err
}
if health != nil {
return health, nil
}
}
gvk := obj.GroupVersionKind()
switch gvk.Group {
case "apps", "extensions":
switch gvk.Kind {
case kube.DeploymentKind:
health, err = getDeploymentHealth(obj)
case kube.IngressKind:
health, err = getIngressHealth(obj)
case kube.StatefulSetKind:
health, err = getStatefulSetHealth(obj)
case kube.ReplicaSetKind:
health, err = getReplicaSetHealth(obj)
case kube.DaemonSetKind:
health, err = getDaemonSetHealth(obj)
}
case "argoproj.io":
switch gvk.Kind {
case "Application":
health = getApplicationHealth(obj)
case "Workflow":
health, err = getArgoWorkflowHealth(obj)
}
case "apiregistration.k8s.io":
switch gvk.Kind {
case kube.APIServiceKind:
health, err = getAPIServiceHealth(obj)
}
case "networking.k8s.io":
switch gvk.Kind {
case kube.IngressKind:
health, err = getIngressHealth(obj)
}
case "":
switch gvk.Kind {
case kube.ServiceKind:
health, err = getServiceHealth(obj)
case kube.PersistentVolumeClaimKind:
health, err = getPVCHealth(obj)
case kube.PodKind:
health, err = getPodHealth(obj)
}
case "batch":
switch gvk.Kind {
case kube.JobKind:
health, err = getJobHealth(obj)
}
}
if err != nil {
health = &HealthStatus{
Status: HealthStatusUnknown,
Message: err.Error(),
}
}
return health, err
}
func getPVCHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
pvc := &coreV1.PersistentVolumeClaim{}
err := scheme.Scheme.Convert(obj, pvc, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, pvc, err)
}
switch pvc.Status.Phase {
case coreV1.ClaimLost:
return &HealthStatus{Status: HealthStatusDegraded}, nil
case coreV1.ClaimPending:
return &HealthStatus{Status: HealthStatusProgressing}, nil
case coreV1.ClaimBound:
return &HealthStatus{Status: HealthStatusHealthy}, nil
default:
return &HealthStatus{Status: HealthStatusUnknown}, nil
}
}
func getIngressHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
ingress := &extv1beta1.Ingress{}
err := scheme.Scheme.Convert(obj, ingress, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, ingress, err)
}
health := HealthStatus{}
if len(ingress.Status.LoadBalancer.Ingress) > 0 {
health.Status = HealthStatusHealthy
} else {
health.Status = HealthStatusProgressing
}
return &health, nil
}
func getServiceHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
service := &coreV1.Service{}
err := scheme.Scheme.Convert(obj, service, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, service, err)
}
health := HealthStatus{Status: HealthStatusHealthy}
if service.Spec.Type == coreV1.ServiceTypeLoadBalancer {
if len(service.Status.LoadBalancer.Ingress) > 0 {
health.Status = HealthStatusHealthy
} else {
health.Status = HealthStatusProgressing
}
}
return &health, nil
}
func getDeploymentHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
deployment := &appsv1.Deployment{}
err := scheme.Scheme.Convert(obj, deployment, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, deployment, err)
}
if deployment.Spec.Paused {
return &HealthStatus{
Status: HealthStatusSuspended,
Message: "Deployment is paused",
}, nil
}
// Borrowed at kubernetes/kubectl/rollout_status.go https://github.com/kubernetes/kubernetes/blob/5232ad4a00ec93942d0b2c6359ee6cd1201b46bc/pkg/kubectl/rollout_status.go#L80
if deployment.Generation <= deployment.Status.ObservedGeneration {
cond := getDeploymentCondition(deployment.Status, v1.DeploymentProgressing)
if cond != nil && cond.Reason == "ProgressDeadlineExceeded" {
return &HealthStatus{
Status: HealthStatusDegraded,
Message: fmt.Sprintf("Deployment %q exceeded its progress deadline", obj.GetName()),
}, nil
} else if deployment.Spec.Replicas != nil && deployment.Status.UpdatedReplicas < *deployment.Spec.Replicas {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for rollout to finish: %d out of %d new replicas have been updated...", deployment.Status.UpdatedReplicas, *deployment.Spec.Replicas),
}, nil
} else if deployment.Status.Replicas > deployment.Status.UpdatedReplicas {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for rollout to finish: %d old replicas are pending termination...", deployment.Status.Replicas-deployment.Status.UpdatedReplicas),
}, nil
} else if deployment.Status.AvailableReplicas < deployment.Status.UpdatedReplicas {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for rollout to finish: %d of %d updated replicas are available...", deployment.Status.AvailableReplicas, deployment.Status.UpdatedReplicas),
}, nil
}
} else {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: "Waiting for rollout to finish: observed deployment generation less then desired generation",
}, nil
}
return &HealthStatus{
Status: HealthStatusHealthy,
}, nil
}
func init() {
_ = apiregistrationv1.SchemeBuilder.AddToScheme(scheme.Scheme)
_ = apiregistrationv1beta1.SchemeBuilder.AddToScheme(scheme.Scheme)
}
func getApplicationHealth(obj *unstructured.Unstructured) *HealthStatus {
status, _, _ := unstructured.NestedString(obj.Object, "status", "health", "status")
message, _, _ := unstructured.NestedString(obj.Object, "status", "health", "message")
return &HealthStatus{Status: HealthStatusCode(status), Message: message}
}
func getDaemonSetHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
daemon := &appsv1.DaemonSet{}
err := scheme.Scheme.Convert(obj, daemon, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, daemon, err)
}
// Borrowed at kubernetes/kubectl/rollout_status.go https://github.com/kubernetes/kubernetes/blob/5232ad4a00ec93942d0b2c6359ee6cd1201b46bc/pkg/kubectl/rollout_status.go#L110
if daemon.Generation <= daemon.Status.ObservedGeneration {
if daemon.Status.UpdatedNumberScheduled < daemon.Status.DesiredNumberScheduled {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for daemon set %q rollout to finish: %d out of %d new pods have been updated...", daemon.Name, daemon.Status.UpdatedNumberScheduled, daemon.Status.DesiredNumberScheduled),
}, nil
}
if daemon.Status.NumberAvailable < daemon.Status.DesiredNumberScheduled {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for daemon set %q rollout to finish: %d of %d updated pods are available...", daemon.Name, daemon.Status.NumberAvailable, daemon.Status.DesiredNumberScheduled),
}, nil
}
} else {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: "Waiting for rollout to finish: observed daemon set generation less then desired generation",
}, nil
}
return &HealthStatus{
Status: HealthStatusHealthy,
}, nil
}
func getStatefulSetHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
sts := &appsv1.StatefulSet{}
err := scheme.Scheme.Convert(obj, sts, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, sts, err)
}
// Borrowed at kubernetes/kubectl/rollout_status.go https://github.com/kubernetes/kubernetes/blob/5232ad4a00ec93942d0b2c6359ee6cd1201b46bc/pkg/kubectl/rollout_status.go#L131
if sts.Status.ObservedGeneration == 0 || sts.Generation > sts.Status.ObservedGeneration {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: "Waiting for statefulset spec update to be observed...",
}, nil
}
if sts.Spec.Replicas != nil && sts.Status.ReadyReplicas < *sts.Spec.Replicas {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for %d pods to be ready...", *sts.Spec.Replicas-sts.Status.ReadyReplicas),
}, nil
}
if sts.Spec.UpdateStrategy.Type == appsv1.RollingUpdateStatefulSetStrategyType && sts.Spec.UpdateStrategy.RollingUpdate != nil {
if sts.Spec.Replicas != nil && sts.Spec.UpdateStrategy.RollingUpdate.Partition != nil {
if sts.Status.UpdatedReplicas < (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition) {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for partitioned roll out to finish: %d out of %d new pods have been updated...",
sts.Status.UpdatedReplicas, (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition)),
}, nil
}
}
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("partitioned roll out complete: %d new pods have been updated...", sts.Status.UpdatedReplicas),
}, nil
}
if sts.Status.UpdateRevision != sts.Status.CurrentRevision {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("waiting for statefulset rolling update to complete %d pods at revision %s...", sts.Status.UpdatedReplicas, sts.Status.UpdateRevision),
}, nil
}
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("statefulset rolling update complete %d pods at revision %s...", sts.Status.CurrentReplicas, sts.Status.CurrentRevision),
}, nil
}
func getReplicaSetHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
replicaSet := &appsv1.ReplicaSet{}
err := scheme.Scheme.Convert(obj, replicaSet, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, replicaSet, err)
}
if replicaSet.Generation <= replicaSet.Status.ObservedGeneration {
cond := getReplicaSetCondition(replicaSet.Status, v1.ReplicaSetReplicaFailure)
if cond != nil && cond.Status == coreV1.ConditionTrue {
return &HealthStatus{
Status: HealthStatusDegraded,
Message: cond.Message,
}, nil
} else if replicaSet.Spec.Replicas != nil && replicaSet.Status.AvailableReplicas < *replicaSet.Spec.Replicas {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for rollout to finish: %d out of %d new replicas are available...", replicaSet.Status.AvailableReplicas, *replicaSet.Spec.Replicas),
}, nil
}
} else {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: "Waiting for rollout to finish: observed replica set generation less then desired generation",
}, nil
}
return &HealthStatus{
Status: HealthStatusHealthy,
}, nil
}
func getDeploymentCondition(status v1.DeploymentStatus, condType v1.DeploymentConditionType) *v1.DeploymentCondition {
for i := range status.Conditions {
c := status.Conditions[i]
if c.Type == condType {
return &c
}
}
return nil
}
func getReplicaSetCondition(status v1.ReplicaSetStatus, condType v1.ReplicaSetConditionType) *v1.ReplicaSetCondition {
for i := range status.Conditions {
c := status.Conditions[i]
if c.Type == condType {
return &c
}
}
return nil
}
func getJobHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
job := &batchv1.Job{}
err := scheme.Scheme.Convert(obj, job, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, job, err)
}
failed := false
var failMsg string
complete := false
var message string
for _, condition := range job.Status.Conditions {
switch condition.Type {
case batchv1.JobFailed:
failed = true
complete = true
failMsg = condition.Message
case batchv1.JobComplete:
complete = true
message = condition.Message
}
}
if !complete {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: message,
}, nil
} else if failed {
return &HealthStatus{
Status: HealthStatusDegraded,
Message: failMsg,
}, nil
} else {
return &HealthStatus{
Status: HealthStatusHealthy,
Message: message,
}, nil
}
}
func getPodHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
pod := &coreV1.Pod{}
err := scheme.Scheme.Convert(obj, pod, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, pod, err)
}
// This logic cannot be applied when the pod.Spec.RestartPolicy is: coreV1.RestartPolicyOnFailure,
// coreV1.RestartPolicyNever, otherwise it breaks the resource hook logic.
// The issue is, if we mark a pod with ImagePullBackOff as Degraded, and the pod is used as a resource hook,
// then we will prematurely fail the PreSync/PostSync hook. Meanwhile, when that error condition is resolved
// (e.g. the image is available), the resource hook pod will unexpectedly be executed even though the sync has
// completed.
if pod.Spec.RestartPolicy == coreV1.RestartPolicyAlways {
var status HealthStatusCode
var messages []string
for _, containerStatus := range pod.Status.ContainerStatuses {
waiting := containerStatus.State.Waiting
// Article listing common container errors: https://medium.com/kokster/debugging-crashloopbackoffs-with-init-containers-26f79e9fb5bf
if waiting != nil && (strings.HasPrefix(waiting.Reason, "Err") || strings.HasSuffix(waiting.Reason, "Error") || strings.HasSuffix(waiting.Reason, "BackOff")) {
status = HealthStatusDegraded
messages = append(messages, waiting.Message)
}
}
if status != "" {
return &HealthStatus{
Status: status,
Message: strings.Join(messages, ", "),
}, nil
}
}
getFailMessage := func(ctr *coreV1.ContainerStatus) string {
if ctr.State.Terminated != nil {
if ctr.State.Terminated.Message != "" {
return ctr.State.Terminated.Message
}
if ctr.State.Terminated.Reason == "OOMKilled" {
return ctr.State.Terminated.Reason
}
if ctr.State.Terminated.ExitCode != 0 {
return fmt.Sprintf("container %q failed with exit code %d", ctr.Name, ctr.State.Terminated.ExitCode)
}
}
return ""
}
switch pod.Status.Phase {
case coreV1.PodPending:
return &HealthStatus{
Status: HealthStatusProgressing,
Message: pod.Status.Message,
}, nil
case coreV1.PodSucceeded:
return &HealthStatus{
Status: HealthStatusHealthy,
Message: pod.Status.Message,
}, nil
case coreV1.PodFailed:
if pod.Status.Message != "" {
// Pod has a nice error message. Use that.
return &HealthStatus{Status: HealthStatusDegraded, Message: pod.Status.Message}, nil
}
for _, ctr := range append(pod.Status.InitContainerStatuses, pod.Status.ContainerStatuses...) {
if msg := getFailMessage(&ctr); msg != "" {
return &HealthStatus{Status: HealthStatusDegraded, Message: msg}, nil
}
}
return &HealthStatus{Status: HealthStatusDegraded, Message: ""}, nil
case coreV1.PodRunning:
switch pod.Spec.RestartPolicy {
case coreV1.RestartPolicyAlways:
// if pod is ready, it is automatically healthy
if podutil.IsPodReady(pod) {
return &HealthStatus{
Status: HealthStatusHealthy,
Message: pod.Status.Message,
}, nil
}
// if it's not ready, check to see if any container terminated, if so, it's degraded
for _, ctrStatus := range pod.Status.ContainerStatuses {
if ctrStatus.LastTerminationState.Terminated != nil {
return &HealthStatus{
Status: HealthStatusDegraded,
Message: pod.Status.Message,
}, nil
}
}
// otherwise we are progressing towards a ready state
return &HealthStatus{
Status: HealthStatusProgressing,
Message: pod.Status.Message,
}, nil
case coreV1.RestartPolicyOnFailure, coreV1.RestartPolicyNever:
// pods set with a restart policy of OnFailure or Never, have a finite life.
// These pods are typically resource hooks. Thus, we consider these as Progressing
// instead of healthy.
return &HealthStatus{
Status: HealthStatusProgressing,
Message: pod.Status.Message,
}, nil
}
}
return &HealthStatus{
Status: HealthStatusUnknown,
Message: pod.Status.Message,
}, nil
}
func getAPIServiceHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
apiservice := &apiregistrationv1.APIService{}
err := scheme.Scheme.Convert(obj, apiservice, nil)
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, apiservice, err)
}
for _, c := range apiservice.Status.Conditions {
switch c.Type {
case apiregistrationv1.Available:
if c.Status == apiregistrationv1.ConditionTrue {
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("%s: %s", c.Reason, c.Message),
}, nil
} else {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("%s: %s", c.Reason, c.Message),
}, nil
}
}
}
return &HealthStatus{
Status: HealthStatusProgressing,
Message: "Waiting to be processed",
}, nil
}
type NodePhase string
// Workflow and node statuses
const (
NodePending NodePhase = "Pending"
NodeRunning NodePhase = "Running"
NodeSucceeded NodePhase = "Succeeded"
NodeSkipped NodePhase = "Skipped"
NodeFailed NodePhase = "Failed"
NodeError NodePhase = "Error"
)
// An agnostic workflow object only considers Status.Phase and Status.Message. It is agnostic to the API version or any
// other fields.
type ArgoWorkflow struct {
Status struct {
Phase NodePhase
Message string
}
}
func getArgoWorkflowHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
var wf ArgoWorkflow
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &wf)
if err != nil {
return nil, err
}
switch wf.Status.Phase {
case NodePending, NodeRunning:
return &HealthStatus{Status: HealthStatusProgressing, Message: wf.Status.Message}, nil
case NodeSucceeded:
return &HealthStatus{Status: HealthStatusHealthy, Message: wf.Status.Message}, nil
case NodeFailed, NodeError:
return &HealthStatus{Status: HealthStatusDegraded, Message: wf.Status.Message}, nil
}
return &HealthStatus{Status: HealthStatusHealthy, Message: wf.Status.Message}, nil
}