feat: add flagger.app/Canary health check lua script and tests (#3902)

* add flagger.app/Canary health check lua script and tests

* add flagger.app/Canary health check lua script and tests, fix type

* add handle for flagger Initialized phase

* add handle for flagger Initialized phase and test
This commit is contained in:
gambuzzi 2020-07-13 21:14:22 +01:00 committed by GitHub
parent 60637e6df2
commit 2a7aabe5a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 225 additions and 0 deletions

View file

@ -0,0 +1,31 @@
sep = " --- "
hs = {}
if obj.status ~= nil then
message = ""
if tonumber(obj.status.canaryWeight) > 0 then
message = "Canary Weight: " .. obj.status.canaryWeight .. " %"
end
for i, condition in ipairs(obj.status.conditions) do
if message ~= "" then
message = message .. sep
end
message = message .. condition.message
end
if obj.status.phase == "Failed" then
hs.status = "Degraded"
elseif ( obj.status.phase == "Progressing" or
obj.status.phase == "Finalising" or
obj.status.phase == "Promoting" ) then
hs.status = "Progressing"
elseif ( obj.status.phase == "Succeeded" or
obj.status.phase == "Initialized" ) then
hs.status = "Healthy"
else
hs.status = "Unknown"
end
hs.message = obj.status.phase .. sep .. message
return hs
end
hs.status = "Unknown"
hs.message = "No status"
return hs

View file

@ -0,0 +1,25 @@
tests:
- healthStatus:
status: Progressing
message: "Progressing --- Canary Weight: 10 % --- New revision detected, progressing canary analysis."
inputPath: testdata/progressing.yaml
- healthStatus:
status: Progressing
message: "Finalising --- Canary analysis completed, routing all traffic to primary."
inputPath: testdata/finalising.yaml
- healthStatus:
status: Progressing
message: "Promoting --- Canary analysis completed, starting primary rolling update."
inputPath: testdata/promoting.yaml
- healthStatus:
status: Degraded
message: "Failed --- Canary analysis failed, Deployment scaled to zero."
inputPath: testdata/degraded.yaml
- healthStatus:
status: Healthy
message: "Succeeded --- Canary analysis completed successfully, promotion finished."
inputPath: testdata/succeeded.yaml
- healthStatus:
status: Healthy
message: "Initialized --- Installation successful."
inputPath: testdata/initialized.yaml

View file

@ -0,0 +1,29 @@
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
generation: 1
labels:
app.kubernetes.io/instance: podinfo
name: podinfo
namespace: default
resourceVersion: "2268395"
selfLink: /apis/flagger.app/v1beta1/namespaces/default/canaries/podinfo
uid: 82df0136-0248-4a95-9c60-3184792614ea
spec: {}
status:
canaryWeight: 0
conditions:
- lastTransitionTime: "2020-07-03T19:13:47Z"
lastUpdateTime: "2020-07-03T19:13:47Z"
message: Canary analysis failed, Deployment scaled to zero.
reason: Failed
status: "False"
type: Promoted
failedChecks: 0
iterations: 0
lastAppliedSpec: 765c47b8f7
lastPromotedSpec: fc74df5fc
lastTransitionTime: "2020-07-03T19:13:47Z"
phase: Failed
trackedConfigs: {}

View file

@ -0,0 +1,28 @@
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
generation: 1
labels:
app.kubernetes.io/instance: podinfo
name: podinfo
namespace: default
resourceVersion: "2268395"
selfLink: /apis/flagger.app/v1beta1/namespaces/default/canaries/podinfo
uid: 82df0136-0248-4a95-9c60-3184792614ea
spec: {}
status:
canaryWeight: 0
conditions:
- lastTransitionTime: "2020-07-03T18:53:02Z"
lastUpdateTime: "2020-07-03T18:55:12Z"
message: Canary analysis completed, routing all traffic to primary.
reason: Finalising
status: Unknown
type: Promoted
failedChecks: 0
iterations: 0
lastAppliedSpec: fc74df5fc
lastPromotedSpec: 744b467645
lastTransitionTime: "2020-07-03T18:55:12Z"
phase: Finalising
trackedConfigs: {}

View file

@ -0,0 +1,28 @@
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
generation: 1
labels:
app.kubernetes.io/instance: podinfo
name: podinfo
namespace: default
resourceVersion: "2268395"
selfLink: /apis/flagger.app/v1beta1/namespaces/default/canaries/podinfo
uid: 82df0136-0248-4a95-9c60-3184792614ea
spec: {}
status:
canaryWeight: 0
conditions:
- lastTransitionTime: "2020-07-03T13:36:22Z"
lastUpdateTime: "2020-07-03T13:36:22Z"
message: Installation successful.
reason: Initialized
status: "True"
type: Promoted
failedChecks: 0
iterations: 0
lastAppliedSpec: 658bbf784f
lastPromotedSpec: 658bbf784f
lastTransitionTime: "2020-07-03T13:36:22Z"
phase: Initialized
trackedConfigs: {}

View file

@ -0,0 +1,28 @@
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
generation: 1
labels:
app.kubernetes.io/instance: podinfo
name: podinfo
namespace: default
resourceVersion: "2268395"
selfLink: /apis/flagger.app/v1beta1/namespaces/default/canaries/podinfo
uid: 82df0136-0248-4a95-9c60-3184792614ea
spec: {}
status:
canaryWeight: 10
conditions:
- lastTransitionTime: "2020-07-03T18:46:52Z"
lastUpdateTime: "2020-07-03T18:46:52Z"
message: New revision detected, progressing canary analysis.
reason: Progressing
status: Unknown
type: Promoted
failedChecks: 0
iterations: 0
lastAppliedSpec: 5c75b466fb
lastPromotedSpec: 658bbf784f
lastTransitionTime: "2020-07-03T18:47:02Z"
phase: Progressing
trackedConfigs: {}

View file

@ -0,0 +1,28 @@
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
generation: 1
labels:
app.kubernetes.io/instance: podinfo
name: podinfo
namespace: default
resourceVersion: "2268395"
selfLink: /apis/flagger.app/v1beta1/namespaces/default/canaries/podinfo
uid: 82df0136-0248-4a95-9c60-3184792614ea
spec: {}
status:
canaryWeight: 0
conditions:
- lastTransitionTime: "2020-07-03T18:53:02Z"
lastUpdateTime: "2020-07-03T18:55:02Z"
message: Canary analysis completed, starting primary rolling update.
reason: Promoting
status: Unknown
type: Promoted
failedChecks: 0
iterations: 0
lastAppliedSpec: fc74df5fc
lastPromotedSpec: 744b467645
lastTransitionTime: "2020-07-03T18:55:02Z"
phase: Promoting
trackedConfigs: {}

View file

@ -0,0 +1,28 @@
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
generation: 1
labels:
app.kubernetes.io/instance: podinfo
name: podinfo
namespace: default
resourceVersion: "2268395"
selfLink: /apis/flagger.app/v1beta1/namespaces/default/canaries/podinfo
uid: 82df0136-0248-4a95-9c60-3184792614ea
spec: {}
status:
canaryWeight: 0
conditions:
- lastTransitionTime: "2020-07-03T13:36:22Z"
lastUpdateTime: "2020-07-03T13:36:22Z"
message: Canary analysis completed successfully, promotion finished.
reason: Succeeded
status: "True"
type: Promoted
failedChecks: 0
iterations: 0
lastAppliedSpec: 658bbf784f
lastPromotedSpec: 658bbf784f
lastTransitionTime: "2020-07-03T13:36:22Z"
phase: Succeeded
trackedConfigs: {}