Skip to content

Commit

Permalink
fix: revert appending subsid into snapshotid
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx committed Jan 8, 2025
1 parent f2fea43 commit 40aec63
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 60 deletions.
7 changes: 3 additions & 4 deletions pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,14 +864,13 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
return nil, status.Error(codes.InvalidArgument, "CreateSnapshot Source Volume ID must be provided")
}

rgName, accountName, fileShareName, _, _, srcVolSubsID, err := GetFileShareInfo(sourceVolumeID) //nolint:dogsled
rgName, accountName, fileShareName, _, _, subsID, err := GetFileShareInfo(sourceVolumeID) //nolint:dogsled
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("GetFileShareInfo(%s) failed with error: %v", sourceVolumeID, err))
}
if rgName == "" {
rgName = d.cloud.ResourceGroup
}
subsID := srcVolSubsID
if subsID == "" {
subsID = d.cloud.SubscriptionID
}
Expand Down Expand Up @@ -908,7 +907,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
return &csi.CreateSnapshotResponse{
Snapshot: &csi.Snapshot{
SizeBytes: volumehelper.GiBToBytes(int64(itemSnapshotQuota)),
SnapshotId: getSnapshotID(srcVolSubsID, sourceVolumeID, itemSnapshot, subsID),
SnapshotId: sourceVolumeID + "#" + itemSnapshot,
SourceVolumeId: sourceVolumeID,
CreationTime: timestamppb.New(itemSnapshotTime),
// Since the snapshot of azurefile has no field of ReadyToUse, here ReadyToUse is always set to true.
Expand Down Expand Up @@ -979,7 +978,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
createResp := &csi.CreateSnapshotResponse{
Snapshot: &csi.Snapshot{
SizeBytes: volumehelper.GiBToBytes(int64(itemSnapshotQuota)),
SnapshotId: getSnapshotID(srcVolSubsID, sourceVolumeID, itemSnapshot, subsID),
SnapshotId: sourceVolumeID + "#" + itemSnapshot,
SourceVolumeId: sourceVolumeID,
CreationTime: timestamppb.New(itemSnapshotTime),
// Since the snapshot of azurefile has no field of ReadyToUse, here ReadyToUse is always set to true.
Expand Down
14 changes: 0 additions & 14 deletions pkg/azurefile/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,3 @@ func isConfidentialRuntimeClass(ctx context.Context, kubeClient clientset.Interf
klog.Infof("runtimeClass %s handler: %s", runtimeClassName, runtimeClass.Handler)
return runtimeClass.Handler == confidentialRuntimeClassHandler, nil
}

// getSnapshotID returns snapshotID based on srcVolSubsID, srcVolumeID, itemSnapshot and subsID
func getSnapshotID(srcVolSubsID, srcVolumeID, itemSnapshot, subsID string) string {
snapshotID := srcVolumeID + "#" + itemSnapshot
if srcVolSubsID == "" {
// if srcVolumeID does not contain subscription id, append it to snapshotID
if strings.HasSuffix(srcVolumeID, "#") {
snapshotID = srcVolumeID + subsID + "#" + itemSnapshot
} else {
snapshotID = srcVolumeID + "#" + subsID + "#" + itemSnapshot
}
}
return snapshotID
}
42 changes: 0 additions & 42 deletions pkg/azurefile/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,48 +815,6 @@ func TestIsConfidentialRuntimeClass(t *testing.T) {
}
}

func TestGetSnapshotID(t *testing.T) {
tests := []struct {
desc string
srcVolumeSubsID string
srcVolumeID string
itemSnapshot string
subsID string
expected string
}{
{
desc: "srcVolumeSubsID contains subsID",
srcVolumeSubsID: "subsID",
srcVolumeID: "rg#f5713de20cde511e8ba4900#fileShareName#diskname.vhd#uuid#namespace#subsID",
itemSnapshot: "snapshot",
expected: "rg#f5713de20cde511e8ba4900#fileShareName#diskname.vhd#uuid#namespace#subsID#snapshot",
},
{
desc: "srcVolumeSubsID is empty",
srcVolumeSubsID: "",
srcVolumeID: "rg#f5713de20cde511e8ba4900#fileShareName#diskname.vhd#uuid#namespace",
itemSnapshot: "snapshot",
subsID: "subsID",
expected: "rg#f5713de20cde511e8ba4900#fileShareName#diskname.vhd#uuid#namespace#subsID#snapshot",
},
{
desc: "srcVolumeSubsID is empty but contains # at the end",
srcVolumeSubsID: "",
srcVolumeID: "rg#f5713de20cde511e8ba4900#fileShareName#diskname.vhd#uuid#namespace#",
itemSnapshot: "snapshot",
subsID: "subsID",
expected: "rg#f5713de20cde511e8ba4900#fileShareName#diskname.vhd#uuid#namespace#subsID#snapshot",
},
}

for _, test := range tests {
result := getSnapshotID(test.srcVolumeSubsID, test.srcVolumeID, test.itemSnapshot, test.subsID)
if result != test.expected {
t.Errorf("test[%s]: unexpected output: %v, expected result: %v", test.desc, result, test.expected)
}
}
}

func TestIsThrottlingError(t *testing.T) {
tests := []struct {
desc string
Expand Down

0 comments on commit 40aec63

Please sign in to comment.