Skip to content

Commit

Permalink
feat(health): Implement AnsibleJob CRD health checks (argoproj#14483)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Ng <[email protected]>
  • Loading branch information
mikeshng authored and Hariharasuthan99 committed Jun 16, 2024
1 parent d16b51f commit af38f92
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 0 deletions.
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

0 comments on commit af38f92

Please sign in to comment.