Skip to content

Commit

Permalink
Account for missing fields in Rollout HealthStatus (argoproj#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
dthomson25 authored Jun 7, 2019
1 parent 4860f2c commit 03b7d24
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 7 deletions.
26 changes: 19 additions & 7 deletions resource_customizations/argoproj.io/Rollout/health.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
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
end
return nil
end

function getNumberValueOrDefault(field)
if field ~= nil then
return field
end
return 0
end

function checkPaused(obj)
hs = {}
local paused = false
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions resource_customizations/argoproj.io/Rollout/health_test.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 03b7d24

Please sign in to comment.