Skip to content

Commit 7c5b786

Browse files
deploy: Add script to inject imagePullSecrets to serviceaccount
This patch adds a utility script that is called as a part of `build-helm-installer` to inject `imagePullSecrets` from `ceph-csi-operator` values to `serviceaccounts` Signed-off-by: Niraj Yadav <niryadav@redhat.com>
1 parent 1a556db commit 7c5b786

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ build-helm-installer: manifests generate kustomize helmify ## Generate helm char
204204
cd build && echo "$$BUILD_INSTALLER_OVERLAY" > kustomization.yaml
205205
cd build && $(KUSTOMIZE) edit add resource ../config/default/
206206
$(KUSTOMIZE) build build | $(HELMIFY) -image-pull-secrets deploy/charts/ceph-csi-operator
207+
hack/patch-sa-with-imgpullsecrets.sh deploy/charts/ceph-csi-operator
207208
rm -rf build
208209

209210
.PHONY: build-multifile-installer

deploy/charts/ceph-csi-operator/templates/serviceaccount.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ metadata:
66
{{- include "ceph-csi-operator.labels" . | nindent 4 }}
77
annotations:
88
{{- toYaml .Values.cephfsCtrlpluginSa.serviceAccount.annotations | nindent 4 }}
9+
{{- with .Values.imagePullSecrets }}
10+
imagePullSecrets:
11+
{{ toYaml . | indent 2 }}
12+
{{- end }}
913
---
1014
apiVersion: v1
1115
kind: ServiceAccount
@@ -15,6 +19,10 @@ metadata:
1519
{{- include "ceph-csi-operator.labels" . | nindent 4 }}
1620
annotations:
1721
{{- toYaml .Values.cephfsNodepluginSa.serviceAccount.annotations | nindent 4 }}
22+
{{- with .Values.imagePullSecrets }}
23+
imagePullSecrets:
24+
{{ toYaml . | indent 2 }}
25+
{{- end }}
1826
---
1927
apiVersion: v1
2028
kind: ServiceAccount
@@ -24,6 +32,10 @@ metadata:
2432
{{- include "ceph-csi-operator.labels" . | nindent 4 }}
2533
annotations:
2634
{{- toYaml .Values.controllerManager.serviceAccount.annotations | nindent 4 }}
35+
{{- with .Values.imagePullSecrets }}
36+
imagePullSecrets:
37+
{{ toYaml . | indent 2 }}
38+
{{- end }}
2739
---
2840
apiVersion: v1
2941
kind: ServiceAccount
@@ -33,6 +45,10 @@ metadata:
3345
{{- include "ceph-csi-operator.labels" . | nindent 4 }}
3446
annotations:
3547
{{- toYaml .Values.nfsCtrlpluginSa.serviceAccount.annotations | nindent 4 }}
48+
{{- with .Values.imagePullSecrets }}
49+
imagePullSecrets:
50+
{{ toYaml . | indent 2 }}
51+
{{- end }}
3652
---
3753
apiVersion: v1
3854
kind: ServiceAccount
@@ -42,6 +58,10 @@ metadata:
4258
{{- include "ceph-csi-operator.labels" . | nindent 4 }}
4359
annotations:
4460
{{- toYaml .Values.nfsNodepluginSa.serviceAccount.annotations | nindent 4 }}
61+
{{- with .Values.imagePullSecrets }}
62+
imagePullSecrets:
63+
{{ toYaml . | indent 2 }}
64+
{{- end }}
4565
---
4666
apiVersion: v1
4767
kind: ServiceAccount
@@ -51,6 +71,10 @@ metadata:
5171
{{- include "ceph-csi-operator.labels" . | nindent 4 }}
5272
annotations:
5373
{{- toYaml .Values.rbdCtrlpluginSa.serviceAccount.annotations | nindent 4 }}
74+
{{- with .Values.imagePullSecrets }}
75+
imagePullSecrets:
76+
{{ toYaml . | indent 2 }}
77+
{{- end }}
5478
---
5579
apiVersion: v1
5680
kind: ServiceAccount
@@ -60,3 +84,7 @@ metadata:
6084
{{- include "ceph-csi-operator.labels" . | nindent 4 }}
6185
annotations:
6286
{{- toYaml .Values.rbdNodepluginSa.serviceAccount.annotations | nindent 4 }}
87+
{{- with .Values.imagePullSecrets }}
88+
imagePullSecrets:
89+
{{ toYaml . | indent 2 }}
90+
{{- end }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
# DO NOT run this script on its own
3+
# It will append the required template multiple times
4+
# It is intended to be ran as a part of generating heml charts using helmify
5+
6+
set -e
7+
8+
CHART_DIR=$1
9+
SA_FILE="${CHART_DIR}/templates/serviceaccount.yaml"
10+
11+
if [ ! -f "$SA_FILE" ]; then
12+
echo "No serviceaccount.yaml template in $CHART_DIR, nothing to do!"
13+
exit 1
14+
fi
15+
16+
TEMPLATE_SNIPPET=$(
17+
cat <<'EOF'
18+
{{- with .Values.imagePullSecrets }}
19+
imagePullSecrets:
20+
{{ toYaml . | indent 2 }}
21+
{{- end }}
22+
EOF
23+
)
24+
25+
echo "Patching $SA_FILE for imagePullSecrets"
26+
27+
awk -v snippet="$TEMPLATE_SNIPPET" '
28+
# Before printing a separator, print the snippet
29+
/^---/ { print snippet }
30+
31+
# Print the current line
32+
{ print }
33+
34+
# At the end of the file, print the snippet for the last section
35+
END { print snippet }
36+
' "$SA_FILE" >"${SA_FILE}.tmp"
37+
38+
mv "${SA_FILE}.tmp" "$SA_FILE"
39+
40+
echo "Patched $SA_FILE successfully"
41+
exit 0

0 commit comments

Comments
 (0)