20
20
echo " Running with the following params: ${REG_DAEMON_PORT} ${WS_DAEMON_PORT} ${NODE_POOL_INDEX} ${DEV_BRANCH} "
21
21
fi
22
22
23
+ echo " Use node pool index $NODE_POOL_INDEX "
24
+
23
25
# Optional params
24
26
# default yes, we add a license
25
27
LICENSE=$( cat /tmp/license)
26
28
# default, no, we do not add feature flags, file is empty
27
29
DEFAULT_FEATURE_FLAGS=$( cat /tmp/defaultFeatureFlags)
28
30
29
- i=0
31
+
30
32
31
33
# count YAML like lines in the k8s manifest file
32
34
MATCHES=" $( grep -c -- --- k8s.yaml) "
33
35
# get the read number of K8s manifest docs
34
36
# K8s object names and kinds are duplicated in a config map to faciliate deletion
35
37
# subtract one (the config map) and then divide by 2 to get the actual # of docs we'll loop through
36
38
DOCS=" $(( ((MATCHES - 1 ) / 2 ) + 1 )) "
39
+ documentIndex=0
37
40
38
- echo " Use node pool index $NODE_POOL_INDEX "
39
-
40
- while [ " $i " -le " $DOCS " ]; do
41
+ while [ " $documentIndex " -le " $DOCS " ]; do
41
42
# override daemon sets which bind to an actual node port via the hostPort setting on the pod
42
43
unset PORT SIZE NAME UNSET
43
- PORT=$( yq r k8s.yaml -d " $i " spec.template.spec.containers.[0].ports.[0].hostPort)
44
+ PORT=$( yq r k8s.yaml -d " $documentIndex " spec.template.spec.containers.[0].ports.[0].hostPort)
44
45
SIZE=" ${# PORT} "
45
- NAME=$( yq r k8s.yaml -d " $i " metadata.name)
46
- KIND=$( yq r k8s.yaml -d " $i " kind)
46
+ NAME=$( yq r k8s.yaml -d " $documentIndex " metadata.name)
47
+ KIND=$( yq r k8s.yaml -d " $documentIndex " kind)
47
48
if [[ " $SIZE " -ne " 0" ]] && [[ " $NAME " == " registry-facade" ]] && [[ " $KIND " == " DaemonSet" ]] ; then
48
49
echo " setting $NAME to $REG_DAEMON_PORT "
49
- yq w -i k8s.yaml -d " $i " spec.template.spec.containers.[0].ports.[0].hostPort " $REG_DAEMON_PORT "
50
+ yq w -i k8s.yaml -d " $documentIndex " spec.template.spec.containers.[0].ports.[0].hostPort " $REG_DAEMON_PORT "
50
51
fi
51
52
if [[ " $SIZE " -ne " 0" ]] && [[ " $NAME " == " ws-daemon" ]] && [[ " $KIND " == " DaemonSet" ]] ; then
52
53
echo " setting $NAME to $WS_DAEMON_PORT "
53
- yq w -i k8s.yaml -d " $i " spec.template.spec.containers.[0].ports.[0].hostPort " $WS_DAEMON_PORT "
54
- yq w -i k8s.yaml -d " $i " spec.template.spec.containers.[0].ports.[0].containerPort " $WS_DAEMON_PORT "
54
+ yq w -i k8s.yaml -d " $documentIndex " spec.template.spec.containers.[0].ports.[0].hostPort " $WS_DAEMON_PORT "
55
+ yq w -i k8s.yaml -d " $documentIndex " spec.template.spec.containers.[0].ports.[0].containerPort " $WS_DAEMON_PORT "
55
56
fi
56
57
57
58
# override details for registry-facade service
58
59
if [[ " registry-facade" == " $NAME " ]] && [[ " $KIND " == " Service" ]]; then
59
60
WORK=" overrides for $NAME $KIND "
60
61
echo " $WORK "
61
- yq w -i k8s.yaml -d " $i " spec.ports[0].port " $REG_DAEMON_PORT "
62
+ yq w -i k8s.yaml -d " $documentIndex " spec.ports[0].port " $REG_DAEMON_PORT "
62
63
fi
63
64
64
65
# override labels for pod scheduling on nodes
@@ -72,7 +73,7 @@ while [ "$i" -le "$DOCS" ]; do
72
73
yq w -i /tmp/" $NAME " pool.yaml spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].key " $LABEL "
73
74
yq w -i /tmp/" $NAME " pool.yaml spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].operator Exists
74
75
# append it
75
- yq m --arrays=overwrite -i k8s.yaml -d " $i " /tmp/" $NAME " pool.yaml
76
+ yq m --arrays=overwrite -i k8s.yaml -d " $documentIndex " /tmp/" $NAME " pool.yaml
76
77
elif [[ " $KIND " == " DaemonSet" ]] || [[ " $KIND " == " Deployment" ]] || [[ " $KIND " == " StatefulSet" ]] || [[ " $KIND " == " Job" ]]; then
77
78
LABEL=" gitpod.io/workload_meta"
78
79
echo " setting $LABEL for $NAME "
@@ -81,15 +82,15 @@ while [ "$i" -le "$DOCS" ]; do
81
82
yq w -i /tmp/" $NAME " pool.yaml spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].key " $LABEL "
82
83
yq w -i /tmp/" $NAME " pool.yaml spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].operator Exists
83
84
# append it
84
- yq m --arrays=overwrite -i k8s.yaml -d " $i " /tmp/" $NAME " pool.yaml
85
+ yq m --arrays=overwrite -i k8s.yaml -d " $documentIndex " /tmp/" $NAME " pool.yaml
85
86
fi
86
87
87
88
# overrides for server-config
88
89
if [[ " server-config" == " $NAME " ]] && [[ " $KIND " == " ConfigMap" ]]; then
89
90
WORK=" overrides for $NAME $KIND "
90
91
echo " $WORK "
91
92
touch /tmp/" $NAME " overrides.yaml
92
- yq r k8s.yaml -d " $i " data | yq prefix - data > /tmp/" $NAME " overrides.yaml
93
+ yq r k8s.yaml -d " $documentIndex " data | yq prefix - data > /tmp/" $NAME " overrides.yaml
93
94
94
95
THEIA_BUCKET_NAME=$( yq r ./.werft/jobs/build/helm/values.dev.yaml components.server.theiaPluginsBucketNameOverride)
95
96
THEIA_BUCKET_NAME_EXPR=" s/\" theiaPluginsBucketNameOverride\" : \"\" /\" theiaPluginsBucketNameOverride\" : \" $THEIA_BUCKET_NAME \" /"
@@ -129,36 +130,36 @@ while [ "$i" -le "$DOCS" ]; do
129
130
fi
130
131
131
132
# Merge the changes
132
- yq m -x -i k8s.yaml -d " $i " /tmp/" $NAME " overrides.yaml
133
+ yq m -x -i k8s.yaml -d " $documentIndex " /tmp/" $NAME " overrides.yaml
133
134
fi
134
135
135
136
# overrides for ws-manager-bridge configmap
136
137
if [[ " ws-manager-bridge-config" == " $NAME " ]] && [[ " $KIND " == " ConfigMap" ]]; then
137
138
WORK=" overrides for $NAME $KIND "
138
139
echo " $WORK "
139
140
touch /tmp/" $NAME " overrides.yaml
140
- yq r k8s.yaml -d " $i " data | yq prefix - data > /tmp/" $NAME " overrides.yaml
141
+ yq r k8s.yaml -d " $documentIndex " data | yq prefix - data > /tmp/" $NAME " overrides.yaml
141
142
142
143
# simliar to server, except the ConfigMap hierarchy, key, and value are different
143
144
SHORT_NAME=$( yq r ./.werft/jobs/build/helm/values.dev.yaml installation.shortname)
144
145
INSTALL_SHORT_NAME_EXPR=" s/\" installation\" : \"\" /\" installation\" : \" $SHORT_NAME \" /"
145
146
sed -i " $INSTALL_SHORT_NAME_EXPR " /tmp/" $NAME " overrides.yaml
146
- yq m -x -i k8s.yaml -d " $i " /tmp/" $NAME " overrides.yaml
147
+ yq m -x -i k8s.yaml -d " $documentIndex " /tmp/" $NAME " overrides.yaml
147
148
fi
148
149
149
150
# override details for Minio
150
151
if [[ " minio" == " $NAME " ]] && [[ " $KIND " == " Deployment" ]]; then
151
152
WORK=" overrides for $NAME $KIND "
152
153
echo " $WORK "
153
- yq -d " $i " w -i k8s.yaml spec.template.spec.serviceAccountName ws-daemon
154
+ yq -d " $documentIndex " w -i k8s.yaml spec.template.spec.serviceAccountName ws-daemon
154
155
fi
155
156
156
157
# overrides for ws-manager
157
158
if [[ " ws-manager" == " $NAME " ]] && [[ " $KIND " == " ConfigMap" ]]; then
158
159
WORK=" overrides for $NAME $KIND "
159
160
echo " $WORK "
160
161
touch /tmp/" $NAME " overrides.yaml
161
- yq r k8s.yaml -d " $i " data | yq prefix - data > /tmp/" $NAME " overrides.yaml
162
+ yq r k8s.yaml -d " $documentIndex " data | yq prefix - data > /tmp/" $NAME " overrides.yaml
162
163
163
164
SHORT_NAME=$( yq r ./.werft/jobs/build/helm/values.dev.yaml installation.shortname)
164
165
STAGING_HOST_NAME=$( yq r ./.werft/jobs/build/helm/values.dev.yaml hostname)
@@ -192,15 +193,15 @@ while [ "$i" -le "$DOCS" ]; do
192
193
yq w -i /tmp/" $NAME " -cm-overrides.yaml " data.[config.json]" -- " $( < /tmp/" $NAME " -cm-overrides.json) "
193
194
yq m -x -i /tmp/" $NAME " overrides.yaml /tmp/" $NAME " -cm-overrides.yaml
194
195
195
- yq m -x -i k8s.yaml -d " $i " /tmp/" $NAME " overrides.yaml
196
+ yq m -x -i k8s.yaml -d " $documentIndex " /tmp/" $NAME " overrides.yaml
196
197
fi
197
198
198
199
# overrides for ws-proxy
199
200
if [[ " ws-proxy" == " $NAME " ]] && [[ " $KIND " == " ConfigMap" ]]; then
200
201
WORK=" overrides for $NAME $KIND "
201
202
echo " $WORK "
202
203
touch /tmp/" $NAME " overrides.yaml
203
- yq r k8s.yaml -d " $i " data | yq prefix - data > /tmp/" $NAME " overrides.yaml
204
+ yq r k8s.yaml -d " $documentIndex " data | yq prefix - data > /tmp/" $NAME " overrides.yaml
204
205
205
206
# simliar to server, except the ConfigMap hierarchy, key, and value are different
206
207
SHORT_NAME=$( yq r ./.werft/jobs/build/helm/values.dev.yaml installation.shortname)
@@ -215,7 +216,7 @@ while [ "$i" -le "$DOCS" ]; do
215
216
# In this, we only do a find replace on a given line if we find workspaceHostSuffixRegex on the line
216
217
sed -i -e " /workspaceHostSuffixRegex/s/$CURRENT_WS_SUFFIX_REGEX /$DEV_BRANCH \\\\\\\\ .staging\\\\\\\\ .gitpod-dev\\\\\\\\ .com/g" /tmp/" $NAME " overrides.yaml
217
218
218
- yq m -x -i k8s.yaml -d " $i " /tmp/" $NAME " overrides.yaml
219
+ yq m -x -i k8s.yaml -d " $documentIndex " /tmp/" $NAME " overrides.yaml
219
220
fi
220
221
221
222
if [[ " openvsx-proxy" == " $NAME " ]] && [[ " $KIND " == " StatefulSet" ]]; then
@@ -224,23 +225,23 @@ while [ "$i" -le "$DOCS" ]; do
224
225
# We're being hit by this while trying to install Gitpod on GKE and k3s running different versions
225
226
# where 'availableReplicas' is unkown in GKE while being required on k3s.
226
227
# This workaround should be deleted when https://github.com/gitpod-io/gitpod/issues/8529 gets fixed.
227
- yq d -i k8s.yaml -d " $i " ' status'
228
+ yq d -i k8s.yaml -d " $documentIndex " ' status'
228
229
fi
229
230
230
231
if [[ ! -v WITH_VM ]] && [[ " ws-proxy" == " $NAME " ]] && [[ " $KIND " == " Service" ]]; then
231
232
WORK=" overrides for $NAME $KIND "
232
233
echo " $WORK "
233
- yq w -i k8s.yaml -d " $i " " spec.ports[+].name" http-lb
234
- yq w -i k8s.yaml -d " $i " " spec.ports.(name==http-lb).port" 80
235
- yq w -i k8s.yaml -d " $i " " spec.ports.(name==http-lb).protocol" TCP
236
- yq w -i k8s.yaml -d " $i " " spec.ports.(name==http-lb).targetPort" 8080
237
-
238
- yq w -i k8s.yaml -d " $i " " spec.ports[+].name" https-lb
239
- yq w -i k8s.yaml -d " $i " " spec.ports.(name==https-lb).port" 443
240
- yq w -i k8s.yaml -d " $i " " spec.ports.(name==https-lb).protocol" TCP
241
- yq w -i k8s.yaml -d " $i " " spec.ports.(name==https-lb).targetPort" 9090
242
- yq w -i k8s.yaml -d " $i " " metadata.annotations[cloud.google.com/neg]" ' {"exposed_ports": {"22":{},"80":{},"443":{}}}'
243
- yq w -i k8s.yaml -d " $i " spec.type LoadBalancer
234
+ yq w -i k8s.yaml -d " $documentIndex " " spec.ports[+].name" http-lb
235
+ yq w -i k8s.yaml -d " $documentIndex " " spec.ports.(name==http-lb).port" 80
236
+ yq w -i k8s.yaml -d " $documentIndex " " spec.ports.(name==http-lb).protocol" TCP
237
+ yq w -i k8s.yaml -d " $documentIndex " " spec.ports.(name==http-lb).targetPort" 8080
238
+
239
+ yq w -i k8s.yaml -d " $documentIndex " " spec.ports[+].name" https-lb
240
+ yq w -i k8s.yaml -d " $documentIndex " " spec.ports.(name==https-lb).port" 443
241
+ yq w -i k8s.yaml -d " $documentIndex " " spec.ports.(name==https-lb).protocol" TCP
242
+ yq w -i k8s.yaml -d " $documentIndex " " spec.ports.(name==https-lb).targetPort" 9090
243
+ yq w -i k8s.yaml -d " $documentIndex " " metadata.annotations[cloud.google.com/neg]" ' {"exposed_ports": {"22":{},"80":{},"443":{}}}'
244
+ yq w -i k8s.yaml -d " $documentIndex " spec.type LoadBalancer
244
245
fi
245
246
246
247
# update workspace-templates configmap to set affinity for workspace, ghosts, image builders, etc.
@@ -251,7 +252,7 @@ while [ "$i" -le "$DOCS" ]; do
251
252
touch /tmp/" $NAME " overrides.yaml
252
253
253
254
# get the data to modify
254
- yq r k8s.yaml -d " $i " ' data.[default.yaml]' > /tmp/" $NAME " overrides.yaml
255
+ yq r k8s.yaml -d " $documentIndex " ' data.[default.yaml]' > /tmp/" $NAME " overrides.yaml
255
256
256
257
# add the proper affinity
257
258
LABEL=" gitpod.io/workspace_$NODE_POOL_INDEX "
@@ -261,29 +262,29 @@ while [ "$i" -le "$DOCS" ]; do
261
262
yq w -i /tmp/" $NAME " overrides.yaml " spec.containers.(name==workspace).env[+].name" GITPOD_PREVENT_METADATA_ACCESS
262
263
yq w -i /tmp/" $NAME " overrides.yaml " spec.containers.(name==workspace).env.(name==GITPOD_PREVENT_METADATA_ACCESS).value" " true"
263
264
264
- yq w -i k8s.yaml -d " $i " " data.[default.yaml]" -- " $( < /tmp/" $NAME " overrides.yaml) "
265
+ yq w -i k8s.yaml -d " $documentIndex " " data.[default.yaml]" -- " $( < /tmp/" $NAME " overrides.yaml) "
265
266
fi
266
267
267
268
# NetworkPolicy for ws-daemon
268
269
if [[ " ws-daemon" == " $NAME " ]] && [[ " $KIND " == " NetworkPolicy" ]]; then
269
270
WORK=" overrides for $NAME $KIND "
270
271
echo " $WORK "
271
- yq w -i k8s.yaml -d " $i " spec.ingress[0].ports[0].port " $WS_DAEMON_PORT "
272
+ yq w -i k8s.yaml -d " $documentIndex " spec.ingress[0].ports[0].port " $WS_DAEMON_PORT "
272
273
fi
273
274
274
275
# NetworkPolicy for workspace-default
275
276
if [[ " workspace-default" == " $NAME " ]] && [[ " $KIND " == " NetworkPolicy" ]]; then
276
277
WORK=" overrides for $NAME $KIND "
277
278
echo " $WORK "
278
- yq w -i k8s.yaml -d " $i " spec.egress[0].to[0].ipBlock.except[0] 169.254.169.254/30
279
+ yq w -i k8s.yaml -d " $documentIndex " spec.egress[0].to[0].ipBlock.except[0] 169.254.169.254/30
279
280
fi
280
281
281
282
# host ws-daemon on $WS_DAEMON_PORT
282
283
if [[ " ws-daemon" == " $NAME " ]] && [[ " $KIND " == " ConfigMap" ]]; then
283
284
WORK=" overrides for $NAME $KIND "
284
285
echo " $WORK "
285
286
# Get a copy of the config we're working with
286
- yq r k8s.yaml -d " $i " > /tmp/" $NAME " -" $KIND " -overrides.yaml
287
+ yq r k8s.yaml -d " $documentIndex " > /tmp/" $NAME " -" $KIND " -overrides.yaml
287
288
# Parse and update the JSON, and write it to a file
288
289
yq r /tmp/" $NAME " -" $KIND " -overrides.yaml ' data.[config.json]' \
289
290
| jq " .service.address = $WS_DAEMON_PORT " > /tmp/" $NAME " -" $KIND " -overrides.json
@@ -297,14 +298,14 @@ while [ "$i" -le "$DOCS" ]; do
297
298
# merge the updated data object with existing config
298
299
yq m -x -i /tmp/" $NAME " -" $KIND " -overrides.yaml /tmp/" $NAME " -" $KIND " -data-overrides.yaml
299
300
# merge the updated config map with k8s.yaml
300
- yq m -x -i k8s.yaml -d " $i " /tmp/" $NAME " -" $KIND " -overrides.yaml
301
+ yq m -x -i k8s.yaml -d " $documentIndex " /tmp/" $NAME " -" $KIND " -overrides.yaml
301
302
fi
302
303
303
304
# suspend telemetry cron job
304
305
if [[ " gitpod-telemetry" == " $NAME " ]] && [[ " $KIND " == " CronJob" ]]; then
305
306
WORK=" suspend $NAME $KIND "
306
307
echo " $WORK "
307
- yq w -i k8s.yaml -d " $i " spec.suspend " true"
308
+ yq w -i k8s.yaml -d " $documentIndex " spec.suspend " true"
308
309
fi
309
310
310
311
# Uncomment to change or remove resources from the configmap which can be used to uninstall Gitpod
@@ -315,7 +316,7 @@ while [ "$i" -le "$DOCS" ]; do
315
316
# WORK="overrides for $NAME $KIND"
316
317
# echo "$WORK"
317
318
# # Get a copy of the config we're working with
318
- # yq r k8s.yaml -d "$i " > /tmp/"$NAME"-"$KIND".yaml
319
+ # yq r k8s.yaml -d "$documentIndex " > /tmp/"$NAME"-"$KIND".yaml
319
320
# # Parse the YAML string from the config map
320
321
# yq r /tmp/"$NAME"-"$KIND".yaml 'data.[app.yaml]' > /tmp/"$NAME"-"$KIND"-original.yaml
321
322
# # Loop through the config YAML docs
@@ -355,13 +356,13 @@ while [ "$i" -le "$DOCS" ]; do
355
356
# # merge overrides into base
356
357
# yq w -i /tmp/"$NAME"-"$KIND".yaml "data.[app.yaml]" -- "$(< /tmp/"$NAME"-"$KIND"-overrides.yaml)"
357
358
# # merge base into k8s.yaml
358
- # yq m -x -i -d "$i " k8s.yaml /tmp/"$NAME"-"$KIND".yaml
359
+ # yq m -x -i -d "$documentIndex " k8s.yaml /tmp/"$NAME"-"$KIND".yaml
359
360
# fi
360
361
361
362
# TODO: integrate with chargebees
362
363
# won't fix now, use Helm
363
364
364
- i =$(( i + 1 ))
365
+ documentIndex =$(( documentIndex + 1 ))
365
366
done
366
367
367
368
exit
0 commit comments