Skip to content

Commit 6ba9b39

Browse files
author
Simon Emms
committed
[kots]: allow multiple docker pull secrets
1 parent 0e0abb8 commit 6ba9b39

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

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

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,36 @@ 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+
# Output the local registry secret - this is proxy.replicated.com if user hasn't set their own
156+
echo "{{repl LocalRegistryImagePullSecret }}" | base64 -d > /tmp/kotsregistry.json
157+
158+
# Add the registries to the server allowlist
159+
yq e -i ".experimental.webApp.server.defaultBaseImageRegistryWhitelist += $(cat /tmp/kotsregistry.json | jq '.auths' | jq -rc 'keys')" "${CONFIG_FILE}"
160+
161+
if [ '{{repl ConfigOptionEquals "reg_incluster" "0" }}' = "true" ];
158162
then
159163
echo "Gitpod: configuring external container registry"
160164
165+
# Create a container-registry secret merging the external registry and KOTS registry keys
166+
echo '{{repl printf "{\"auths\": {\"%s\": {\"username\": \"%s\", \"password\": %s, \"auth\": \"%s\"}}}" (ConfigOption "reg_server" | default (ConfigOption "reg_url")) (ConfigOption "reg_username") (ConfigOption "reg_password" | toJson) (printf "%s:%s" (ConfigOption "reg_username") (ConfigOption "reg_password") | Base64Encode) }}' \
167+
| yq -o=json '.' - \
168+
> /tmp/gitpodregistry.json
169+
170+
cat /tmp/kotsregistry.json /tmp/gitpodregistry.json | jq -s '.[0] * .[1]' - - > /tmp/container-registry-secret
171+
172+
echo "Gitpod: create the container-registry secret"
173+
kubectl create secret docker-registry container-registry \
174+
--namespace "{{repl Namespace }}" \
175+
--from-file=.dockerconfigjson=/tmp/container-registry-secret \
176+
-o yaml --dry-run=client | \
177+
kubectl replace --namespace "{{repl Namespace }}" --force -f -
178+
161179
yq e -i ".containerRegistry.inCluster = false" "${CONFIG_FILE}"
162180
yq e -i ".containerRegistry.external.url = \"{{repl ConfigOption "reg_url" }}\"" "${CONFIG_FILE}"
163181
yq e -i ".containerRegistry.external.certificate.kind = \"secret\"" "${CONFIG_FILE}"
@@ -273,6 +291,23 @@ spec:
273291
'del(select(.kind == "StatefulSet" and .metadata.name == "openvsx-proxy").status)' \
274292
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
275293
294+
if [ '{{repl ConfigOptionEquals "reg_incluster" "1" }}' = "true" ];
295+
then
296+
echo "Gitpod: Add the local registry secret to the in-cluster registry secret"
297+
298+
# Get the in-cluster registry secret
299+
yq eval-all '(select(.kind == "Secret" and .metadata.name == "builtin-registry-auth") | .data.".dockerconfigjson")' \
300+
"${GITPOD_OBJECTS}/templates/gitpod.yaml" \
301+
| base64 -d \
302+
> /tmp/gitpodregistry.json
303+
304+
export REGISTRY_SECRET=$(cat /tmp/kotsregistry.json /tmp/gitpodregistry.json | jq -s '.[0] * .[1]' - - | base64 -w 0)
305+
306+
echo "Gitpod: update the in-cluster registry secret"
307+
yq eval-all --inplace '(select(.kind == "Secret" and .metadata.name == "builtin-registry-auth") | .data.".dockerconfigjson") |= env(REGISTRY_SECRET)' \
308+
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
309+
fi
310+
276311
echo "Gitpod: Escape any Golang template values"
277312
sed -i -r 's/(.*\{\{.*)/{{`\1`}}/' "${GITPOD_OBJECTS}/templates/gitpod.yaml"
278313

install/kots/manifests/gitpod-registry-secret.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

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)