This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
app-dep-10-secrets_custom_image_notify.yaml
76 lines (69 loc) · 2.46 KB
/
app-dep-10-secrets_custom_image_notify.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
apiVersion: apps/v1
kind: Deployment
metadata:
name: app10
namespace: default
spec:
replicas: 1
selector:
matchLabels:
com.talend.application: test
com.talend.service: test-app-svc
template:
metadata:
annotations:
sidecar.vault.talend.org/inject: "true"
sidecar.vault.talend.org/notify: "curl localhost:8888/refresh_secrets" # To be notified each time secrets are updated
# NOTE:
# For this sample to work, you cannot use default Vault docker image as curl is not installed.
# You have to set your own custom Vault image with the tools you depend on (here we use 'grem1in/vault-curl-jq' image instead).
sidecar.vault.talend.org/vault-image: "grem1in/vault-curl-jq"
labels:
com.talend.application: test
com.talend.service: test-app-svc
spec:
serviceAccountName: default
containers:
- name: app-container
image: node:14-buster
command:
- "sh"
- "-c"
- |
set -e
cat <<EOF > "/my_custom_api.js"
const http = require("http")
const fs = require('fs')
const PORT = 8888
const server = http.createServer((request, response) => {
const { method, url, headers } = request
if (url === "/refresh_secrets") {
console.log("Notification received: read secrets file to update values")
fs.readFile("/opt/talend/secrets/secrets.properties", "utf8", (error, data) => {
if (error) {
console.error(error)
} else {
console.log(data)
}
})
response.statusCode = 200
response.end()
}
})
server.listen(PORT, error => {
if (error) {
return console.error(error)
}
console.log(\`Server listening on port \${PORT}\`)
})
EOF
while true; do
echo "Wait for secrets file availability..."
if [ -f "/opt/talend/secrets/secrets.properties" ]; then
echo "Secrets are:"
cat /opt/talend/secrets/secrets.properties
break
fi
sleep 2
done
node my_custom_api.js