Skip to content

Commit 69142b6

Browse files
authored
Merge pull request #621 from kaovilai/fix-sed-in-place-modifications
Fix: Prevent duplicate sidecars by copying to temp before sed modifications
2 parents 518b002 + 822fe02 commit 69142b6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

deploy/util/deploy-hostpath.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,23 @@ fi
253253
echo "deploying hostpath components"
254254
for i in $(ls ${BASE_DIR}/hostpath/*.yaml | sort); do
255255
echo " $i"
256+
257+
# Copy original file to temp directory to avoid modifying git-tracked files
258+
temp_yaml="${TEMP_DIR}/$(basename "$i")"
259+
cp "$i" "$temp_yaml"
260+
256261
if volume_mode_conversion; then
257-
sed -i -e 's/# end csi-provisioner args/- \"--prevent-volume-mode-conversion=true\"\n # end csi-provisioner args/' $i
262+
sed -i -e 's/# end csi-provisioner args/- \"--prevent-volume-mode-conversion=true\"\n # end csi-provisioner args/' "$temp_yaml"
258263
fi
259264

260265
# Add external-snapshot-metadata sidecar to the driver, mount TLS certs,
261266
# and enable snapshot-metadata service
262267
if snapshot_metadata; then
263-
sed -i -e "/# end csi containers/r ${SNAPSHOT_METADATA_SIDECAR_PATCH_RELATIVE_PATH}" $i
264-
sed -i -e 's/# end csi volumes/- name: csi-snapshot-metadata-server-certs\n secret:\n secretName: csi-snapshot-metadata-certs\n # end csi volumes/' $i
265-
sed -i -e 's/# end hostpath args/- \"--enable-snapshot-metadata\"\n # end hostpath args/' $i
268+
sed -i -e "/# end csi containers/r ${SNAPSHOT_METADATA_SIDECAR_PATCH_RELATIVE_PATH}" "$temp_yaml"
269+
sed -i -e 's/# end csi volumes/- name: csi-snapshot-metadata-server-certs\n secret:\n secretName: csi-snapshot-metadata-certs\n # end csi volumes/' "$temp_yaml"
270+
sed -i -e 's/# end hostpath args/- \"--enable-snapshot-metadata\"\n # end hostpath args/' "$temp_yaml"
266271
fi
267-
modified="$(cat "$i" | sed -e "s;${default_kubelet_data_dir}/;${KUBELET_DATA_DIR}/;" | while IFS= read -r line; do
272+
modified="$(cat "$temp_yaml" | sed -e "s;${default_kubelet_data_dir}/;${KUBELET_DATA_DIR}/;" | while IFS= read -r line; do
268273
nocomments="$(echo "$line" | sed -e 's/ *#.*$//')"
269274
if echo "$nocomments" | grep -q '^[[:space:]]*image:[[:space:]]*'; then
270275
# Split 'image: quay.io/k8scsi/csi-attacher:v1.0.1'

0 commit comments

Comments
 (0)