forked from argoproj/gitops-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health_daemonset.go
57 lines (53 loc) · 2.28 KB
/
health_daemonset.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
package health
import (
"fmt"
"github.com/STollenaar/gitops-engine/pkg/utils/kube"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)
func getDaemonSetHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
gvk := obj.GroupVersionKind()
switch gvk {
case appsv1.SchemeGroupVersion.WithKind(kube.DaemonSetKind):
var daemon appsv1.DaemonSet
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &daemon)
if err != nil {
return nil, fmt.Errorf("failed to convert unstructured DaemonSet to typed: %v", err)
}
return getAppsv1DaemonSetHealth(&daemon)
default:
return nil, fmt.Errorf("unsupported DaemonSet GVK: %s", gvk)
}
}
func getAppsv1DaemonSetHealth(daemon *appsv1.DaemonSet) (*HealthStatus, error) {
// 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.Spec.UpdateStrategy.Type == appsv1.OnDeleteDaemonSetStrategyType {
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("daemon set %d out of %d new pods have been updated", daemon.Status.UpdatedNumberScheduled, daemon.Status.DesiredNumberScheduled),
}, nil
}
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 than desired generation",
}, nil
}
return &HealthStatus{
Status: HealthStatusHealthy,
}, nil
}