Skip to content

Commit d2dc67d

Browse files
author
Simon Emms
committed
[kots]: add preflight check to validate the generated Gitpod config
1 parent 0db679d commit d2dc67d

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

.werft/jobs/build/build-and-publish.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ function publishKots(werft: Werft, jobConfig: JobConfig) {
154154
{ slice: phases.PUBLISH_KOTS },
155155
);
156156

157-
// Generate the logo and pull any Helm charts
158-
exec(`make logo helm -C ${REPLICATED_DIR}`, { slice: phases.PUBLISH_KOTS });
157+
// Generate the preflights, logo and pull any Helm charts
158+
exec(`make generate_preflight_checks logo helm -C ${REPLICATED_DIR}`, { slice: phases.PUBLISH_KOTS });
159159

160160
// Update the additionalImages in the kots-app.yaml
161161
exec(`/tmp/installer mirror kots --file ${REPLICATED_YAML_DIR}/kots-app.yaml`, { slice: phases.PUBLISH_KOTS });

install/kots/Makefile

+26-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANNEL_UNSTABLE = Unstable
44
CHARTS_DIR = charts
55
YAML_DIR = manifests
66

7-
all: logo helm lint create_dev_release
7+
all: generate_preflight_checks logo helm lint create_dev_release
88

99
create_dev_release:
1010
@if [ "${REPLICATED_DEV_CHANNEL}" = "" ]; then \
@@ -24,6 +24,31 @@ create_unstable_release:
2424
replicated release create --lint --ensure-channel --yaml-dir ${YAML_DIR} --promote ${CHANNEL_UNSTABLE}
2525
.PHONY: create_unstable_release
2626

27+
generate_preflight_checks:
28+
@echo "Generating installation config validation preflight check"
29+
30+
# Extract the installer job
31+
@yq r manifests/gitpod-installer-job.yaml spec.template.spec > /tmp/installer-job.yaml
32+
# Remove the envFrom block
33+
@yq d -i /tmp/installer-job.yaml containers[0].envFrom
34+
35+
# Extract the envFrom block as envvars and convert to "env" format
36+
@yq r -j manifests/gitpod-kots-config.yaml data > /tmp/installer-envvars.json
37+
38+
@for row in $$(cat /tmp/installer-envvars.json | jq -r 'to_entries | .[] | @base64'); do \
39+
yq w -i /tmp/installer-job.yaml containers[0].env[+].name "$$(echo $${row} | base64 -d | jq -r '.key')"; \
40+
yq w -i /tmp/installer-job.yaml containers[0].env[-1].value "$$(echo $${row} | base64 -d | jq -r '.value')"; \
41+
done
42+
43+
# Set as dry run
44+
@yq w -i /tmp/installer-job.yaml containers[0].env[+].name "INSTALLER_DRY_RUN"
45+
@yq w --tag=!!str -i /tmp/installer-job.yaml containers[0].env[-1].value "true"
46+
47+
# Merge the envvars into the installer job
48+
@yq p -i /tmp/installer-job.yaml spec.collectors[0].runPod.podSpec
49+
@yq m -i manifests/kots-preflight.yaml /tmp/installer-job.yaml
50+
.PHONY: generate_preflight_checks
51+
2752
helm:
2853
@echo "Installing Helm dependencies"
2954
@rm -f ${YAML_DIR}/*.tgz

install/kots/manifests/gitpod-installation-status.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spec:
3030
containers:
3131
- name: installation-status
3232
# This will normally be the release tag
33-
image: "eu.gcr.io/gitpod-core-dev/build/installer:sje-kots-refactoring.6"
33+
image: "eu.gcr.io/gitpod-core-dev/build/installer:sje-kots-config-validate.7"
3434
envFrom:
3535
- configMapRef:
3636
name: gitpod-kots-config

install/kots/manifests/gitpod-installer-job.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ spec:
3939
containers:
4040
- name: installer
4141
# This will normally be the release tag
42-
image: "eu.gcr.io/gitpod-core-dev/build/installer:sje-kots-refactoring.6"
42+
image: "eu.gcr.io/gitpod-core-dev/build/installer:sje-kots-config-validate.7"
4343
volumeMounts:
4444
- mountPath: /mnt/node0
4545
name: node-fs0

install/kots/manifests/kots-preflight.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ metadata:
77
name: gitpod
88
spec:
99
collectors:
10+
# This will be overridden by the generate_preflight_checks in the Makefile - this must remain at position 0
11+
- runPod:
12+
name: validate-config
13+
namespace: '{{repl Namespace }}'
14+
podSpec:
15+
containers: []
1016
- run:
1117
collectorName: database
1218
image: eu.gcr.io/gitpod-core-dev/build/kots-config-check/database:sje-kots-config-check.9
@@ -99,6 +105,23 @@ spec:
99105
100106
echo "connection: ${CONNECTION}"
101107
analyzers:
108+
- textAnalyze:
109+
checkName: Gitpod configuration
110+
fileName: validate-config/validate-config.log
111+
regexGroups: 'Gitpod: status (?P<Status>\w+)'
112+
outcomes:
113+
- fail:
114+
when: "Status == fail"
115+
message: |
116+
Your generated Gitpod config failed validation. Run
117+
`kubectl get configmaps -n {{repl Namespace }} gitpod-installation-status -o jsonpath="{.data.gitpod-installer\.log}"`
118+
to view the output.
119+
- pass:
120+
when: "Status == pass"
121+
message: |
122+
Your generated Gitpod config is valid. Run
123+
`kubectl get configmaps -n {{repl Namespace }} gitpod-installation-status -o jsonpath="{.data.gitpod-installer\.log}"`
124+
to view the output.
102125
- clusterVersion:
103126
outcomes:
104127
- fail:

0 commit comments

Comments
 (0)