Skip to content

Commit e1c577d

Browse files
committed
add webapp sidecar for token bootstrap
1 parent 474bb50 commit e1c577d

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

hosting/k8s/helm/templates/supervisor.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ spec:
7474
{{- with .Values.supervisor.podSecurityContext }}
7575
{{- toYaml . | nindent 8 }}
7676
{{- end }}
77+
{{- if not .Values.webapp.bootstrap.enabled }}
7778
initContainers:
7879
- name: init-shared
7980
image: busybox:1.35
@@ -83,6 +84,7 @@ spec:
8384
volumeMounts:
8485
- name: shared
8586
mountPath: /home/node/shared
87+
{{- end }}
8688
containers:
8789
- name: supervisor
8890
image: {{ include "trigger-v4.supervisor.image" . }}
@@ -134,8 +136,11 @@ spec:
134136
- name: TRIGGER_API_URL
135137
value: "http://{{ include "trigger-v4.fullname" . }}-webapp:{{ .Values.webapp.service.port }}"
136138
- name: TRIGGER_WORKER_TOKEN
137-
{{- if .Values.supervisor.bootstrap.enabled }}
138-
value: "file://{{ .Values.supervisor.bootstrap.workerTokenPath }}"
139+
{{- if .Values.webapp.bootstrap.enabled }}
140+
valueFrom:
141+
secretKeyRef:
142+
name: {{ include "trigger-v4.fullname" . }}-worker-token
143+
key: token
139144
{{- else if .Values.supervisor.bootstrap.workerToken.secret.name }}
140145
valueFrom:
141146
secretKeyRef:
@@ -234,13 +239,16 @@ spec:
234239
{{- with .Values.supervisor.extraEnvVars }}
235240
{{- toYaml . | nindent 12 }}
236241
{{- end }}
242+
{{- if not .Values.webapp.bootstrap.enabled }}
237243
volumeMounts:
238244
- name: shared
239245
mountPath: /home/node/shared
246+
{{- end }}
240247
{{- with .Values.supervisor.securityContext }}
241248
securityContext:
242249
{{- toYaml . | nindent 12 }}
243250
{{- end }}
251+
{{- if not .Values.webapp.bootstrap.enabled }}
244252
volumes:
245253
- name: shared
246254
{{- if .Values.persistence.shared.enabled }}
@@ -249,6 +257,7 @@ spec:
249257
{{- else }}
250258
emptyDir: {}
251259
{{- end }}
260+
{{- end }}
252261
{{- with .Values.supervisor.nodeSelector }}
253262
nodeSelector:
254263
{{- toYaml . | nindent 8 }}

hosting/k8s/helm/templates/webapp.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: {{ include "trigger-v4.fullname" . }}-webapp
5+
labels:
6+
{{- $component := "webapp" }}
7+
{{- include "trigger-v4.componentLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "component" $component) | nindent 4 }}
8+
---
9+
apiVersion: rbac.authorization.k8s.io/v1
10+
kind: Role
11+
metadata:
12+
name: {{ include "trigger-v4.fullname" . }}-webapp-token-syncer
13+
labels:
14+
{{- $component := "webapp" }}
15+
{{- include "trigger-v4.componentLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "component" $component) | nindent 4 }}
16+
rules:
17+
- apiGroups: [""]
18+
resources: ["secrets"]
19+
verbs: ["create", "get", "update", "patch"]
20+
---
21+
apiVersion: rbac.authorization.k8s.io/v1
22+
kind: RoleBinding
23+
metadata:
24+
name: {{ include "trigger-v4.fullname" . }}-webapp-token-syncer
25+
labels:
26+
{{- $component := "webapp" }}
27+
{{- include "trigger-v4.componentLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "component" $component) | nindent 4 }}
28+
subjects:
29+
- kind: ServiceAccount
30+
name: {{ include "trigger-v4.fullname" . }}-webapp
31+
namespace: {{ .Release.Namespace }}
32+
roleRef:
33+
kind: Role
34+
name: {{ include "trigger-v4.fullname" . }}-webapp-token-syncer
35+
apiGroup: rbac.authorization.k8s.io
36+
---
137
apiVersion: apps/v1
238
kind: Deployment
339
metadata:
@@ -19,6 +55,7 @@ spec:
1955
labels:
2056
{{- include "trigger-v4.componentSelectorLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "component" $component) | nindent 8 }}
2157
spec:
58+
serviceAccountName: {{ include "trigger-v4.fullname" . }}-webapp
2259
{{- with .Values.global.imagePullSecrets }}
2360
imagePullSecrets:
2461
{{- toYaml . | nindent 8 }}
@@ -38,6 +75,55 @@ spec:
3875
- name: shared
3976
mountPath: /home/node/shared
4077
containers:
78+
- name: token-syncer
79+
image: bitnami/kubectl:1.28
80+
securityContext:
81+
runAsUser: 1000
82+
runAsNonRoot: true
83+
command:
84+
- /bin/bash
85+
- -c
86+
- |
87+
TOKEN_FILE="/home/node/shared/worker_token"
88+
SECRET_NAME="{{ include "trigger-v4.fullname" . }}-worker-token"
89+
NAMESPACE="{{ .Release.Namespace }}"
90+
91+
echo "Token syncer starting..."
92+
echo "Monitoring: $TOKEN_FILE"
93+
echo "Target secret: $SECRET_NAME"
94+
95+
while true; do
96+
if [ -f "$TOKEN_FILE" ]; then
97+
TOKEN=$(cat "$TOKEN_FILE")
98+
if [ ! -z "$TOKEN" ]; then
99+
echo "Token file found, creating/updating secret..."
100+
101+
# Create or update the secret
102+
kubectl create secret generic "$SECRET_NAME" \
103+
--from-literal=token="$TOKEN" \
104+
--namespace="$NAMESPACE" \
105+
--dry-run=client -o yaml | kubectl apply -f -
106+
107+
if [ $? -eq 0 ]; then
108+
echo "Secret successfully created/updated"
109+
# Continue monitoring for updates
110+
sleep 30
111+
else
112+
echo "Failed to create/update secret, retrying in 5s..."
113+
sleep 5
114+
fi
115+
else
116+
echo "Token file exists but is empty, waiting..."
117+
sleep 2
118+
fi
119+
else
120+
echo "Waiting for token file..."
121+
sleep 2
122+
fi
123+
done
124+
volumeMounts:
125+
- name: shared
126+
mountPath: /home/node/shared
41127
- name: webapp
42128
securityContext:
43129
{{- toYaml .Values.webapp.securityContext | nindent 12 }}

0 commit comments

Comments
 (0)