Argo workflowsでは Default Workflow Spec を設定する事でワークフローに色々とパッチできる。
以下のようにexit-handlerをworkflowDefaultsにしておくと、ワークフロー側に何も記述せずとも失敗時にSlackに通知できる。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| apiVersion: v1
kind: ConfigMap
metadata:
name: workflow-controller-configmap
data:
workflowDefaults: |
spec:
onExit: exit-handler
templates:
- name: exit-handler
when: "{{workflow.status}} != Succeeded"
container:
image: curlimages/curl:latest
args: ["-X","POST","-H",'Content-type: application/json',"--data",
'{"attachments": [{"title":"Workflow status: {{workflow.status}}","color": "danger","fields": [{"title": "name", "value": "{{workflow.name}}", "short": true }, {"title": "url", "value": "https://{{inputs.parameters.host}}/archived-workflows/{{workflow.namespace}}/?phase=Failed", "short": false }]}]}',
"{{inputs.parameters.webhook-url}}"]
inputs:
parameters:
- name: webhook-url
value: https://hooks.slack.com/services/xxxx
- name: host
value: my-argo-workflows.example.com
|
もっといい実装ありそう