-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargocd-notifications-cm.yml
136 lines (130 loc) · 5.74 KB
/
argocd-notifications-cm.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
namespace: argocd
data:
context: |
argocdUrl: https://argocd.simulatan.me
# default subscriptions
subscriptions: |
- recipients:
- discord-webhook
- github
# only apply to k8s-ops projects, others have different services
selector: argocd.argoproj.io/instance=k8s-ops
triggers:
- sync-operation-change
service.github: |
appID: "652832"
installationID: "44413271"
privateKey: $github-privateKey
service.github.contestsubmission: |
appID: "652832"
installationID: "47219356"
privateKey: $github-privateKey
service.webhook.discord-webhook: |
url: https://discord.com/api/webhooks/$discord-webhook-id/$discord-webhook-token
headers:
- name: Content-Type
value: application/json
trigger.sync-operation-change: |
- when: app.status.sync.status in ['OutOfSync']
oncePer: app.status.operationState.syncResult.revision
send: [app-deployment-update]
- when: app.status.operationState.phase in ['Succeeded']
oncePer: app.status.operationState.syncResult.revision
send: [app-deployment-update]
- when: app.status.operationState.phase in ['Running']
oncePer: app.status.operationState.syncResult.revision
send: [app-deployment-update]
- when: app.status.operationState.phase in ['Error', 'Failed']
oncePer: app.status.operationState.syncResult.revision
send: [app-deployment-update]
template.app-deployment-update: |
webhook:
discord-webhook:
method: POST
body: |
{
"avatar_url": "{{.context.argocdUrl}}/assets/images/logo.png",
"embeds": [{
"title": "{{.app.status.sync.status}}: {{.app.metadata.name}}",
"url": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
"color": {{ if or (eq .app.status.operationState.phase "Running") (eq .app.status.sync.status "OutOfSync") }} 896490 {{ else if eq .app.status.operationState.phase "Succeeded" }} 1621586 {{ else if has .app.status.operationState.phase (list "Error" "Failed") }} 16039984 {{ end }},
"fields": [{
"name": "Operation State",
"value": "{{.app.status.operationState.phase}}",
"inline": true
},
{
"name": "Sync State",
"value": "{{.app.status.sync.status}}",
"inline": true
},
{
"name": "",
"value": "",
"inline": true
},
{{if .app.spec.source.repoURL}}
{
"name": "Source",
"value": "[{{call .strings.ReplaceAll .app.spec.source.repoURL "https://" ""}}/{{.app.spec.source.path}}]({{.app.spec.source.repoURL}}/tree/{{.app.status.sync.revision}}/{{.app.spec.source.path}})",
"inline": true
},
{{end}}
{
"name": "",
"value": "",
"inline": false
},
{
"name": "Commit SHA",
"value": "[{{.app.status.sync.revision | trunc 7}}]({{.app.spec.source.repoURL}}/commit/{{.app.status.sync.revision}})",
"inline": true
},
{
"name": "Commit Author",
"value": "{{(call .repo.GetCommitMetadata .app.status.sync.revision).Author}}",
"inline": true
},
{
"name": "Commit Date",
"value": "{{(call .repo.GetCommitMetadata .app.status.sync.revision).Date}}",
"inline": true
},
{
"name": "Commit Message",
"value": "{{(call .repo.GetCommitMetadata .app.status.sync.revision).Message}}",
"inline": false
}]
}]
}
github:
repoURLPath: "{{.app.spec.source.repoURL}}"
revisionPath: "{{.app.status.operationState.syncResult.revision}}"
status:
state: '{{ if eq .app.status.operationState.phase "Running" }}in_progress{{ else if or (eq .app.status.operationState.phase "Error") (eq .app.status.operationState.phase "Failed") }}failure{{ else if eq .app.status.sync.status "OutOfSync" }}pending{{ else if eq .app.status.operationState.phase "Succeeded" }}success{{ end }}'
label: "cd/{{.app.metadata.name}}"
targetURL: "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true"
deployment:
state: '{{ if eq .app.status.operationState.phase "Running" }}in_progress{{ else if or (eq .app.status.operationState.phase "Error") (eq .app.status.operationState.phase "Failed") }}failure{{ else if eq .app.status.sync.status "OutOfSync" }}pending{{ else if eq .app.status.operationState.phase "Succeeded" }}success{{ end }}'
environment: "{{.app.metadata.name}}"
environmentURL: "https://{{.app.metadata.name}}.simulatan.me"
logURL: "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true"
requiredContexts: []
pullRequestComment:
content: |
{{- if eq .app.status.operationState.phase "Succeeded" -}}
Application `{{.app.metadata.name}}` is now running the new manifests.
{{- else -}}
Application `{{.app.metadata.name}}` failed to deploy.
{{- end }}
See more here: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true
message: |
{{- if eq .app.status.operationState.phase "Succeeded" -}}
Application {{.app.metadata.name}} was deployed.
{{- else -}}
Application {{.app.metadata.name}} failed to deploy.
{{- end -}}