Skip to content

Conversation

@kaovilai
Copy link

@kaovilai kaovilai commented Nov 13, 2025

Description

Fixes #620

This PR prevents the duplicate container bug that occurs when running SNAPSHOT_METADATA_TESTS=true ./deploy.sh or VOLUME_MODE_CONVERSION_TESTS=true ./deploy.sh multiple times.

Problem

The deployment script was using sed -i to modify git-tracked YAML files in-place. Each run would add more sidecars, causing:

  • Run 1: ✅ Works (1 sidecar)
  • Run 2: ❌ Duplicate containers (2 sidecars)
  • Run 3+: ❌ More duplicates → Kubernetes rejects deployment

Solution

Copy files to ${TEMP_DIR} before applying sed modifications:

# Copy to temp first
temp_yaml="${TEMP_DIR}/$(basename "$i")"
cp "$i" "$temp_yaml"

# Apply sed -i to temp copy (not original)
sed -i -e "/# end csi containers/r ${PATCH_FILE}" "$temp_yaml"

This keeps original files pristine and makes the script fully idempotent.

Changes

  • Modified deploy/util/deploy-hostpath.sh lines 257-270
  • All deploy/kubernetes-*/deploy.sh symlinks benefit from this fix

Testing

The script can now be run multiple times without creating duplicate containers. Original git-tracked files remain unchanged.

What type of PR is this?

/kind bug

What this PR does / why we need it:

Fixes deployment script to copy YAML files to temp directory before modifications, preventing duplicate sidecars on subsequent runs.

Which issue(s) this PR fixes:

Fixes #620

Special notes for your reviewer:

The fix is simple: copy files to ${TEMP_DIR} before running sed -i, keeping the same sed syntax but operating on temporary copies instead of git-tracked files.

Does this PR introduce a user-facing change?:

Fixed deployment script to prevent duplicate sidecars when running with SNAPSHOT_METADATA_TESTS=true or VOLUME_MODE_CONVERSION_TESTS=true multiple times

Note

Responses generated with Claude

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 13, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kaovilai
Once this PR has been reviewed and has the lgtm label, please assign saad-ali for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Contributor

Welcome @kaovilai!

It looks like this is your first PR to kubernetes-csi/csi-driver-host-path 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-csi/csi-driver-host-path has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 13, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @kaovilai. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 13, 2025
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 <[email protected]>
@kaovilai kaovilai force-pushed the fix-sed-in-place-modifications branch from d185fc6 to 822fe02 Compare November 13, 2025 19:44
@kaovilai kaovilai changed the title Fix: Prevent duplicate sidecars by using temp copies instead of sed -i Fix: Prevent duplicate sidecars by copying to temp before sed modifications Nov 13, 2025
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 13, 2025
@carlory
Copy link
Member

carlory commented Nov 17, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: deploy.sh creates duplicate sidecars on subsequent runs with SNAPSHOT_METADATA_TESTS=true

3 participants