Skip to content

bash script to migrate standalone pvs/pvcs to a new volumePath #1365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

badri-pathak
Copy link
Member

@badri-pathak badri-pathak commented Jul 26, 2025

Pull request checklist

The script is going to handle the feature request of the following EPIC and Stories
[Story] Bash script to migrate PVC's from standalone CSI to CNSA in vanilla kubernetes for version-1 volumes
[Epic] Handle existing volume migration due to primaryfs removal in CSI 3.0.0
[Epic] Enable PVC Migration from CSI Standalone to CNSA Deployment in Vanilla Kubernetes


Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature Enhancement
  • Test Automation
  • Code Refactoring (no functional changes, no api changes)
  • Build related changes
  • Community Operator listing
  • Other (please describe):

What is the current behavior?

  • Currently, all PersistentVolumes (PVs) created by the standalone CSI driver have volumeHandle values that include paths based on either the primary fileset or consistency group, such as:
"volumeHandle": "0;2;13009550825755318848;9A7B0B0A:68891B40;;pvc-ec2b7bc4-3253-4aaa-ad42-4ca88914919d;/ibm/fs1/spectrum-scale-csi-volume-store/.volumes/pvc-ec2b7bc4-3253-4aaa-ad42-4ca88914919d"

This format is specific to the standalone CSI deployment.

What is the new behavior?

  • To support migration to the CNSA-based Kubernetes setup or New CSI setup after primaryfs removal, we need to update all existing PVs to use the CNSA-compatible/New CSI setup volumeHandle format. This format includes a new mount path and structure expected by CNSANew CSI setup, for example:
e.g. VolumeId: 0;2;13009550825755318848;9A7B0B0A:68891B40;;pvc-ec2b7bc4-3253-4aaa-ad42-4ca88914919d;/var/mnt/remotefs1/pvc-ec2b7bc4-3253-4aaa-ad42-4ca88914919d/pvc-ec2b7bc4-3253-4aaa-ad42-4ca88914919d-data

Migration Script

A helper script is provided to automate this PV migration:

# Usage: ./migration_pv_pvc.bash --new_path_prefix /var/mnt

Where:
- `/var/mnt` is the path where the all the fileset is mounted on the CNSA/New CSI storage cluster.

This script updates the volumeHandle values in PV definitions and re-creates the associated PVCs to be compatible with CNSA-based/New CSI setup deployments.

Features of the Migration Script:

  • Automatically filters PVs using the spectrumscale.csi.ibm.com driver.
  • Skips already-migrated PVs (those with /var/mnt/ in the volumeHandle).
  • Takes backup of each PV and PVC before modification:
csi_migration_data/
└── <timestamp>/
    ├── migration.log
    ├── <pvc-name-1>/
    │   ├── pvc.yaml
    │   └── pv.yaml
    ├── <pvc-name-2>/
    │   ├── pvc.yaml
    │   └── pv.yaml
    └── ...

  • Logs all actions, successes, and failures to:
csi_migration_data/migration.log
  • Summarizes total successful, skipped and failed migrations at the end with names.

Note/Limitation

  • The CNSA/New CSI setup must use the same remote filesystem names as those configured earlier in the standalone CSI setup. Consistency in filesystem names is required for proper volume migration and access.

How risky is this change?

  • Small, isolated change
  • Medium, requires regression testing
  • Large, requires functional and regression testing

@badri-pathak badri-pathak changed the title adding script to migrate csi to cnsa k8s env [WIP] adding script to migrate csi to cnsa k8s env Jul 26, 2025
@badri-pathak badri-pathak changed the title [WIP] adding script to migrate csi to cnsa k8s env bash script to migrate standalone pvs/pvcs to cnsa k8s pvs/pvcs env Jul 29, 2025
@badri-pathak
Copy link
Member Author

Tested examples are.
image

@badri-pathak badri-pathak changed the title bash script to migrate standalone pvs/pvcs to cnsa k8s pvs/pvcs env bash script to migrate standalone pvs/pvcs to cnsa k8s pvs/pvcs env for version1 independent fsets Aug 1, 2025
@badri-pathak badri-pathak changed the title bash script to migrate standalone pvs/pvcs to cnsa k8s pvs/pvcs env for version1 independent fsets bash script to migrate standalone pvs/pvcs to cnsa k8s pvs/pvcs env for version1 fsets Aug 2, 2025
@badri-pathak badri-pathak changed the title bash script to migrate standalone pvs/pvcs to cnsa k8s pvs/pvcs env for version1 fsets bash script to migrate standalone pvs/pvcs to a new volumePath Aug 4, 2025
Copy link
Member

@saurabhwani5 saurabhwani5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@badri-pathak I am adding my suggestions here :
if user give path with / in end as mount path consider /var/mnt/ instead of /var, will it impact CSI operations as volume handle path will be /var/mnt//

@saurabhwani5
Copy link
Member

I was trying this script on 4 pvcs of version 1 independent -> source pvc , clone , restored pvc and shallow volume
But script is getting terminated after 1 st pvc only and it is not changing path of other pvcs , I had given path /var/mnt but it is working for one pvc only

[root@saurabhrhel9-master 1365]# bash migration_pv_pvc.bash --new_path_prefix /var/mnt
Using the new path prefix: /var/mnt
The new volume handle volumePath will be: /var/mnt/<RemoteFS>/...

Proceed with migration? (yes/y/Y to continue): y
Logging to csi_migration_data/20250812_020542/migration.log
Starting migration at: Tue Aug 12 02:05:42 AM PDT 2025

Found 4 PVs using spectrumscale.csi.ibm.com driver

[1/4]  --------------------------------------------------------------------------------
Processing PV: pvc-168116ca-3f96-40f0-baa8-81c0c64cea82
Current volumeHandle: 0;2;6734525309045651944;272C0B0A:688B3AD6;;pvc-168116ca-3f96-40f0-baa8-81c0c64cea82;/var/mnt/newfs1/pvc-168116ca-3f96-40f0-baa8-81c0c64cea82/pvc-168116ca-3f96-40f0-baa8-81c0c64cea82-data
Preparing to migrate PVC: ibm-spectrum-scale-pvc-from-snapshot in namespace ibm-spectrum-scale-csi-driver
Detected volumeHandle type: 0;2 (fileset) : Fileset volume and independent fileset
Already migrated (volumeHandle matches target). Skipping pvc-168116ca-3f96-40f0-baa8-81c0c64cea82


[root@saurabhrhel9-master 1365]# oc describe pv | grep VolumeHandle
    VolumeHandle:      0;2;6734525309045651944;272C0B0A:688B3AD6;;pvc-168116ca-3f96-40f0-baa8-81c0c64cea82;/var/mnt/newfs1/pvc-168116ca-3f96-40f0-baa8-81c0c64cea82/pvc-168116ca-3f96-40f0-baa8-81c0c64cea82-data
    VolumeHandle:      0;2;6734525309045651944;272C0B0A:688B3AD6;;pvc-3e3093b7-be2b-407a-83fe-25d99af224eb;/ibm/newfs1/pvc-3e3093b7-be2b-407a-83fe-25d99af224eb/pvc-3e3093b7-be2b-407a-83fe-25d99af224eb-data
    VolumeHandle:      0;2;6734525309045651944;272C0B0A:688B3AD6;;pvc-9c88d531-c7ac-46eb-b575-ed547184c1df;/ibm/newfs1/pvc-9c88d531-c7ac-46eb-b575-ed547184c1df/pvc-9c88d531-c7ac-46eb-b575-ed547184c1df-data
    VolumeHandle:      0;3;6734525309045651944;272C0B0A:688B3AD6;;pvc-ac6e091a-3257-4ca4-8c48-ac66bee7f2d8;/ibm/newfs1/pvc-9c88d531-c7ac-46eb-b575-ed547184c1df/.snapshots/snapshot-ceff0dd3-4ade-48b8-a2ae-4040f031f83a/pvc-9c88d531-c7ac-46eb-b575-ed547184c1df-data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants