Skip to content

Commit 46dcc6b

Browse files
[kots] Allow multiple docker pull secrets
1 parent f5eaee9 commit 46dcc6b

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,18 @@ spec:
146146
then
147147
echo "Gitpod: configuring mirrored container registry"
148148
149-
yq e -i ".containerRegistry.inCluster = false" "${CONFIG_FILE}"
150-
yq e -i ".containerRegistry.external.url = \"{{repl LocalRegistryAddress }}\"" "${CONFIG_FILE}"
151-
yq e -i ".containerRegistry.external.certificate.kind = \"secret\"" "${CONFIG_FILE}"
152-
yq e -i ".containerRegistry.external.certificate.name = \"{{repl ImagePullSecretName }}\"" "${CONFIG_FILE}"
153149
yq e -i ".repository = \"{{repl LocalRegistryAddress }}\"" "${CONFIG_FILE}"
154150
yq e -i ".imagePullSecrets[0].kind = \"secret\"" "${CONFIG_FILE}"
155151
yq e -i ".imagePullSecrets[0].name = \"{{repl ImagePullSecretName }}\"" "${CONFIG_FILE}"
156152
yq e -i '.dropImageRepo = true' "${CONFIG_FILE}"
157-
elif [ '{{repl ConfigOptionEquals "reg_incluster" "0" }}' = "true" ];
153+
fi
154+
155+
if [ '{{repl ConfigOptionEquals "reg_incluster" "0" }}' = "true" ];
158156
then
159157
echo "Gitpod: configuring external container registry"
160158
161159
yq e -i ".containerRegistry.inCluster = false" "${CONFIG_FILE}"
162160
yq e -i ".containerRegistry.external.url = \"{{repl ConfigOption "reg_url" }}\"" "${CONFIG_FILE}"
163-
yq e -i ".containerRegistry.external.certificate.kind = \"secret\"" "${CONFIG_FILE}"
164-
yq e -i ".containerRegistry.external.certificate.name = \"container-registry\"" "${CONFIG_FILE}"
165161
else
166162
if [ '{{repl ConfigOptionEquals "reg_incluster_storage" "s3" }}' = "true" ];
167163
then
@@ -174,6 +170,9 @@ spec:
174170
yq e -i ".containerRegistry.s3storage.certificate.name = \"container-registry-s3-backend\"" "${CONFIG_FILE}"
175171
fi
176172
fi
173+
# merged-registry-auths will be created below
174+
yq e -i ".containerRegistry.external.certificate.kind = \"secret\"" "${CONFIG_FILE}"
175+
yq e -i ".containerRegistry.external.certificate.name = \"merged-registry-auths\"" "${CONFIG_FILE}"
177176
178177
if [ '{{repl ConfigOptionNotEquals "store_provider" "incluster" }}' = "true" ];
179178
then
@@ -273,6 +272,26 @@ spec:
273272
'del(select(.kind == "StatefulSet" and .metadata.name == "openvsx-proxy").status)' \
274273
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
275274
275+
# Merge different docker pull secrets into one secret
276+
if [ '{{repl HasLocalRegistry }}' = "true" ];
277+
then
278+
kubectl get secret "{{repl ImagePullSecretName }}" -o=jsonpath="{.data['\.dockerconfigjson']}" | base64 -d | yq -P - > registry-auth-airgap.yaml
279+
fi
280+
if [ '{{repl ConfigOptionEquals "reg_incluster" "0" }}' = "true" ];
281+
then
282+
kubectl get secret "container-registry" -o=jsonpath="{.data['\.dockerconfigjson']}" | base64 -d | yq -P - > registry-auth-external.yaml
283+
else
284+
yq eval 'select(.kind == "Secret" and .metadata.name == "builtin-registry-auth").data.".dockerconfigjson"' \
285+
"${GITPOD_OBJECTS}/templates/gitpod.yaml" | base64 -d | yq -P - > registry-auth-builtin.yaml
286+
fi
287+
# merge all files together (https://mikefarah.gitbook.io/yq/operators/reduce#merge-all-yaml-files-together)
288+
yq -o=json eval-all '. as $item ireduce ({}; . * $item )' registry-auth-*.yaml > merged-registry-auths.yaml
289+
# create secret and update if exists (https://stackoverflow.com/a/45881259/1364435)
290+
kubectl create secret generic merged-registry-auths \
291+
--save-config --dry-run=client \
292+
--from-file=.dockerconfigjson=./merged-registry-auths.yaml \
293+
-o yaml > "${GITPOD_OBJECTS}/templates/merged-registry-auths.yaml"
294+
276295
echo "Gitpod: Escape any Golang template values"
277296
sed -i -r 's/(.*\{\{.*)/{{`\1`}}/' "${GITPOD_OBJECTS}/templates/gitpod.yaml"
278297

install/kots/manifests/kots-config.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ spec:
2828
- name: reg_incluster
2929
title: Use in-cluster container registry
3030
type: bool
31-
when: '{{repl eq HasLocalRegistry false }}'
3231
default: "1"
3332
help_text: You may either use an in-cluster container registry or configure your own external container registry for better performance. This container registry must be accessible from your Kubernetes cluster.
3433
recommended: false
@@ -85,27 +84,27 @@ spec:
8584
- name: reg_url
8685
title: Container registry URL
8786
type: text
88-
when: '{{repl and (eq HasLocalRegistry false) (ConfigOptionEquals "reg_incluster" "0") }}'
87+
when: '{{repl (ConfigOptionEquals "reg_incluster" "0") }}'
8988
required: true
9089
help_text: The container registry URL. This will usually be the fully qualified domain of your registry.
9190

9291
- name: reg_server
9392
title: Container registry server
9493
type: text
95-
when: '{{repl and (eq HasLocalRegistry false) (ConfigOptionEquals "reg_incluster" "0") }}'
94+
when: '{{repl (ConfigOptionEquals "reg_incluster" "0") }}'
9695
help_text: The container registry server. This is used when [generating your credentials](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-by-providing-credentials-on-the-command-line). Depending upon your provider, this may or may not be the same as the registry URL. If not specified, the URL will be used.
9796

9897
- name: reg_username
9998
title: Container registry username
10099
type: text
101-
when: '{{repl and (eq HasLocalRegistry false) (ConfigOptionEquals "reg_incluster" "0") }}'
100+
when: '{{repl (ConfigOptionEquals "reg_incluster" "0") }}'
102101
required: true
103102
help_text: The username for your container registry.
104103

105104
- name: reg_password
106105
title: Container registry password
107106
type: password
108-
when: '{{repl and (eq HasLocalRegistry false) (ConfigOptionEquals "reg_incluster" "0") }}'
107+
when: '{{repl (ConfigOptionEquals "reg_incluster" "0") }}'
109108
required: true
110109
help_text: The password for your container registry.
111110

0 commit comments

Comments
 (0)