From 3c4b42de75be318df5d028ded4086fc04e0f2147 Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Thu, 11 Apr 2019 07:47:59 -0700 Subject: [PATCH] Displays resources that are being deleted as "Progressing". Closes #1410 (#1426) --- util/health/health.go | 11 ++-- util/health/health_test.go | 7 +-- util/health/testdata/pod-deletion.yaml | 75 ++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 util/health/testdata/pod-deletion.yaml diff --git a/util/health/health.go b/util/health/health.go index 74e092df94..5aba422c17 100644 --- a/util/health/health.go +++ b/util/health/health.go @@ -49,10 +49,15 @@ func SetApplicationHealth(resStatuses []appv1.ResourceStatus, liveObjs []*unstru // GetResourceHealth returns the health of a k8s resource func GetResourceHealth(obj *unstructured.Unstructured, resourceOverrides map[string]appv1.ResourceOverride) (*appv1.HealthStatus, error) { - var err error - var health *appv1.HealthStatus - health, err = getResourceHealthFromLuaScript(obj, resourceOverrides) + if obj.GetDeletionTimestamp() != nil { + return &appv1.HealthStatus{ + Status: appv1.HealthStatusProgressing, + Message: "Pending deletion", + }, nil + } + + health, err := getResourceHealthFromLuaScript(obj, resourceOverrides) if err != nil { health = &appv1.HealthStatus{ Status: appv1.HealthStatusUnknown, diff --git a/util/health/health_test.go b/util/health/health_test.go index dc6d9c6a75..2f71a8e7b4 100644 --- a/util/health/health_test.go +++ b/util/health/health_test.go @@ -13,12 +13,12 @@ import ( ) func assertAppHealth(t *testing.T, yamlPath string, expectedStatus appv1.HealthStatusCode) { - health := getHealtStatus(yamlPath, t) + health := getHealthStatus(yamlPath, t) assert.NotNil(t, health) assert.Equal(t, expectedStatus, health.Status) } -func getHealtStatus(yamlPath string, t *testing.T) *appv1.HealthStatus { +func getHealthStatus(yamlPath string, t *testing.T) *appv1.HealthStatus { yamlBytes, err := ioutil.ReadFile(yamlPath) assert.Nil(t, err) var obj unstructured.Unstructured @@ -59,7 +59,7 @@ func TestIngressHealth(t *testing.T) { } func TestCRD(t *testing.T) { - assert.Nil(t, getHealtStatus("./testdata/knative-service.yaml", t)) + assert.Nil(t, getHealthStatus("./testdata/knative-service.yaml", t)) } func TestJob(t *testing.T) { @@ -79,6 +79,7 @@ func TestPod(t *testing.T) { assertAppHealth(t, "./testdata/pod-running-restart-onfailure.yaml", appv1.HealthStatusProgressing) assertAppHealth(t, "./testdata/pod-failed.yaml", appv1.HealthStatusDegraded) assertAppHealth(t, "./testdata/pod-succeeded.yaml", appv1.HealthStatusHealthy) + assertAppHealth(t, "./testdata/pod-deletion.yaml", appv1.HealthStatusProgressing) } func TestSetApplicationHealth(t *testing.T) { diff --git a/util/health/testdata/pod-deletion.yaml b/util/health/testdata/pod-deletion.yaml new file mode 100644 index 0000000000..27177cd6bd --- /dev/null +++ b/util/health/testdata/pod-deletion.yaml @@ -0,0 +1,75 @@ +apiVersion: v1 +kind: Pod +metadata: + creationTimestamp: 2018-12-02T10:16:04Z + name: image-pull-backoff + namespace: argocd + resourceVersion: "155333" + selfLink: /api/v1/namespaces/argocd/pods/image-pull-backoff + uid: 46c1e8de-f61b-11e8-a057-fe5f49266390 + deletionTimestamp: 2018-12-03T10:16:04Z +spec: + containers: + - image: doesnt-exist + imagePullPolicy: Always + name: main + resources: {} + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /var/run/secrets/kubernetes.io/serviceaccount + name: default-token-f9jvj + readOnly: true + dnsPolicy: ClusterFirst + nodeName: minikube + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + serviceAccount: default + serviceAccountName: default + terminationGracePeriodSeconds: 30 + tolerations: + - effect: NoExecute + key: node.kubernetes.io/not-ready + operator: Exists + tolerationSeconds: 300 + - effect: NoExecute + key: node.kubernetes.io/unreachable + operator: Exists + tolerationSeconds: 300 + volumes: + - name: default-token-f9jvj + secret: + defaultMode: 420 + secretName: default-token-f9jvj +status: + conditions: + - lastProbeTime: null + lastTransitionTime: 2018-12-02T10:16:04Z + status: "True" + type: Initialized + - lastProbeTime: null + lastTransitionTime: 2018-12-02T10:16:04Z + message: 'containers with unready status: [main]' + reason: ContainersNotReady + status: "False" + type: Ready + - lastProbeTime: null + lastTransitionTime: 2018-12-02T10:16:04Z + status: "True" + type: PodScheduled + containerStatuses: + - image: doesnt-exist + imageID: "" + lastState: {} + name: main + ready: false + restartCount: 0 + state: + waiting: + reason: PodInitializing + hostIP: 192.168.64.41 + phase: Pending + podIP: 172.17.0.9 + qosClass: BestEffort + startTime: 2018-12-02T10:16:04Z