Skip to content

Commit a989257

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

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,30 @@ 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+
echo "{{repl LocalRegistryImagePullSecret | Base64Decode }}" > /tmp/kotsregistry.json
156+
157+
if [ '{{repl ConfigOptionEquals "reg_incluster" "0" }}' = "true" ];
158158
then
159159
echo "Gitpod: configuring external container registry"
160160
161+
# Create a container-registry secret merging the external registry and KOTS registry keys
162+
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) }}" > /tmp/gitpodregistry.json
163+
164+
cat /tmp/kotsregistry.json /tmp/gitpodregistry.json | jq -s '.[0] * .[1]' - - | base64 -w 0 > /tmp/container-registry-secret
165+
166+
echo "Gitpod: create the container-registry secret"
167+
kubectl create secret docker-registry container-registry \
168+
--namespace "{{repl Namespace }}" \
169+
--from-file=.dockerconfigjson=/tmp/container-registry-secret \
170+
-o yaml --dry-run=client | \
171+
kubectl replace --namespace "{{repl Namespace }}" --force -f -
172+
161173
yq e -i ".containerRegistry.inCluster = false" "${CONFIG_FILE}"
162174
yq e -i ".containerRegistry.external.url = \"{{repl ConfigOption "reg_url" }}\"" "${CONFIG_FILE}"
163175
yq e -i ".containerRegistry.external.certificate.kind = \"secret\"" "${CONFIG_FILE}"
@@ -273,6 +285,23 @@ spec:
273285
'del(select(.kind == "StatefulSet" and .metadata.name == "openvsx-proxy").status)' \
274286
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
275287
288+
if [ '{{repl ConfigOptionEquals "reg_incluster" "1" }}' = "true" ];
289+
then
290+
echo "Gitpod: Add the local registry secret to the in-cluster registry secret"
291+
292+
# Get the in-cluster registry secret
293+
yq eval-all '(select(.kind == "Secret" and .metadata.name == "builtin-registry-auth") | .data.".dockerconfigjson")' \
294+
"${GITPOD_OBJECTS}/templates/gitpod.yaml" \
295+
| base64 -d \
296+
> /tmp/gitpodregistry.json
297+
298+
export REGISTRY_SECRET=$(cat /tmp/kotsregistry.json /tmp/gitpodregistry.json | jq -s '.[0] * .[1]' - - | base64 -w 0)
299+
300+
echo "Gitpod: update the in-cluster registry secret"
301+
yq eval-all --inplace '(select(.kind == "Secret" and .metadata.name == "builtin-registry-auth") | .data.".dockerconfigjson") |= env(REGISTRY_SECRET)' \
302+
"${GITPOD_OBJECTS}/templates/gitpod.yaml"
303+
fi
304+
276305
echo "Gitpod: Escape any Golang template values"
277306
sed -i -r 's/(.*\{\{.*)/{{`\1`}}/' "${GITPOD_OBJECTS}/templates/gitpod.yaml"
278307

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)