Skip to content

Commit

Permalink
Add custom resource health through lua
Browse files Browse the repository at this point in the history
  • Loading branch information
dthomson25 committed Jan 31, 2019
1 parent cefa9d9 commit 00421bb
Show file tree
Hide file tree
Showing 18 changed files with 833 additions and 11 deletions.
28 changes: 26 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,8 @@ func (ctrl *ApplicationController) watchSettings(ctx context.Context) {
select {
case newSettings := <-updateCh:
newAppLabelKey := newSettings.GetAppInstanceLabelKey()
*ctrl.settings = *newSettings
if prevAppLabelKey != newAppLabelKey {
ctrl.settings.AppInstanceLabelKey = newAppLabelKey
log.Infof("label key changed: %s -> %s", prevAppLabelKey, newAppLabelKey)
ctrl.stateCache.Invalidate()
prevAppLabelKey = newAppLabelKey
Expand Down
2 changes: 1 addition & 1 deletion controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, revision st
syncStatus.Revision = manifestInfo.Revision
}

healthStatus, err := health.SetApplicationHealth(resourceSummaries, GetLiveObjs(managedResources))
healthStatus, err := health.SetApplicationHealth(resourceSummaries, GetLiveObjs(managedResources), m.settings.ResourceOverrides)
if err != nil {
conditions = append(conditions, appv1.ApplicationCondition{Type: v1alpha1.ApplicationConditionComparisonError, Message: err.Error()})
}
Expand Down
51 changes: 51 additions & 0 deletions resource_customizations/argoproj.io/Rollout/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
hs = {}
if obj.status ~= nil then
if obj.status.conditions ~= nil then
for i, condition in ipairs(obj.status.conditions) do
if condition.type == "InvalidSpec" then
hs.status = "Degraded"
hs.message = condition.message
return hs
end
end
end
if obj.status.currentPodHash ~= nil then
if obj.spec.replicas ~= nil and obj.status.updatedReplicas < obj.spec.replicas then
hs.status = "Progressing"
hs.message = "Waiting for roll out to finish: More replicas need to be updated"
return hs
end
local verifyingPreview = false
if obj.status.verifyingPreview ~= nil then
verifyingPreview = obj.status.verifyingPreview
end
if verifyingPreview and obj.status.previewSelector ~= nil and obj.status.previewSelector == obj.status.currentPodHash then
hs.status = "Healthy"
hs.message = "The preview Service is serving traffic to the current pod spec"
return hs
end

if obj.status.replicas > obj.status.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
hs.status = "Progressing"
hs.message = "Waiting for roll out to finish: updated replicas are still becoming available"
return hs
end

if obj.status.activeSelector ~= nil and obj.status.activeSelector == obj.status.currentPodHash then
hs.status = "Healthy"
hs.message = "The active Service is serving traffic to the current pod spec"
return hs
end
hs.status = "Progressing"
hs.message = "The current pod spec is not receiving traffic from the active service"
return hs
end
end
hs.status = "Unknown"
hs.message = "Rollout should not reach here. Please file a bug at https://github.com/argoproj/argo-cd/issues/new"
return hs
25 changes: 25 additions & 0 deletions resource_customizations/argoproj.io/Rollout/health_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tests:
- healthStatus:
status: Healthy
message: The active Service is serving traffic to the current pod spec
inputPath: testdata/healthy_servingActiveService.yaml
- healthStatus:
status: Healthy
message: The preview Service is serving traffic to the current pod spec
inputPath: testdata/healthy_servingPreviewService.yaml
- healthStatus:
status: Progressing
message: "Waiting for roll out to finish: More replicas need to be updated"
inputPath: testdata/progressing_addingMoreReplicas.yaml
- healthStatus:
status: Progressing
message: "Waiting for roll out to finish: old replicas are pending termination"
inputPath: testdata/progressing_killingOldReplicas.yaml
- healthStatus:
status: Progressing
message: "Waiting for roll out to finish: updated replicas are still becoming available"
inputPath: testdata/progressing_waitingUntilAvailable.yaml
- healthStatus:
status: Degraded
message: Rollout has missing field '.Spec.Strategy.Type'
inputPath: testdata/degraded_invalidSpec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: invalidSpec
status:
conditions:
- type: AnotherValidCondition
status: true
- type: InvalidSpec
status: true
message: Rollout has missing field '.Spec.Strategy.Type'
reason: MissingStrategy
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"argoproj.io/v1alpha1","kind":"Rollout","metadata":{"annotations":{},"labels":{"app.kubernetes.io/instance":"guestbook-default","ksonnet.io/component":"guestbook-ui"},"name":"ks-guestbook-ui","namespace":"default"},"spec":{"minReadySeconds":30,"replicas":1,"selector":{"matchLabels":{"app":"ks-guestbook-ui"}},"strategy":{"blueGreen":{"activeService":"ks-guestbook-ui-active","previewService":"ks-guestbook-ui-preview"},"type":"BlueGreenUpdate"},"template":{"metadata":{"labels":{"app":"ks-guestbook-ui"}},"spec":{"containers":[{"image":"gcr.io/heptio-images/ks-guestbook-demo:0.2","name":"ks-guestbook-ui","ports":[{"containerPort":80}]}]}}}}
rollout.argoproj.io/revision: "1"
clusterName: ""
creationTimestamp: 2019-01-22T16:52:54Z
generation: 1
labels:
app.kubernetes.io/instance: guestbook-default
ksonnet.io/component: guestbook-ui
name: ks-guestbook-ui
namespace: default
resourceVersion: "153353"
selfLink: /apis/argoproj.io/v1alpha1/namespaces/default/rollouts/ks-guestbook-ui
uid: 29802403-1e66-11e9-a6a4-025000000001
spec:
minReadySeconds: 30
replicas: 1
selector:
matchLabels:
app: ks-guestbook-ui
strategy:
blueGreen:
activeService: ks-guestbook-ui-active
previewService: ks-guestbook-ui-preview
type: BlueGreenUpdate
template:
metadata:
creationTimestamp: null
labels:
app: ks-guestbook-ui
spec:
containers:
- image: gcr.io/heptio-images/ks-guestbook-demo:0.2
name: ks-guestbook-ui
ports:
- containerPort: 80
resources: {}
status:
activeSelector: dc689d967
availableReplicas: 1
conditions:
- lastTransitionTime: 2019-01-24T09:51:02Z
lastUpdateTime: 2019-01-24T09:51:02Z
message: Rollout is serving traffic from the active service.
reason: Available
status: "True"
type: Available
currentPodHash: dc689d967
observedGeneration: 77646c9d4c
previewSelector: ""
readyReplicas: 1
replicas: 1
updatedReplicas: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
annotations:
rollout.argoproj.io/revision: "7"
clusterName: ""
creationTimestamp: 2019-01-22T16:52:54Z
generation: 1
labels:
app.kubernetes.io/instance: guestbook-default
name: ks-guestbook-ui
namespace: default
resourceVersion: "164113"
selfLink: /apis/argoproj.io/v1alpha1/namespaces/default/rollouts/ks-guestbook-ui
uid: 29802403-1e66-11e9-a6a4-025000000001
spec:
minReadySeconds: 30
replicas: 3
selector:
matchLabels:
app: ks-guestbook-ui
strategy:
blueGreen:
activeService: ks-guestbook-ui-active
previewService: ks-guestbook-ui-preview
type: BlueGreenUpdate
template:
metadata:
creationTimestamp: null
labels:
app: ks-guestbook-ui
spec:
containers:
- image: gcr.io/heptio-images/ks-guestbook-demo:0.1
name: ks-guestbook-ui
ports:
- containerPort: 83
resources: {}
status:
activeSelector: 85f9884f5d
availableReplicas: 6
conditions:
- lastTransitionTime: 2019-01-25T07:44:26Z
lastUpdateTime: 2019-01-25T07:44:26Z
message: Rollout is serving traffic from the active service.
reason: Available
status: "True"
type: Available
currentPodHash: 697fb9575c
observedGeneration: 767f98959f
previewSelector: 697fb9575c
readyReplicas: 6
replicas: 6
updatedReplicas: 3
verifyingPreview: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
annotations:
rollout.argoproj.io/revision: "7"
clusterName: ""
creationTimestamp: 2019-01-22T16:52:54Z
generation: 1
labels:
app.kubernetes.io/instance: guestbook-default
name: ks-guestbook-ui
namespace: default
resourceVersion: "164023"
selfLink: /apis/argoproj.io/v1alpha1/namespaces/default/rollouts/ks-guestbook-ui
uid: 29802403-1e66-11e9-a6a4-025000000001
spec:
minReadySeconds: 30
replicas: 3
selector:
matchLabels:
app: ks-guestbook-ui
strategy:
blueGreen:
activeService: ks-guestbook-ui-active
previewService: ks-guestbook-ui-preview
type: BlueGreenUpdate
template:
metadata:
creationTimestamp: null
labels:
app: ks-guestbook-ui
spec:
containers:
- image: gcr.io/heptio-images/ks-guestbook-demo:0.1
name: ks-guestbook-ui
ports:
- containerPort: 83
resources: {}
status:
activeSelector: 85f9884f5d
availableReplicas: 3
conditions:
- lastTransitionTime: 2019-01-25T07:44:26Z
lastUpdateTime: 2019-01-25T07:44:26Z
message: Rollout is serving traffic from the active service.
reason: Available
status: "True"
type: Available
currentPodHash: 697fb9575c
observedGeneration: 767f98959f
previewSelector: ""
readyReplicas: 3
replicas: 3
updatedReplicas: 0
Loading

0 comments on commit 00421bb

Please sign in to comment.