Skip to content

Commit f1d5544

Browse files
committed
feat: support nfs volume clone and snapshot restore
1 parent 257194a commit f1d5544

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

pkg/azurefile/azurefile.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,9 +1109,6 @@ func (d *Driver) ResizeFileShare(ctx context.Context, subsID, resourceGroup, acc
11091109

11101110
// copyFileShare copies a fileshare, if dstAccountName is empty, then copy in the same account
11111111
func (d *Driver) copyFileShare(ctx context.Context, req *csi.CreateVolumeRequest, dstAccountName string, dstAccountSasToken string, authAzcopyEnv []string, secretNamespace string, shareOptions *ShareOptions, accountOptions *storage.AccountOptions, storageEndpointSuffix string) error {
1112-
if shareOptions.Protocol == armstorage.EnabledProtocolsNFS {
1113-
return fmt.Errorf("protocol nfs is not supported for volume cloning")
1114-
}
11151112
var sourceVolumeID string
11161113
if req.GetVolumeContentSource() != nil && req.GetVolumeContentSource().GetVolume() != nil {
11171114
sourceVolumeID = req.GetVolumeContentSource().GetVolume().GetVolumeId()
@@ -1143,7 +1140,7 @@ func (d *Driver) copyFileShare(ctx context.Context, req *csi.CreateVolumeRequest
11431140
srcPath := fmt.Sprintf("https://%s.file.%s/%s%s", srcAccountName, storageEndpointSuffix, srcFileShareName, srcAccountSasToken)
11441141
dstPath := fmt.Sprintf("https://%s.file.%s/%s%s", dstAccountName, storageEndpointSuffix, dstFileShareName, dstAccountSasToken)
11451142

1146-
return d.copyFileShareByAzcopy(ctx, srcFileShareName, dstFileShareName, srcPath, dstPath, "", srcAccountName, dstAccountName, srcAccountSasToken, authAzcopyEnv, accountOptions)
1143+
return d.copyFileShareByAzcopy(ctx, srcFileShareName, dstFileShareName, srcPath, dstPath, "", srcAccountName, dstAccountName, srcAccountSasToken, authAzcopyEnv, shareOptions, accountOptions)
11471144
}
11481145

11491146
// GetTotalAccountQuota returns the total quota in GB of all file shares in the storage account and the number of file shares

pkg/azurefile/controllerserver.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,9 +1111,6 @@ func (d *Driver) ListSnapshots(_ context.Context, _ *csi.ListSnapshotsRequest) (
11111111

11121112
// restoreSnapshot restores from a snapshot
11131113
func (d *Driver) restoreSnapshot(ctx context.Context, req *csi.CreateVolumeRequest, dstAccountName, dstAccountSasToken string, authAzcopyEnv []string, secretNamespace string, shareOptions *ShareOptions, accountOptions *storage.AccountOptions, storageEndpointSuffix string) error {
1114-
if shareOptions.Protocol == armstorage.EnabledProtocolsNFS {
1115-
return fmt.Errorf("protocol nfs is not supported for snapshot restore")
1116-
}
11171114
var sourceSnapshotID string
11181115
if req.GetVolumeContentSource() != nil && req.GetVolumeContentSource().GetSnapshot() != nil {
11191116
sourceSnapshotID = req.GetVolumeContentSource().GetSnapshot().GetSnapshotId()
@@ -1154,10 +1151,10 @@ func (d *Driver) restoreSnapshot(ctx context.Context, req *csi.CreateVolumeReque
11541151
dstPath := fmt.Sprintf("https://%s.file.%s/%s%s", dstAccountName, storageEndpointSuffix, dstFileShareName, dstAccountSasToken)
11551152

11561153
srcFileShareSnapshotName := fmt.Sprintf("%s(snapshot: %s)", srcFileShareName, snapshot)
1157-
return d.copyFileShareByAzcopy(ctx, srcFileShareSnapshotName, dstFileShareName, srcPath, dstPath, snapshot, srcAccountName, dstAccountName, srcAccountSasToken, authAzcopyEnv, accountOptions)
1154+
return d.copyFileShareByAzcopy(ctx, srcFileShareSnapshotName, dstFileShareName, srcPath, dstPath, snapshot, srcAccountName, dstAccountName, srcAccountSasToken, authAzcopyEnv, shareOptions, accountOptions)
11581155
}
11591156

1160-
func (d *Driver) copyFileShareByAzcopy(ctx context.Context, srcFileShareName, dstFileShareName, srcPath, dstPath, snapshot, srcAccountName, dstAccountName, accountSASToken string, authAzcopyEnv []string, accountOptions *storage.AccountOptions) error {
1157+
func (d *Driver) copyFileShareByAzcopy(ctx context.Context, srcFileShareName, dstFileShareName, srcPath, dstPath, snapshot, srcAccountName, dstAccountName, accountSASToken string, authAzcopyEnv []string, shareOptions *ShareOptions, accountOptions *storage.AccountOptions) error {
11611158
azcopyCopyOptions := azcopyCloneVolumeOptions
11621159
srcPathAuth := srcPath
11631160
if snapshot != "" {
@@ -1169,6 +1166,10 @@ func (d *Driver) copyFileShareByAzcopy(ctx context.Context, srcFileShareName, ds
11691166
}
11701167
}
11711168

1169+
if shareOptions.Protocol == armstorage.EnabledProtocolsNFS {
1170+
azcopyCopyOptions = append(azcopyCopyOptions, "--nfs")
1171+
}
1172+
11721173
jobState, percent, err := d.azcopy.GetAzcopyJob(dstFileShareName, authAzcopyEnv)
11731174
klog.V(2).Infof("azcopy job status: %s, copy percent: %s%%, error: %v", jobState, percent, err)
11741175

pkg/azurefileplugin/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ARG ARCH
2222

2323
RUN apt update \
2424
&& apt install -y curl \
25-
&& curl -Ls https://azcopyvnext-awgzd8g7aagqhzhe.b02.azurefd.net/releases/release-10.29.1-20250515/azcopy_linux_${ARCH}_10.29.1.tar.gz \
25+
&& curl -Ls https://github.com/Azure/azure-storage-azcopy/releases/download/v10.30.0-preview.1/azcopy_linux_${ARCH}_10.30.0.preview.1.tar.gz \
2626
| tar xvzf - --strip-components=1 -C /usr/local/bin/ --wildcards "*/azcopy"
2727

2828
FROM base

test/e2e/dynamic_provisioning_test.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
101101
test.Run(ctx, cs, snapshotrcs, ns)
102102
})
103103

104+
ginkgo.It("should create a pod, write and read to it, take a nfs volume snapshot, and create another pod from the snapshot [file.csi.azure.com]", func(ctx ginkgo.SpecContext) {
105+
skipIfUsingInTreeVolumePlugin()
106+
skipIfTestingInWindowsCluster()
107+
108+
pod := testsuites.PodDetails{
109+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
110+
Volumes: []testsuites.VolumeDetails{
111+
{
112+
ClaimSize: "100Gi",
113+
VolumeMount: testsuites.VolumeMountDetails{
114+
NameGenerate: "test-volume-",
115+
MountPathGenerate: "/mnt/test-",
116+
},
117+
},
118+
},
119+
}
120+
podWithSnapshot := testsuites.PodDetails{
121+
Cmd: "grep 'hello world' /mnt/test-1/data",
122+
}
123+
test := testsuites.DynamicallyProvisionedVolumeSnapshotTest{
124+
CSIDriver: testDriver,
125+
Pod: pod,
126+
ShouldOverwrite: false,
127+
ShouldRestore: true,
128+
PodWithSnapshot: podWithSnapshot,
129+
StorageClassParameters: map[string]string{
130+
"skuName": "Premium_LRS",
131+
"protocol": "nfs",
132+
},
133+
}
134+
test.Run(ctx, cs, snapshotrcs, ns)
135+
})
136+
104137
ginkgo.It("should create a pod, write to its pv, take a volume snapshot, overwrite data in original pv, create another pod from the snapshot, use another storage class, and read unaltered original data from original pv[file.csi.azure.com]", func(ctx ginkgo.SpecContext) {
105138
skipIfUsingInTreeVolumePlugin()
106139
skipIfTestingInWindowsCluster()
@@ -1740,7 +1773,7 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
17401773
test.Run(ctx, cs, ns)
17411774
})
17421775

1743-
ginkgo.It("should clone a large size volume from an existing volume [file.csi.azure.com]", func(ctx ginkgo.SpecContext) {
1776+
ginkgo.It("should clone a large size volume from an existing nfs volume [file.csi.azure.com]", func(ctx ginkgo.SpecContext) {
17441777
skipIfTestingInWindowsCluster()
17451778
skipIfTestingInMigrationCluster()
17461779
skipIfUsingInTreeVolumePlugin()
@@ -1765,7 +1798,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
17651798
Pod: pod,
17661799
PodWithClonedVolume: podWithClonedVolume,
17671800
StorageClassParameters: map[string]string{
1768-
"skuName": "Standard_LRS",
1801+
"skuName": "Premium_LRS",
1802+
"protocol": "nfs",
17691803
},
17701804
}
17711805
test.Run(ctx, cs, ns)

0 commit comments

Comments
 (0)