@@ -13,26 +13,28 @@ if [ ! -f "$SA_FILE" ]; then
1313 exit 1
1414fi
1515
16- TEMPLATE_SNIPPET=$(
17- cat << 'EOF '
18- {{- with .Values.imagePullSecrets }}
19- imagePullSecrets:
20- {{ toYaml . | indent 2 }}
21- {{- end }}
22- EOF
23- )
24-
2516echo " Patching $SA_FILE for imagePullSecrets"
2617
27- awk -v snippet=" $TEMPLATE_SNIPPET " '
18+ # Use awk to insert the snippet before each '---' separator and at the end
19+ awk '
2820 # Before printing a separator, print the snippet
29- /^---/ { print snippet }
21+ /^---/ {
22+ print "{{- with .Values.imagePullSecrets }}"
23+ print "imagePullSecrets:"
24+ print "{{ toYaml . | indent 2 }}"
25+ print "{{- end }}"
26+ }
3027
3128 # Print the current line
3229 { print }
3330
3431 # At the end of the file, print the snippet for the last section
35- END { print snippet }
32+ END {
33+ print "{{- with .Values.imagePullSecrets }}"
34+ print "imagePullSecrets:"
35+ print "{{ toYaml . | indent 2 }}"
36+ print "{{- end }}"
37+ }
3638' " $SA_FILE " > " ${SA_FILE} .tmp"
3739
3840mv " ${SA_FILE} .tmp" " $SA_FILE "
@@ -51,12 +53,12 @@ if [[ "$CHART_DIR" == *"ceph-csi-operator"* ]]; then
5153
5254 # Check if the file already has the $root variable definition
5355 if ! grep -q " {{- \$ root := . -}}" " $file " ; then
54- # Add the $root variable definition at the top of the file
55- sed -i " 1i {{- \$ root := . -}}" " $file "
56+ # Add the $root variable definition at the top of the file using a temp file
57+ echo " {{- \$ root := . -}}" | cat - " $file " > " $file .tmp " && mv " $file .tmp " " $file "
5658 fi
5759
58- # Replace the namespace string
59- sed -i " s/namespace: ceph-csi-operator-system/namespace: {{ \$ root.Release.Namespace }}/g" " $file "
60+ # Replace the namespace string using a temp file (portable across all platforms)
61+ sed " s/namespace: ceph-csi-operator-system/namespace: {{ \$ root.Release.Namespace }}/g" " $file " > " $file .tmp " && mv " $file .tmp " " $file "
6062 fi
6163 done
6264
0 commit comments