Skip to content

Commit 03a8531

Browse files
author
Simon Emms
committed
[kots]: allow multiple docker pull secrets
1 parent 769c7b2 commit 03a8531

File tree

3 files changed

+41
-22
lines changed

3 files changed

+41
-22
lines changed

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,33 @@ 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+
if [ '{{repl ConfigOptionEquals "reg_incluster" "0" }}' = "true" ];
158159
then
159160
echo "Gitpod: configuring external container registry"
160161
162+
# Create a container-registry secret merging the external registry and KOTS registry keys
163+
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) }}' \
164+
| yq -o=json '.' - \
165+
> /tmp/gitpodregistry.json
166+
167+
cat /tmp/kotsregistry.json /tmp/gitpodregistry.json | jq -s '.[0] * .[1]' - - > /tmp/container-registry-secret
168+
169+
echo "Gitpod: create the container-registry secret"
170+
kubectl create secret docker-registry container-registry \
171+
--namespace "{{repl Namespace }}" \
172+
--from-file=.dockerconfigjson=/tmp/container-registry-secret \
173+
-o yaml --dry-run=client | \
174+
kubectl replace --namespace "{{repl Namespace }}" --force -f -
175+
161176
yq e -i ".containerRegistry.inCluster = false" "${CONFIG_FILE}"
162177
yq e -i ".containerRegistry.external.url = \"{{repl ConfigOption "reg_url" }}\"" "${CONFIG_FILE}"
163178
yq e -i ".containerRegistry.external.certificate.kind = \"secret\"" "${CONFIG_FILE}"
@@ -273,6 +288,23 @@ spec:
273288
'del(select(.kind == "StatefulSet" and .metadata.name == "openvsx-proxy").status)' \
274289
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
275290
291+
if [ '{{repl ConfigOptionEquals "reg_incluster" "1" }}' = "true" ];
292+
then
293+
echo "Gitpod: Add the local registry secret to the in-cluster registry secret"
294+
295+
# Get the in-cluster registry secret
296+
yq eval-all '(select(.kind == "Secret" and .metadata.name == "builtin-registry-auth") | .data.".dockerconfigjson")' \
297+
"${GITPOD_OBJECTS}/templates/gitpod.yaml" \
298+
| base64 -d \
299+
> /tmp/gitpodregistry.json
300+
301+
export REGISTRY_SECRET=$(cat /tmp/kotsregistry.json /tmp/gitpodregistry.json | jq -s '.[0] * .[1]' - - | base64 -w 0)
302+
303+
echo "Gitpod: update the in-cluster registry secret"
304+
yq eval-all --inplace '(select(.kind == "Secret" and .metadata.name == "builtin-registry-auth") | .data.".dockerconfigjson") |= env(REGISTRY_SECRET)' \
305+
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
306+
fi
307+
276308
echo "Gitpod: Escape any Golang template values"
277309
sed -i -r 's/(.*\{\{.*)/{{`\1`}}/' "${GITPOD_OBJECTS}/templates/gitpod.yaml"
278310

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)