-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-04.yml
158 lines (158 loc) · 3.79 KB
/
example-04.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
apiVersion: v1
kind: Namespace
metadata:
name: example-04
---
apiVersion: k8s.consol.de/v1beta1
kind: NamespaceManager
metadata:
name: example-04
namespace: example-04
spec:
policies:
- name: call webhook when specific pods succeed
condition:
type: PODS_SUCCEED
params:
podLabels:
component: main
initialDelaySeconds: 60
periodSeconds: 10
action:
type: WEBHOOK
params:
url: http://webhooky.example-04.svc.cluster.local/api/webhook/my-super-awesome-webhook
---
apiVersion: v1
kind: ConfigMap
metadata:
name: helper-scripts
namespace: example-04
data:
simulate-long-running-test.sh: |-
#!/usr/bin/env sh
set -e
echo simulating long running test
COUNTER=0
while [ ${COUNTER} -lt ${MOCK_TEST_ITERATIONS:-10} ]; do
COUNTER=`expr ${COUNTER} + 1`
sleep ${MOCK_TEST_SLEEP_SECONDS:-3}
echo finished iteration ${COUNTER}
done
if [ ! -z "${MOCK_TEST_SIMULATE_FAILURE}" ]; then
echo simulating failure
exit 1
fi
echo success
node-server: |-
#!/usr/bin/env node
const http = require("http");
const server = http.createServer((req, res) => {
console.log(`received request at ${new Date().toISOString()}`);
console.log(`${req.method} ${req.url}`);
console.log(`headers:\n${JSON.stringify(req.headers || {}, null, 2)}`);
const chunks = [];
req
.on("data", (chunk) => {
chunks.push(chunk);
})
.on("end", () => {
const body = Buffer.concat(chunks).toString();
console.log(`body:\n${body}`);
res.writeHead(200);
res.end("OK");
console.log("response has been sent");
})
.on("error", (err) => {
console.log(`got error: ${err}`);
res.writeHead(500);
res.end("FAILED :(");
console.log("error response has been sent");
});
});
const port = process.env.PORT || 80;
server.listen(port);
console.log(`server is listening on port ${port}`);
---
apiVersion: batch/v1
kind: Job
metadata:
name: my-toothsome-spicy-spiritual-app
namespace: example-04
spec:
completions: 1
parallelism: 1
backoffLimit: 0
template:
metadata:
labels:
app: test-app-04
component: main
spec:
restartPolicy: Never
containers:
- name: main
image: alpine
### uncomment to test
### that operator
### will not call the webhook
# env:
# - name: MOCK_TEST_SIMULATE_FAILURE
# value: "yes"
command:
- "/opt/helper-scripts/simulate-long-running-test.sh"
volumeMounts:
- mountPath: /opt/helper-scripts
name: helper-scripts
volumes:
- name: helper-scripts
configMap:
name: helper-scripts
defaultMode: 0555
---
apiVersion: v1
kind: Service
metadata:
name: webhooky
namespace: example-04
spec:
ports:
- port: 80
name: web
selector:
app: test-app-04
component: webhook
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: webhooky
namespace: example-04
spec:
replicas: 1
selector:
matchLabels:
app: test-app-04
component: webhook
template:
metadata:
labels:
app: test-app-04
component: webhook
spec:
containers:
- name: main
image: node:14.3.0-alpine3.11
ports:
- containerPort: 80
command:
- "/opt/helper-scripts/node-server"
volumeMounts:
- mountPath: /opt/helper-scripts
name: helper-scripts
volumes:
- name: helper-scripts
configMap:
name: helper-scripts
defaultMode: 0555