Skip to content

Commit 822fe02

Browse files
kaovilaiclaude
andcommitted
Fix: Prevent duplicate sidecars by using temp copies instead of sed -i
When SNAPSHOT_METADATA_TESTS=true or VOLUME_MODE_CONVERSION_TESTS=true, the deploy script was modifying git-tracked YAML files in-place using sed -i. This caused issues on subsequent runs: - Run 1: Works fine, adds 1 snapshot-metadata sidecar - Run 2: File already modified, adds another sidecar → duplicate containers - Run 3+: More duplicates → Kubernetes rejects deployment Root cause: - Lines 257, 263-265 used sed -i to modify files directly - Modified files were committed to git or left dirty - Not idempotent - each run added more modifications Solution: - Copy files to TEMP_DIR before modifications - Apply all sed operations to temporary copies - Keep original git-tracked files pristine - Script is now fully idempotent Fixes the bug across all kubernetes-* deployments that use deploy/util/deploy-hostpath.sh as a symlink. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 518b002 commit 822fe02

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)