From 5ce2e717e0e53492a003447dc2478dad452d2518 Mon Sep 17 00:00:00 2001 From: Danny Thomson Date: Wed, 5 Jun 2019 14:47:34 -0700 Subject: [PATCH] Account for missing fields in Rollout HealthStatus --- .../argoproj.io/Rollout/health.lua | 26 +++++-- .../argoproj.io/Rollout/health_test.yaml | 4 + .../testdata/newRolloutWithoutStatus.yaml | 74 +++++++++++++++++++ 3 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 resource_customizations/argoproj.io/Rollout/testdata/newRolloutWithoutStatus.yaml diff --git a/resource_customizations/argoproj.io/Rollout/health.lua b/resource_customizations/argoproj.io/Rollout/health.lua index 7cec631fa3059..cb1fb560ddf7d 100644 --- a/resource_customizations/argoproj.io/Rollout/health.lua +++ b/resource_customizations/argoproj.io/Rollout/health.lua @@ -1,31 +1,36 @@ function checkReplicasStatus(obj) hs = {} - if obj.spec.replicas ~= nil and obj.status.updatedReplicas < obj.spec.replicas then + replicasCount = getNumberValueOrDefault(obj.spec.replicas) + replicasStatus = getNumberValueOrDefault(obj.status.replicas) + updatedReplicas = getNumberValueOrDefault(obj.status.updatedReplicas) + availableReplicas = getNumberValueOrDefault(obj.status.availableReplicas) + + if updatedReplicas < replicasCount then hs.status = "Progressing" hs.message = "Waiting for roll out to finish: More replicas need to be updated" return hs end - if obj.status.replicas > obj.status.updatedReplicas then + if replicasStatus > updatedReplicas then hs.status = "Progressing" hs.message = "Waiting for roll out to finish: old replicas are pending termination" return hs end - if obj.status.availableReplicas < obj.status.updatedReplicas then + if availableReplicas < updatedReplicas then hs.status = "Progressing" hs.message = "Waiting for roll out to finish: updated replicas are still becoming available" return hs end - if obj.spec.replicas ~= nil and obj.status.updatedReplicas < obj.spec.replicas then + if updatedReplicas < replicasCount then hs.status = "Progressing" hs.message = "Waiting for roll out to finish: More replicas need to be updated" return hs end - if obj.status.replicas > obj.status.updatedReplicas then + if replicasStatus > updatedReplicas then hs.status = "Progressing" hs.message = "Waiting for roll out to finish: old replicas are pending termination" return hs end - if obj.status.availableReplicas < obj.status.updatedReplicas then + if availableReplicas < updatedReplicas then hs.status = "Progressing" hs.message = "Waiting for roll out to finish: updated replicas are still becoming available" return hs @@ -33,6 +38,13 @@ function checkReplicasStatus(obj) return nil end +function getNumberValueOrDefault(field) + if field ~= nil then + return field + end + return 0 +end + function checkPaused(obj) hs = {} local paused = false @@ -76,7 +88,7 @@ if obj.status ~= nil then if replicasHS ~= nil then return replicasHS end - if obj.status.blueGreen.activeSelector ~= nil and obj.status.blueGreen.activeSelector == obj.status.currentPodHash then + if obj.status.blueGreen ~= nil and obj.status.blueGreen.activeSelector ~= nil and obj.status.currentPodHash ~= nil and obj.status.blueGreen.activeSelector == obj.status.currentPodHash then hs.status = "Healthy" hs.message = "The active Service is serving traffic to the current pod spec" return hs diff --git a/resource_customizations/argoproj.io/Rollout/health_test.yaml b/resource_customizations/argoproj.io/Rollout/health_test.yaml index a36004c49266a..957b67e34849a 100644 --- a/resource_customizations/argoproj.io/Rollout/health_test.yaml +++ b/resource_customizations/argoproj.io/Rollout/health_test.yaml @@ -1,4 +1,8 @@ tests: +- healthStatus: + status: Progressing + message: "Waiting for roll out to finish: More replicas need to be updated" + inputPath: testdata/newRolloutWithoutStatus.yaml - healthStatus: status: Degraded message: Rollout has missing field '.Spec.Strategy.Type' diff --git a/resource_customizations/argoproj.io/Rollout/testdata/newRolloutWithoutStatus.yaml b/resource_customizations/argoproj.io/Rollout/testdata/newRolloutWithoutStatus.yaml new file mode 100644 index 0000000000000..417b924d10252 --- /dev/null +++ b/resource_customizations/argoproj.io/Rollout/testdata/newRolloutWithoutStatus.yaml @@ -0,0 +1,74 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"argoproj.io/v1alpha1","kind":"Rollout","metadata":{"annotations":{},"labels":{"app":"helm-guestbook","app.kubernetes.io/instance":"bluegreen","chart":"helm-guestbook-0.1.0","heritage":"Tiller","release":"bluegreen"},"name":"bluegreen-helm-guestbook","namespace":"default"},"spec":{"replicas":1,"revisionHistoryLimit":3,"selector":{"matchLabels":{"app":"helm-guestbook","release":"bluegreen"}},"strategy":{"blueGreen":{"activeService":"bluegreen-helm-guestbook","previewService":"bluegreen-helm-guestbook-preview"}},"template":{"metadata":{"labels":{"app":"helm-guestbook","release":"bluegreen"}},"spec":{"containers":[{"image":"gcr.io/heptio-images/ks-guestbook-demo:0.1","imagePullPolicy":"IfNotPresent","livenessProbe":{"httpGet":{"path":"/","port":"http"}},"name":"helm-guestbook","ports":[{"containerPort":80,"name":"http","protocol":"TCP"}],"readinessProbe":{"httpGet":{"path":"/","port":"http"}},"resources":{}}]}}}} + rollout.argoproj.io/revision: "1" + creationTimestamp: 2019-06-05T21:26:38Z + generation: 1 + labels: + app: helm-guestbook + app.kubernetes.io/instance: bluegreen + chart: helm-guestbook-0.1.0 + heritage: Tiller + release: bluegreen + name: bluegreen-helm-guestbook + namespace: default + resourceVersion: "150297" + selfLink: /apis/argoproj.io/v1alpha1/namespaces/default/rollouts/bluegreen-helm-guestbook + uid: 9a560c89-87d8-11e9-a97d-080027da2583 +spec: + replicas: 1 + revisionHistoryLimit: 3 + selector: + matchLabels: + app: helm-guestbook + release: bluegreen + strategy: + blueGreen: + activeService: bluegreen-helm-guestbook + previewService: bluegreen-helm-guestbook-preview + template: + metadata: + creationTimestamp: null + labels: + app: helm-guestbook + release: bluegreen + spec: + containers: + - image: gcr.io/heptio-images/ks-guestbook-demo:0.1 + imagePullPolicy: IfNotPresent + livenessProbe: + httpGet: + path: / + port: http + name: helm-guestbook + ports: + - containerPort: 80 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: / + port: http + resources: {} +status: + blueGreen: {} + canary: {} + conditions: + - lastTransitionTime: 2019-06-05T21:26:38Z + lastUpdateTime: 2019-06-05T21:26:38Z + message: Created new replica set "bluegreen-helm-guestbook-7c4599cc5b" + reason: NewReplicaSetCreated + status: "True" + type: Progressing + - lastTransitionTime: 2019-06-05T21:26:38Z + lastUpdateTime: 2019-06-05T21:26:38Z + message: Rollout does not have minimum availability + reason: AvailableReason + status: "False" + type: Available + currentPodHash: 7c4599cc5b + observedGeneration: 78597c98fd + selector: app=helm-guestbook,release=bluegreen \ No newline at end of file