-
Notifications
You must be signed in to change notification settings - Fork 3
/
slack-executor-plugin-configmap.yaml
110 lines (98 loc) · 2.86 KB
/
slack-executor-plugin-configmap.yaml
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
# This is an auto-generated file. DO NOT EDIT
apiVersion: v1
data:
sidecar.container: |
args:
- |
import json
import os
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.request import urlopen, Request
class Plugin(BaseHTTPRequestHandler):
def args(self):
return json.loads(self.rfile.read(int(self.headers.get('Content-Length'))))
def reply(self, reply):
self.send_response(200)
self.end_headers()
self.wfile.write(json.dumps(reply).encode("UTF-8"))
def unsupported(self):
self.send_response(404)
self.end_headers()
def do_POST(self):
if self.path == '/api/v1/template.execute':
args = self.args()
if 'slack' in args['template'].get('plugin', {}):
x = urlopen(
Request(os.getenv('URL'),
data=json.dumps({'text': args['template']['plugin']['slack']['text']}).encode()))
if x.status != 200:
raise Exception("not 200")
self.reply({'node': {'phase': 'Succeeded', 'message': 'Slack message sent'}})
else:
self.reply({})
else:
self.unsupported()
if __name__ == '__main__':
httpd = HTTPServer(('', 7522), Plugin)
httpd.serve_forever()
command:
- python
- -c
env:
- name: URL
valueFrom:
secretKeyRef:
key: URL
name: slack-executor-plugin
image: python:alpine
name: slack-executor-plugin
ports:
- containerPort: 7522
resources:
limits:
cpu: 200m
memory: 64Mi
requests:
cpu: 100m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
kind: ConfigMap
metadata:
annotations:
workflows.argoproj.io/description: |
This plugin sends a Slack message.
You must create a secret:
```yaml
apiVersion: v1
kind: Secret
metadata:
name: slack-executor-plugin
stringData:
URL: https://hooks.slack.com/services/.../.../...
```
Example:
```yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: slack-example-
spec:
entrypoint: main
templates:
- name: main
plugin:
slack:
text: "{{workflow.name}} finished!"
```
workflows.argoproj.io/version: '>= v3.3'
creationTimestamp: null
labels:
workflows.argoproj.io/configmap-type: ExecutorPlugin
name: slack-executor-plugin