Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(health): Add custom health check for AnsibleJob resource #14483

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions resource_customizations/tower.ansible.com/AnsibleJob/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
hs = {}
if obj.status ~= nil then
if obj.status.ansibleJobResult ~= nil then
jobstatus = obj.status.ansibleJobResult.status
if jobstatus == "successful" then
hs.status = "Healthy"
hs.message = jobstatus .. " job - " .. obj.status.ansibleJobResult.url
return hs
end
if jobstatus == "failed" or jobstatus == "error" or jobstatus == "canceled" then
hs.status = "Degraded"
hs.message = jobstatus .. " job - " .. obj.status.ansibleJobResult.url
return hs
end
if jobstatus == "new" or jobstatus == "pending" or jobstatus == "waiting" or jobstatus == "running" then
hs.status = "Progressing"
hs.message = jobstatus .. " job - " .. obj.status.ansibleJobResult.url
return hs
end
end
end

hs.status = "Progressing"
hs.message = "Waiting for AnsibleJob"
return hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
tests:
- healthStatus:
status: Progressing
message: Waiting for AnsibleJob
inputPath: testdata/progressing_noStatus.yaml
- healthStatus:
status: Progressing
message: 'new job - https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1'
inputPath: testdata/progressing_new.yaml
- healthStatus:
status: Progressing
message: 'pending job - https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1'
inputPath: testdata/progressing_pending.yaml
- healthStatus:
status: Progressing
message: 'running job - https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1'
inputPath: testdata/progressing_running.yaml
- healthStatus:
status: Progressing
message: 'waiting job - https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1'
inputPath: testdata/progressing_waiting.yaml
- healthStatus:
status: Degraded
message: 'canceled job - https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1'
inputPath: testdata/degraded_canceled.yaml
- healthStatus:
status: Degraded
message: 'error job - https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1'
inputPath: testdata/degraded_error.yaml
- healthStatus:
status: Degraded
message: 'failed job - https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1'
inputPath: testdata/degraded_failed.yaml
- healthStatus:
status: Healthy
message: 'successful job - https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1'
inputPath: testdata/healthy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: tower.ansible.com/v1alpha1
kind: AnsibleJob
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
creationTimestamp: "2023-06-27T20:22:22Z"
generateName: prehook-test-
generation: 1
labels:
app.kubernetes.io/instance: ansible-hooks
tower_job_id: "1"
name: prehook-test-dfcff01-presync-1687897341
namespace: argocd
resourceVersion: "6536518"
uid: 09fa0d39-a170-4c37-a3b0-6e140e029868
spec:
job_template_name: Demo Job Template
tower_auth_secret: toweraccess
status:
ansibleJobResult:
changed: true
elapsed: "5.21"
failed: false
finished: "2023-06-27T20:22:40.116381Z"
started: "2023-06-27T20:22:34.906399Z"
status: canceled
url: https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: tower.ansible.com/v1alpha1
kind: AnsibleJob
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
creationTimestamp: "2023-06-27T20:22:22Z"
generateName: prehook-test-
generation: 1
labels:
app.kubernetes.io/instance: ansible-hooks
tower_job_id: "1"
name: prehook-test-dfcff01-presync-1687897341
namespace: argocd
resourceVersion: "6536518"
uid: 09fa0d39-a170-4c37-a3b0-6e140e029868
spec:
job_template_name: Demo Job Template
tower_auth_secret: toweraccess
status:
ansibleJobResult:
changed: true
elapsed: "5.21"
failed: true
finished: "2023-06-27T20:22:40.116381Z"
started: "2023-06-27T20:22:34.906399Z"
status: error
url: https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: tower.ansible.com/v1alpha1
kind: AnsibleJob
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
creationTimestamp: "2023-06-27T20:22:22Z"
generateName: prehook-test-
generation: 1
labels:
app.kubernetes.io/instance: ansible-hooks
tower_job_id: "1"
name: prehook-test-dfcff01-presync-1687897341
namespace: argocd
resourceVersion: "6536518"
uid: 09fa0d39-a170-4c37-a3b0-6e140e029868
spec:
job_template_name: Demo Job Template
tower_auth_secret: toweraccess
status:
ansibleJobResult:
changed: true
elapsed: "5.21"
failed: true
finished: "2023-06-27T20:22:40.116381Z"
started: "2023-06-27T20:22:34.906399Z"
status: failed
url: https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: tower.ansible.com/v1alpha1
kind: AnsibleJob
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
creationTimestamp: "2023-06-27T20:22:22Z"
generateName: prehook-test-
generation: 1
labels:
app.kubernetes.io/instance: ansible-hooks
tower_job_id: "1"
name: prehook-test-dfcff01-presync-1687897341
namespace: argocd
resourceVersion: "6536518"
uid: 09fa0d39-a170-4c37-a3b0-6e140e029868
spec:
job_template_name: Demo Job Template
tower_auth_secret: toweraccess
status:
ansibleJobResult:
changed: true
elapsed: "5.21"
failed: false
finished: "2023-06-27T20:22:40.116381Z"
started: "2023-06-27T20:22:34.906399Z"
status: successful
url: https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: tower.ansible.com/v1alpha1
kind: AnsibleJob
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
creationTimestamp: "2023-06-27T20:22:22Z"
generateName: prehook-test-
generation: 1
labels:
app.kubernetes.io/instance: ansible-hooks
tower_job_id: "1"
name: prehook-test-dfcff01-presync-1687897341
namespace: argocd
resourceVersion: "6536518"
uid: 09fa0d39-a170-4c37-a3b0-6e140e029868
spec:
job_template_name: Demo Job Template
tower_auth_secret: toweraccess
status:
ansibleJobResult:
changed: true
failed: false
started: "2023-06-27T20:22:34.906399Z"
status: new
url: https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: tower.ansible.com/v1alpha1
kind: AnsibleJob
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
creationTimestamp: "2023-06-27T20:22:22Z"
generateName: prehook-test-
generation: 1
labels:
app.kubernetes.io/instance: ansible-hooks
name: prehook-test-dfcff01-presync-1687897341
namespace: argocd
resourceVersion: "6536518"
uid: 09fa0d39-a170-4c37-a3b0-6e140e029868
spec:
job_template_name: Demo Job Template
tower_auth_secret: toweraccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: tower.ansible.com/v1alpha1
kind: AnsibleJob
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
creationTimestamp: "2023-06-27T20:22:22Z"
generateName: prehook-test-
generation: 1
labels:
app.kubernetes.io/instance: ansible-hooks
tower_job_id: "1"
name: prehook-test-dfcff01-presync-1687897341
namespace: argocd
resourceVersion: "6536518"
uid: 09fa0d39-a170-4c37-a3b0-6e140e029868
spec:
job_template_name: Demo Job Template
tower_auth_secret: toweraccess
status:
ansibleJobResult:
changed: true
failed: false
started: "2023-06-27T20:22:34.906399Z"
status: pending
url: https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: tower.ansible.com/v1alpha1
kind: AnsibleJob
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
creationTimestamp: "2023-06-27T20:22:22Z"
generateName: prehook-test-
generation: 1
labels:
app.kubernetes.io/instance: ansible-hooks
tower_job_id: "1"
name: prehook-test-dfcff01-presync-1687897341
namespace: argocd
resourceVersion: "6536518"
uid: 09fa0d39-a170-4c37-a3b0-6e140e029868
spec:
job_template_name: Demo Job Template
tower_auth_secret: toweraccess
status:
ansibleJobResult:
changed: true
failed: false
started: "2023-06-27T20:22:34.906399Z"
status: running
url: https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: tower.ansible.com/v1alpha1
kind: AnsibleJob
metadata:
annotations:
argocd.argoproj.io/hook: PreSync
creationTimestamp: "2023-06-27T20:22:22Z"
generateName: prehook-test-
generation: 1
labels:
app.kubernetes.io/instance: ansible-hooks
tower_job_id: "1"
name: prehook-test-dfcff01-presync-1687897341
namespace: argocd
resourceVersion: "6536518"
uid: 09fa0d39-a170-4c37-a3b0-6e140e029868
spec:
job_template_name: Demo Job Template
tower_auth_secret: toweraccess
status:
ansibleJobResult:
changed: true
failed: false
started: "2023-06-27T20:22:34.906399Z"
status: waiting
url: https://argocd.test.ansiblejob.custom.health.com/#/jobs/playbook/1