diff --git a/go.mod b/go.mod index b5e79d5ca7..0ed5c3b148 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4 v4.3.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0 github.com/Azure/go-autorest/autorest v0.11.29 - github.com/Azure/go-autorest/autorest/date v0.3.0 github.com/Azure/go-autorest/autorest/mocks v0.4.2 github.com/container-storage-interface/spec v1.9.0 github.com/golang/protobuf v1.5.3 @@ -56,6 +55,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.5.0 // indirect github.com/Azure/go-autorest v14.2.0+incompatible // indirect github.com/Azure/go-autorest/autorest/adal v0.9.23 // indirect + github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect diff --git a/pkg/azuredisk/azuredisk.go b/pkg/azuredisk/azuredisk.go index c41132e24a..382561f216 100644 --- a/pkg/azuredisk/azuredisk.go +++ b/pkg/azuredisk/azuredisk.go @@ -450,19 +450,23 @@ func (d *DriverCore) getHostUtil() hostUtil { } // getSnapshotCompletionPercent returns the completion percent of snapshot -func (d *DriverCore) getSnapshotCompletionPercent(ctx context.Context, subsID, resourceGroup, snapshotName string) (float64, error) { - copySnapshot, rerr := d.cloud.SnapshotsClient.Get(ctx, subsID, resourceGroup, snapshotName) - if rerr != nil { - return 0.0, rerr.Error() +func (d *DriverCore) getSnapshotCompletionPercent(ctx context.Context, subsID, resourceGroup, snapshotName string) (float32, error) { + snapshotClient, err := d.clientFactory.GetSnapshotClientForSub(subsID) + if err != nil { + return 0.0, err + } + copySnapshot, err := snapshotClient.Get(ctx, resourceGroup, snapshotName) + if err != nil { + return 0.0, err } - if copySnapshot.SnapshotProperties == nil || copySnapshot.SnapshotProperties.CompletionPercent == nil { + if copySnapshot.Properties == nil || copySnapshot.Properties.CompletionPercent == nil { // If CompletionPercent is nil, it means the snapshot is complete klog.V(2).Infof("snapshot(%s) under rg(%s) has no SnapshotProperties or CompletionPercent is nil", snapshotName, resourceGroup) return 100.0, nil } - return *copySnapshot.SnapshotProperties.CompletionPercent, nil + return *copySnapshot.Properties.CompletionPercent, nil } // waitForSnapshotReady wait for completionPercent of snapshot is 100.0 @@ -472,7 +476,7 @@ func (d *DriverCore) waitForSnapshotReady(ctx context.Context, subsID, resourceG return err } - if completionPercent >= float64(100.0) { + if completionPercent >= float32(100.0) { klog.V(2).Infof("snapshot(%s) under rg(%s) complete", snapshotName, resourceGroup) return nil } @@ -487,7 +491,7 @@ func (d *DriverCore) waitForSnapshotReady(ctx context.Context, subsID, resourceG return err } - if completionPercent >= float64(100.0) { + if completionPercent >= float32(100.0) { klog.V(2).Infof("snapshot(%s) under rg(%s) complete", snapshotName, resourceGroup) return nil } diff --git a/pkg/azuredisk/azuredisk_test.go b/pkg/azuredisk/azuredisk_test.go index a7ab924b64..1eccb9fc85 100644 --- a/pkg/azuredisk/azuredisk_test.go +++ b/pkg/azuredisk/azuredisk_test.go @@ -27,7 +27,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" - "github.com/Azure/go-autorest/autorest/date" "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" "golang.org/x/sync/errgroup" @@ -38,10 +37,9 @@ import ( consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants" "sigs.k8s.io/cloud-provider-azure/pkg/azclient/diskclient/mock_diskclient" "sigs.k8s.io/cloud-provider-azure/pkg/azclient/mock_azclient" - "sigs.k8s.io/cloud-provider-azure/pkg/azureclients/snapshotclient/mocksnapshotclient" + "sigs.k8s.io/cloud-provider-azure/pkg/azclient/snapshotclient/mock_snapshotclient" "sigs.k8s.io/cloud-provider-azure/pkg/azureclients/vmclient/mockvmclient" azure "sigs.k8s.io/cloud-provider-azure/pkg/provider" - "sigs.k8s.io/cloud-provider-azure/pkg/retry" ) func TestNewDriverV1(t *testing.T) { @@ -323,17 +321,15 @@ func TestWaitForSnapshot(t *testing.T) { intervel := 1 * time.Millisecond timeout := 10 * time.Millisecond snapshotID := "test" - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{}, - ID: &snapshotID} + snapshot := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{}, + ID: &snapshotID} ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - rerr := &retry.Error{ - RawError: fmt.Errorf("invalid snapshotID"), - } - mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, rerr).AnyTimes() + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(subID).Return(mockSnapshotClient, nil).AnyTimes() + + mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, fmt.Errorf("invalid snapshotID")).AnyTimes() err := d.waitForSnapshotReady(context.Background(), subID, resourceGroup, snapshotID, intervel, timeout) wantErr := true @@ -362,21 +358,22 @@ func TestWaitForSnapshot(t *testing.T) { snapshotID := "test" location := "loc" provisioningState := "succeeded" - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - TimeCreated: &date.Time{}, + snapshot := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + TimeCreated: &time.Time{}, ProvisioningState: &provisioningState, DiskSizeGB: &DiskSize, - CreationData: &compute.CreationData{SourceResourceID: &volumeID}, - CompletionPercent: pointer.Float64(0.0), + CreationData: &armcompute.CreationData{SourceResourceID: &volumeID}, + CompletionPercent: pointer.Float32(0.0), }, Location: &location, ID: &snapshotID} ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, nil).AnyTimes() + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(subID).Return(mockSnapshotClient, nil).AnyTimes() + + mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, nil).AnyTimes() err := d.waitForSnapshotReady(context.Background(), subID, resourceGroup, snapshotID, intervel, timeout) wantErr := true @@ -405,21 +402,21 @@ func TestWaitForSnapshot(t *testing.T) { snapshotID := "test" location := "loc" provisioningState := "succeeded" - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - TimeCreated: &date.Time{}, + snapshot := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + TimeCreated: &time.Time{}, ProvisioningState: &provisioningState, DiskSizeGB: &DiskSize, - CreationData: &compute.CreationData{SourceResourceID: &volumeID}, - CompletionPercent: pointer.Float64(100.0), + CreationData: &armcompute.CreationData{SourceResourceID: &volumeID}, + CompletionPercent: pointer.Float32(100.0), }, Location: &location, ID: &snapshotID} ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, nil).AnyTimes() + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(subID).Return(mockSnapshotClient, nil).AnyTimes() + mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, nil).AnyTimes() err := d.waitForSnapshotReady(context.Background(), subID, resourceGroup, snapshotID, intervel, timeout) wantErr := false diff --git a/pkg/azuredisk/controllerserver.go b/pkg/azuredisk/controllerserver.go index d72292590f..fd697d8633 100644 --- a/pkg/azuredisk/controllerserver.go +++ b/pkg/azuredisk/controllerserver.go @@ -25,8 +25,8 @@ import ( "strings" "time" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" "github.com/container-storage-interface/spec/lib/go/csi" "google.golang.org/grpc/codes" @@ -957,10 +957,10 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ tags[k] = &value } - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - CreationData: &compute.CreationData{ - CreateOption: compute.Copy, + snapshot := armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + CreationData: &armcompute.CreationData{ + CreateOption: to.Ptr(armcompute.DiskCreateOptionCopy), SourceResourceID: &sourceVolumeID, }, Incremental: &incremental, @@ -973,7 +973,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ if err := azureutils.ValidateDataAccessAuthMode(dataAccessAuthMode); err != nil { return nil, status.Error(codes.InvalidArgument, err.Error()) } - snapshot.SnapshotProperties.DataAccessAuthMode = compute.DataAccessAuthMode(dataAccessAuthMode) + snapshot.Properties.DataAccessAuthMode = to.Ptr(armcompute.DataAccessAuthMode(dataAccessAuthMode)) } if acquired := d.volumeLocks.TryAcquire(snapshotName); !acquired { @@ -1002,13 +1002,17 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ }() klog.V(2).Infof("begin to create snapshot(%s, incremental: %v) under rg(%s) region(%s)", snapshotName, incremental, resourceGroup, d.cloud.Location) - if rerr := d.cloud.SnapshotsClient.CreateOrUpdate(ctx, subsID, resourceGroup, snapshotName, snapshot); rerr != nil { - if strings.Contains(rerr.Error().Error(), "existing disk") { - return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("request snapshot(%s) under rg(%s) already exists, but the SourceVolumeId is different, error details: %v", snapshotName, resourceGroup, rerr.Error())) + snapshotClient, err := d.clientFactory.GetSnapshotClientForSub(subsID) + if err != nil { + return nil, status.Errorf(codes.Internal, "could not get snapshot client for subscription(%s) with error(%v)", subsID, err) + } + if _, err := snapshotClient.CreateOrUpdate(ctx, resourceGroup, snapshotName, snapshot); err != nil { + if strings.Contains(err.Error(), "existing disk") { + return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("request snapshot(%s) under rg(%s) already exists, but the SourceVolumeId is different, error details: %v", snapshotName, resourceGroup, err)) } - azureutils.SleepIfThrottled(rerr.Error(), consts.SnapshotOpThrottlingSleepSec) - return nil, status.Error(codes.Internal, fmt.Sprintf("create snapshot error: %v", rerr.Error())) + azureutils.SleepIfThrottled(err, consts.SnapshotOpThrottlingSleepSec) + return nil, status.Error(codes.Internal, fmt.Sprintf("create snapshot error: %v", err.Error())) } if d.shouldWaitForSnapshotReady { @@ -1025,24 +1029,24 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ if crossRegionSnapshotName != "" { copySnapshot := snapshot - if copySnapshot.SnapshotProperties == nil { - copySnapshot.SnapshotProperties = &compute.SnapshotProperties{} + if copySnapshot.Properties == nil { + copySnapshot.Properties = &armcompute.SnapshotProperties{} } - if copySnapshot.SnapshotProperties.CreationData == nil { - copySnapshot.SnapshotProperties.CreationData = &compute.CreationData{} + if copySnapshot.Properties.CreationData == nil { + copySnapshot.Properties.CreationData = &armcompute.CreationData{} } - copySnapshot.SnapshotProperties.CreationData.SourceResourceID = &csiSnapshot.SnapshotId - copySnapshot.SnapshotProperties.CreationData.CreateOption = compute.CopyStart + copySnapshot.Properties.CreationData.SourceResourceID = &csiSnapshot.SnapshotId + copySnapshot.Properties.CreationData.CreateOption = to.Ptr(armcompute.DiskCreateOptionCopyStart) copySnapshot.Location = &location klog.V(2).Infof("begin to create snapshot(%s, incremental: %v) under rg(%s) region(%s)", crossRegionSnapshotName, incremental, resourceGroup, location) - if rerr := d.cloud.SnapshotsClient.CreateOrUpdate(ctx, subsID, resourceGroup, crossRegionSnapshotName, copySnapshot); rerr != nil { - if strings.Contains(rerr.Error().Error(), "existing disk") { - return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("request snapshot(%s) under rg(%s) already exists, but the SourceVolumeId is different, error details: %v", crossRegionSnapshotName, resourceGroup, rerr.Error())) + if _, err := snapshotClient.CreateOrUpdate(ctx, resourceGroup, crossRegionSnapshotName, copySnapshot); err != nil { + if strings.Contains(err.Error(), "existing disk") { + return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("request snapshot(%s) under rg(%s) already exists, but the SourceVolumeId is different, error details: %v", crossRegionSnapshotName, resourceGroup, err)) } - azureutils.SleepIfThrottled(rerr.Error(), consts.SnapshotOpThrottlingSleepSec) - return nil, status.Error(codes.Internal, fmt.Sprintf("create snapshot error: %v", rerr.Error())) + azureutils.SleepIfThrottled(err, consts.SnapshotOpThrottlingSleepSec) + return nil, status.Error(codes.Internal, fmt.Sprintf("create snapshot error: %v", err)) } klog.V(2).Infof("create snapshot(%s) under rg(%s) region(%s) successfully", crossRegionSnapshotName, resourceGroup, location) @@ -1051,9 +1055,9 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ } klog.V(2).Infof("begin to delete snapshot(%s) under rg(%s) region(%s)", snapshotName, resourceGroup, d.cloud.Location) - if rerr := d.cloud.SnapshotsClient.Delete(ctx, subsID, resourceGroup, snapshotName); rerr != nil { - klog.Errorf("delete snapshot error: %v", rerr.Error()) - azureutils.SleepIfThrottled(rerr.Error(), consts.SnapshotOpThrottlingSleepSec) + if err = snapshotClient.Delete(ctx, resourceGroup, snapshotName); err != nil { + klog.Errorf("delete snapshot error: %v", err) + azureutils.SleepIfThrottled(err, consts.SnapshotOpThrottlingSleepSec) } else { klog.V(2).Infof("delete snapshot(%s) under rg(%s) region(%s) successfully", snapshotName, resourceGroup, d.cloud.Location) } @@ -1097,9 +1101,13 @@ func (d *Driver) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequ }() klog.V(2).Infof("begin to delete snapshot(%s) under rg(%s)", snapshotName, resourceGroup) - if rerr := d.cloud.SnapshotsClient.Delete(ctx, subsID, resourceGroup, snapshotName); rerr != nil { - azureutils.SleepIfThrottled(rerr.Error(), consts.SnapshotOpThrottlingSleepSec) - return nil, status.Error(codes.Internal, fmt.Sprintf("delete snapshot error: %v", rerr.Error())) + snapshotClient, err := d.clientFactory.GetSnapshotClientForSub(subsID) + if err != nil { + return nil, status.Errorf(codes.Internal, "could not get snapshot client for subscription(%s) with error(%v)", subsID, err) + } + if err := snapshotClient.Delete(ctx, resourceGroup, snapshotName); err != nil { + azureutils.SleepIfThrottled(err, consts.SnapshotOpThrottlingSleepSec) + return nil, status.Error(codes.Internal, fmt.Sprintf("delete snapshot error: %v", err)) } klog.V(2).Infof("delete snapshot(%s) under rg(%s) successfully", snapshotName, resourceGroup) isOperationSucceeded = true @@ -1127,9 +1135,9 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques } return listSnapshotResp, nil } - + snapshotClient := d.clientFactory.GetSnapshotClient() // no SnapshotId is set, return all snapshots that satisfy the request. - snapshots, err := d.cloud.SnapshotsClient.ListByResourceGroup(ctx, "", d.cloud.ResourceGroup) + snapshots, err := snapshotClient.List(ctx, d.cloud.ResourceGroup) if err != nil { return nil, status.Error(codes.Internal, fmt.Sprintf("Unknown list snapshot error: %v", err.Error())) } @@ -1146,13 +1154,16 @@ func (d *Driver) getSnapshotByID(ctx context.Context, subsID, resourceGroup, sna return nil, status.Errorf(codes.Internal, err.Error()) } } - - snapshot, rerr := d.cloud.SnapshotsClient.Get(ctx, subsID, resourceGroup, snapshotName) - if rerr != nil { - return nil, status.Error(codes.Internal, fmt.Sprintf("get snapshot %s from rg(%s) error: %v", snapshotName, resourceGroup, rerr.Error())) + snapshotClient, err := d.clientFactory.GetSnapshotClientForSub(subsID) + if err != nil { + return nil, status.Errorf(codes.Internal, "could not get snapshot client for subscription(%s) with error(%v)", subsID, err) + } + snapshot, err := snapshotClient.Get(ctx, resourceGroup, snapshotName) + if err != nil { + return nil, status.Error(codes.Internal, fmt.Sprintf("get snapshot %s from rg(%s) error: %v", snapshotName, resourceGroup, err)) } - return azureutils.GenerateCSISnapshot(sourceVolumeID, &snapshot) + return azureutils.GenerateCSISnapshot(sourceVolumeID, snapshot) } // GetSourceDiskSize recursively searches for the sourceDisk and returns: sourceDisk disk size, error diff --git a/pkg/azuredisk/controllerserver_test.go b/pkg/azuredisk/controllerserver_test.go index b18720c4a1..1f46182487 100644 --- a/pkg/azuredisk/controllerserver_test.go +++ b/pkg/azuredisk/controllerserver_test.go @@ -21,11 +21,11 @@ import ( "fmt" "reflect" "testing" + "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" - "github.com/Azure/go-autorest/autorest/date" "github.com/container-storage-interface/spec/lib/go/csi" "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" @@ -41,7 +41,7 @@ import ( volumehelper "sigs.k8s.io/azuredisk-csi-driver/pkg/util" "sigs.k8s.io/cloud-provider-azure/pkg/azclient/diskclient/mock_diskclient" "sigs.k8s.io/cloud-provider-azure/pkg/azclient/mock_azclient" - "sigs.k8s.io/cloud-provider-azure/pkg/azureclients/snapshotclient/mocksnapshotclient" + "sigs.k8s.io/cloud-provider-azure/pkg/azclient/snapshotclient/mock_snapshotclient" "sigs.k8s.io/cloud-provider-azure/pkg/azureclients/vmclient/mockvmclient" azure "sigs.k8s.io/cloud-provider-azure/pkg/provider" "sigs.k8s.io/cloud-provider-azure/pkg/retry" @@ -1274,15 +1274,12 @@ func TestCreateSnapshot(t *testing.T) { d.setCloud(&azure.Cloud{}) ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - rerr := &retry.Error{ - RawError: fmt.Errorf("test"), - } - mockSnapshotClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(rerr).AnyTimes() + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(gomock.Any()).Return(mockSnapshotClient, nil).AnyTimes() + mockSnapshotClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("test")).AnyTimes() _, err := d.CreateSnapshot(context.Background(), req) - expectedErr := status.Errorf(codes.Internal, "create snapshot error: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: test") + expectedErr := status.Errorf(codes.Internal, "create snapshot error: test") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) } @@ -1304,14 +1301,11 @@ func TestCreateSnapshot(t *testing.T) { d.setCloud(&azure.Cloud{}) ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - rerr := &retry.Error{ - RawError: fmt.Errorf("existing disk"), - } - mockSnapshotClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(rerr).AnyTimes() + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(gomock.Any()).Return(mockSnapshotClient, nil).AnyTimes() + mockSnapshotClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("existing disk")).AnyTimes() _, err := d.CreateSnapshot(context.Background(), req) - expectedErr := status.Errorf(codes.AlreadyExists, "request snapshot(snapname) under rg(rg) already exists, but the SourceVolumeId is different, error details: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: existing disk") + expectedErr := status.Errorf(codes.AlreadyExists, "request snapshot(snapname) under rg(rg) already exists, but the SourceVolumeId is different, error details: existing disk") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) } @@ -1333,16 +1327,14 @@ func TestCreateSnapshot(t *testing.T) { d.setCloud(&azure.Cloud{}) ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - rerr := &retry.Error{ - RawError: fmt.Errorf("get snapshot error"), - } - snapshot := compute.Snapshot{} - mockSnapshotClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() - mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, rerr).AnyTimes() + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(gomock.Any()).Return(mockSnapshotClient, nil).AnyTimes() + + snapshot := &armcompute.Snapshot{} + mockSnapshotClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, fmt.Errorf("get snapshot error")).AnyTimes() _, err := d.CreateSnapshot(context.Background(), req) - expectedErr := status.Errorf(codes.Internal, "waitForSnapshotReady(, rg, unit-test) failed with Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: get snapshot error") + expectedErr := status.Errorf(codes.Internal, "waitForSnapshotReady(, rg, unit-test) failed with get snapshot error") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) } @@ -1364,28 +1356,28 @@ func TestCreateSnapshot(t *testing.T) { d.setCloud(&azure.Cloud{}) ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(gomock.Any()).Return(mockSnapshotClient, nil).AnyTimes() provisioningState := "succeeded" DiskSize := int32(10) snapshotID := "test" - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - TimeCreated: &date.Time{}, + snapshot := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + TimeCreated: &time.Time{}, ProvisioningState: &provisioningState, DiskSizeGB: &DiskSize, }, ID: &snapshotID, } - mockSnapshotClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() - mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, nil).AnyTimes() + mockSnapshotClient.EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, nil).AnyTimes() actualresponse, err := d.CreateSnapshot(context.Background(), req) - tp := timestamppb.New(snapshot.SnapshotProperties.TimeCreated.ToTime()) + tp := timestamppb.New(*snapshot.Properties.TimeCreated) ready := true expectedresponse := &csi.CreateSnapshotResponse{ Snapshot: &csi.Snapshot{ - SizeBytes: volumehelper.GiBToBytes(int64(*snapshot.SnapshotProperties.DiskSizeGB)), + SizeBytes: volumehelper.GiBToBytes(int64(*snapshot.Properties.DiskSizeGB)), SnapshotId: *snapshot.ID, SourceVolumeId: req.SourceVolumeId, CreationTime: tp, @@ -1449,16 +1441,13 @@ func TestDeleteSnapshot(t *testing.T) { d.setCloud(&azure.Cloud{}) ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(gomock.Any()).Return(mockSnapshotClient, nil).AnyTimes() req := &csi.DeleteSnapshotRequest{ SnapshotId: "testurl/subscriptions/12/resourceGroups/23/providers/Microsoft.Compute/snapshots/snapshot-name", } - rerr := &retry.Error{ - RawError: fmt.Errorf("get snapshot error"), - } - mockSnapshotClient.EXPECT().Delete(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(rerr).AnyTimes() - expectedErr := status.Errorf(codes.Internal, "delete snapshot error: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: get snapshot error") + mockSnapshotClient.EXPECT().Delete(gomock.Any(), gomock.Any(), gomock.Any()).Return(fmt.Errorf("get snapshot error")).AnyTimes() + expectedErr := status.Errorf(codes.Internal, "delete snapshot error: get snapshot error") _, err := d.DeleteSnapshot(context.Background(), req) if !reflect.DeepEqual(err, expectedErr) { t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) @@ -1474,12 +1463,12 @@ func TestDeleteSnapshot(t *testing.T) { d.setCloud(&azure.Cloud{}) ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(gomock.Any()).Return(mockSnapshotClient, nil).AnyTimes() req := &csi.DeleteSnapshotRequest{ SnapshotId: "testurl/subscriptions/12/resourceGroups/23/providers/Microsoft.Compute/snapshots/snapshot-name", } - mockSnapshotClient.EXPECT().Delete(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() + mockSnapshotClient.EXPECT().Delete(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() _, err := d.DeleteSnapshot(context.Background(), req) if !reflect.DeepEqual(err, nil) { t.Errorf("actualErr: (%v), expectedErr: nil)", err) @@ -1523,18 +1512,15 @@ func TestGetSnapshotByID(t *testing.T) { d.setCloud(&azure.Cloud{}) ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - rerr := &retry.Error{ - RawError: fmt.Errorf("test"), - } + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(gomock.Any()).Return(mockSnapshotClient, nil).AnyTimes() snapshotID := "testurl/subscriptions/23/providers/Microsoft.Compute/snapshots/snapshot-name" - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{}, - ID: &snapshotID, + snapshot := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{}, + ID: &snapshotID, } snapshotVolumeID := "unit-test" - mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, rerr).AnyTimes() + mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, fmt.Errorf("test")).AnyTimes() expectedErr := status.Errorf(codes.Internal, "could not get snapshot name from testurl/subscriptions/23/providers/Microsoft.Compute/snapshots/snapshot-name, correct format: (?i).*/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Compute/snapshots/(.+)") _, err := d.getSnapshotByID(context.Background(), d.getCloud().SubscriptionID, d.getCloud().ResourceGroup, snapshotID, snapshotVolumeID) if !reflect.DeepEqual(err, expectedErr) { @@ -1581,9 +1567,9 @@ func TestListSnapshots(t *testing.T) { provisioningState := "succeeded" DiskSize := int32(10) snapshotID := "test" - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - TimeCreated: &date.Time{}, + snapshot := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + TimeCreated: &time.Time{}, ProvisioningState: &provisioningState, DiskSizeGB: &DiskSize, }, @@ -1591,9 +1577,9 @@ func TestListSnapshots(t *testing.T) { } ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, nil).AnyTimes() + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClientForSub(gomock.Any()).Return(mockSnapshotClient, nil).AnyTimes() + mockSnapshotClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshot, nil).AnyTimes() expectedErr := error(nil) _, err := d.ListSnapshots(context.TODO(), &req) if !reflect.DeepEqual(err, expectedErr) { @@ -1608,18 +1594,15 @@ func TestListSnapshots(t *testing.T) { cntl := gomock.NewController(t) defer cntl.Finish() d, _ := NewFakeDriver(cntl) - snapshot := compute.Snapshot{} - snapshots := []compute.Snapshot{} + snapshot := &armcompute.Snapshot{} + snapshots := []*armcompute.Snapshot{} snapshots = append(snapshots, snapshot) ctrl := gomock.NewController(t) defer ctrl.Finish() - rerr := &retry.Error{ - RawError: fmt.Errorf("test"), - } - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - mockSnapshotClient.EXPECT().ListByResourceGroup(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshots, rerr).AnyTimes() - expectedErr := status.Error(codes.Internal, "Unknown list snapshot error: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: test") + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClient().Return(mockSnapshotClient).AnyTimes() + mockSnapshotClient.EXPECT().List(gomock.Any(), gomock.Any()).Return(snapshots, fmt.Errorf("test")).AnyTimes() + expectedErr := status.Error(codes.Internal, "Unknown list snapshot error: test") _, err := d.ListSnapshots(context.TODO(), &req) if !reflect.DeepEqual(err, expectedErr) { t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) @@ -1633,14 +1616,14 @@ func TestListSnapshots(t *testing.T) { cntl := gomock.NewController(t) defer cntl.Finish() d, _ := NewFakeDriver(cntl) - snapshot := compute.Snapshot{} - snapshots := []compute.Snapshot{} + snapshot := &armcompute.Snapshot{} + snapshots := []*armcompute.Snapshot{} snapshots = append(snapshots, snapshot) ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - mockSnapshotClient.EXPECT().ListByResourceGroup(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshots, nil).AnyTimes() + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClient().Return(mockSnapshotClient).AnyTimes() + mockSnapshotClient.EXPECT().List(gomock.Any(), gomock.Any()).Return(snapshots, nil).AnyTimes() expectedErr := fmt.Errorf("failed to generate snapshot entry: snapshot property is nil") _, err := d.ListSnapshots(context.TODO(), &req) if !reflect.DeepEqual(err, expectedErr) { @@ -1659,22 +1642,22 @@ func TestListSnapshots(t *testing.T) { DiskSize := int32(10) snapshotID := "test" provisioningState := "succeeded" - snapshot1 := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - TimeCreated: &date.Time{}, + snapshot1 := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + TimeCreated: &time.Time{}, ProvisioningState: &provisioningState, DiskSizeGB: &DiskSize, - CreationData: &compute.CreationData{SourceResourceID: &volumeID}, + CreationData: &armcompute.CreationData{SourceResourceID: &volumeID}, }, ID: &snapshotID} - snapshot2 := compute.Snapshot{} - snapshots := []compute.Snapshot{} + snapshot2 := &armcompute.Snapshot{} + snapshots := []*armcompute.Snapshot{} snapshots = append(snapshots, snapshot1, snapshot2) ctrl := gomock.NewController(t) defer ctrl.Finish() - mockSnapshotClient := mocksnapshotclient.NewMockInterface(ctrl) - d.getCloud().SnapshotsClient = mockSnapshotClient - mockSnapshotClient.EXPECT().ListByResourceGroup(gomock.Any(), gomock.Any(), gomock.Any()).Return(snapshots, nil).AnyTimes() + mockSnapshotClient := mock_snapshotclient.NewMockInterface(ctrl) + d.getClientFactory().(*mock_azclient.MockClientFactory).EXPECT().GetSnapshotClient().Return(mockSnapshotClient).AnyTimes() + mockSnapshotClient.EXPECT().List(gomock.Any(), gomock.Any()).Return(snapshots, nil).AnyTimes() snapshotsResponse, _ := d.ListSnapshots(context.TODO(), &req) if len(snapshotsResponse.Entries) != 1 { t.Errorf("actualNumberOfEntries: (%v), expectedNumberOfEntries: (%v)", len(snapshotsResponse.Entries), 1) diff --git a/pkg/azuredisk/controllerserver_v2.go b/pkg/azuredisk/controllerserver_v2.go index 94aa016bce..cd4f8cad44 100644 --- a/pkg/azuredisk/controllerserver_v2.go +++ b/pkg/azuredisk/controllerserver_v2.go @@ -27,8 +27,8 @@ import ( "strconv" "strings" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" "github.com/container-storage-interface/spec/lib/go/csi" "google.golang.org/grpc/codes" @@ -818,10 +818,10 @@ func (d *DriverV2) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRe tags[k] = &value } - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - CreationData: &compute.CreationData{ - CreateOption: compute.Copy, + snapshot := armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + CreationData: &armcompute.CreationData{ + CreateOption: to.Ptr(armcompute.DiskCreateOptionCopy), SourceResourceID: &sourceVolumeID, }, Incremental: &incremental, @@ -833,7 +833,7 @@ func (d *DriverV2) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRe if err := azureutils.ValidateDataAccessAuthMode(dataAccessAuthMode); err != nil { return nil, status.Error(codes.InvalidArgument, err.Error()) } - snapshot.SnapshotProperties.DataAccessAuthMode = compute.DataAccessAuthMode(dataAccessAuthMode) + snapshot.Properties.DataAccessAuthMode = to.Ptr(armcompute.DataAccessAuthMode(dataAccessAuthMode)) } mc := metrics.NewMetricContext(consts.AzureDiskCSIDriverName, "controller_create_snapshot", d.cloud.ResourceGroup, d.cloud.SubscriptionID, d.Name) @@ -843,13 +843,16 @@ func (d *DriverV2) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRe }() klog.V(2).Infof("begin to create snapshot(%s, incremental: %v) under rg(%s)", snapshotName, incremental, resourceGroup) - if rerr := d.cloud.SnapshotsClient.CreateOrUpdate(ctx, subsID, resourceGroup, snapshotName, snapshot); rerr != nil { - if strings.Contains(rerr.Error().Error(), "existing disk") { - return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("request snapshot(%s) under rg(%s) already exists, but the SourceVolumeId is different, error details: %v", snapshotName, resourceGroup, rerr.Error())) + snapshotClient, err := d.clientFactory.GetSnapshotClientForSub(subsID) + if err != nil { + return nil, status.Errorf(codes.Internal, "could not get snapshot client for subscription(%s) with error(%v)", subsID, err) + } + if _, err := snapshotClient.CreateOrUpdate(ctx, resourceGroup, snapshotName, snapshot); err != nil { + if strings.Contains(err.Error(), "existing disk") { + return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("request snapshot(%s) under rg(%s) already exists, but the SourceVolumeId is different, error details: %v", snapshotName, resourceGroup, err)) } - - azureutils.SleepIfThrottled(rerr.Error(), consts.SnapshotOpThrottlingSleepSec) - return nil, status.Error(codes.Internal, fmt.Sprintf("create snapshot error: %v", rerr.Error())) + azureutils.SleepIfThrottled(err, consts.SnapshotOpThrottlingSleepSec) + return nil, status.Error(codes.Internal, fmt.Sprintf("create snapshot error: %v", err)) } if err := d.waitForSnapshotReady(ctx, subsID, resourceGroup, snapshotName, waitForSnapshotReadyInterval, waitForSnapshotReadyTimeout); err != nil { return nil, status.Error(codes.Internal, fmt.Sprintf("waitForSnapshotReady(%s, %s, %s) failed with %v", subsID, resourceGroup, snapshotName, err)) @@ -894,10 +897,14 @@ func (d *DriverV2) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRe }() klog.V(2).Infof("begin to delete snapshot(%s) under rg(%s)", snapshotName, resourceGroup) - rerr := d.cloud.SnapshotsClient.Delete(ctx, subsID, resourceGroup, snapshotName) - if rerr != nil { - azureutils.SleepIfThrottled(rerr.Error(), consts.SnapshotOpThrottlingSleepSec) - return nil, status.Error(codes.Internal, fmt.Sprintf("delete snapshot error: %v", rerr.Error())) + snapshotClient, err := d.clientFactory.GetSnapshotClientForSub(subsID) + if err != nil { + return nil, status.Errorf(codes.Internal, "could not get snapshot client for subscription(%s) with error(%v)", subsID, err) + } + err = snapshotClient.Delete(ctx, resourceGroup, snapshotName) + if err != nil { + azureutils.SleepIfThrottled(err, consts.SnapshotOpThrottlingSleepSec) + return nil, status.Error(codes.Internal, fmt.Sprintf("delete snapshot error: %v", err)) } klog.V(2).Infof("delete snapshot(%s) under rg(%s) successfully", snapshotName, resourceGroup) isOperationSucceeded = true @@ -925,9 +932,9 @@ func (d *DriverV2) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequ } return listSnapshotResp, nil } - + snapshotClient := d.clientFactory.GetSnapshotClient() // no SnapshotId is set, return all snapshots that satisfy the request. - snapshots, err := d.cloud.SnapshotsClient.ListByResourceGroup(ctx, "", d.cloud.ResourceGroup) + snapshots, err := snapshotClient.List(ctx, d.cloud.ResourceGroup) if err != nil { return nil, status.Error(codes.Internal, fmt.Sprintf("Unknown list snapshot error: %v", err.Error())) } @@ -944,13 +951,16 @@ func (d *DriverV2) getSnapshotByID(ctx context.Context, subsID, resourceGroup, s return nil, status.Errorf(codes.Internal, err.Error()) } } - - snapshot, rerr := d.cloud.SnapshotsClient.Get(ctx, subsID, resourceGroup, snapshotName) + snapshotClient, err := d.clientFactory.GetSnapshotClientForSub(subsID) + if err != nil { + return nil, status.Errorf(codes.Internal, "could not get snapshot client for subscription(%s) with error(%v)", subsID, err) + } + snapshot, rerr := snapshotClient.Get(ctx, resourceGroup, snapshotName) if rerr != nil { return nil, status.Error(codes.Internal, fmt.Sprintf("get snapshot %s from rg(%s) error: %v", snapshotName, resourceGroup, rerr.Error())) } - return azureutils.GenerateCSISnapshot(sourceVolumeID, &snapshot) + return azureutils.GenerateCSISnapshot(sourceVolumeID, snapshot) } // GetSourceDiskSize recursively searches for the sourceDisk and returns: sourceDisk disk size, error diff --git a/pkg/azureutils/azure_disk_utils_test.go b/pkg/azureutils/azure_disk_utils_test.go index 5716160a56..b62b6ec8f6 100644 --- a/pkg/azureutils/azure_disk_utils_test.go +++ b/pkg/azureutils/azure_disk_utils_test.go @@ -29,7 +29,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" "github.com/container-storage-interface/spec/lib/go/csi" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -570,13 +569,13 @@ func TestGetSourceVolumeID(t *testing.T) { SourceResourceID := "test" tests := []struct { - snapshot *compute.Snapshot + snapshot *armcompute.Snapshot expected string }{ { - snapshot: &compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - CreationData: &compute.CreationData{ + snapshot: &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + CreationData: &armcompute.CreationData{ SourceResourceID: &SourceResourceID, }, }, @@ -584,21 +583,21 @@ func TestGetSourceVolumeID(t *testing.T) { expected: "test", }, { - snapshot: &compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - CreationData: &compute.CreationData{}, + snapshot: &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + CreationData: &armcompute.CreationData{}, }, }, expected: "", }, { - snapshot: &compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{}, + snapshot: &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{}, }, expected: "", }, { - snapshot: &compute.Snapshot{}, + snapshot: &armcompute.Snapshot{}, expected: "", }, { @@ -1698,7 +1697,7 @@ func TestInsertDiskProperties(t *testing.T) { SKU: &armcompute.DiskSKU{Name: to.Ptr(armcompute.DiskStorageAccountTypesPremiumLRS)}, }, inputMap: map[string]string{}, - expectedMap: map[string]string{"skuname": string(compute.PremiumLRS)}, + expectedMap: map[string]string{"skuname": string(armcompute.DiskStorageAccountTypesPremiumLRS)}, }, { desc: "DiskProperties", @@ -1717,8 +1716,8 @@ func TestInsertDiskProperties(t *testing.T) { }, inputMap: map[string]string{}, expectedMap: map[string]string{ - consts.SkuNameField: string(compute.StandardSSDLRS), - consts.NetworkAccessPolicyField: string(compute.AllowPrivate), + consts.SkuNameField: string(armcompute.DiskStorageAccountTypesStandardSSDLRS), + consts.NetworkAccessPolicyField: string(armcompute.NetworkAccessPolicyAllowPrivate), consts.DiskIOPSReadWriteField: "6400", consts.DiskMBPSReadWriteField: "100", consts.LogicalSectorSizeField: "512", diff --git a/pkg/azureutils/azure_snapshot_utils.go b/pkg/azureutils/azure_snapshot_utils.go index fba3c2fc41..7456a89b8e 100644 --- a/pkg/azureutils/azure_snapshot_utils.go +++ b/pkg/azureutils/azure_snapshot_utils.go @@ -21,7 +21,7 @@ import ( "strconv" "strings" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "github.com/container-storage-interface/spec/lib/go/csi" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -29,29 +29,29 @@ import ( volumehelper "sigs.k8s.io/azuredisk-csi-driver/pkg/util" ) -func GenerateCSISnapshot(sourceVolumeID string, snapshot *compute.Snapshot) (*csi.Snapshot, error) { - if snapshot == nil || snapshot.SnapshotProperties == nil { +func GenerateCSISnapshot(sourceVolumeID string, snapshot *armcompute.Snapshot) (*csi.Snapshot, error) { + if snapshot == nil || snapshot.Properties == nil { return nil, fmt.Errorf("snapshot property is nil") } - if snapshot.SnapshotProperties.TimeCreated == nil { + if snapshot.Properties.TimeCreated == nil { return nil, fmt.Errorf("TimeCreated of snapshot property is nil") } - if snapshot.SnapshotProperties.DiskSizeGB == nil { + if snapshot.Properties.DiskSizeGB == nil { return nil, fmt.Errorf("diskSizeGB of snapshot property is nil") } - ready, _ := isCSISnapshotReady(*snapshot.SnapshotProperties.ProvisioningState) + ready, _ := isCSISnapshotReady(*snapshot.Properties.ProvisioningState) if sourceVolumeID == "" { sourceVolumeID = GetSourceVolumeID(snapshot) } return &csi.Snapshot{ - SizeBytes: volumehelper.GiBToBytes(int64(*snapshot.SnapshotProperties.DiskSizeGB)), + SizeBytes: volumehelper.GiBToBytes(int64(*snapshot.Properties.DiskSizeGB)), SnapshotId: *snapshot.ID, SourceVolumeId: sourceVolumeID, - CreationTime: timestamppb.New(snapshot.SnapshotProperties.TimeCreated.ToTime()), + CreationTime: timestamppb.New(*snapshot.Properties.TimeCreated), ReadyToUse: ready, }, nil } @@ -61,7 +61,7 @@ func GenerateCSISnapshot(sourceVolumeID string, snapshot *compute.Snapshot) (*cs // 2. StartingToken is null, and MaxEntries is not null. Return `MaxEntries` snapshots from zero. // 3. StartingToken is not null, and MaxEntries is null. Return all snapshots from `StartingToken`. // 4. StartingToken is not null, and MaxEntries is not null. Return `MaxEntries` snapshots from `StartingToken`. -func GetEntriesAndNextToken(req *csi.ListSnapshotsRequest, snapshots []compute.Snapshot) (*csi.ListSnapshotsResponse, error) { +func GetEntriesAndNextToken(req *csi.ListSnapshotsRequest, snapshots []*armcompute.Snapshot) (*csi.ListSnapshotsResponse, error) { if req == nil { return nil, status.Errorf(codes.Aborted, "request is nil") } @@ -88,8 +88,8 @@ func GetEntriesAndNextToken(req *csi.ListSnapshotsRequest, snapshots []compute.S } entries := []*csi.ListSnapshotsResponse_Entry{} for count := 0; start < len(snapshots) && count < maxEntries; start++ { - if (req.SourceVolumeId != "" && req.SourceVolumeId == GetSourceVolumeID(&snapshots[start])) || req.SourceVolumeId == "" { - csiSnapshot, err := GenerateCSISnapshot(req.SourceVolumeId, &snapshots[start]) + if (req.SourceVolumeId != "" && req.SourceVolumeId == GetSourceVolumeID(snapshots[start])) || req.SourceVolumeId == "" { + csiSnapshot, err := GenerateCSISnapshot(req.SourceVolumeId, snapshots[start]) if err != nil { return nil, fmt.Errorf("failed to generate snapshot entry: %v", err) } @@ -119,12 +119,12 @@ func GetSnapshotNameFromURI(snapshotURI string) (string, error) { return matches[1], nil } -func GetSourceVolumeID(snapshot *compute.Snapshot) string { +func GetSourceVolumeID(snapshot *armcompute.Snapshot) string { if snapshot != nil && - snapshot.SnapshotProperties != nil && - snapshot.SnapshotProperties.CreationData != nil && - snapshot.SnapshotProperties.CreationData.SourceResourceID != nil { - return *snapshot.SnapshotProperties.CreationData.SourceResourceID + snapshot.Properties != nil && + snapshot.Properties.CreationData != nil && + snapshot.Properties.CreationData.SourceResourceID != nil { + return *snapshot.Properties.CreationData.SourceResourceID } return "" } diff --git a/pkg/azureutils/azure_snapshot_utils_test.go b/pkg/azureutils/azure_snapshot_utils_test.go index 676e2f5f6e..0d8cc68148 100644 --- a/pkg/azureutils/azure_snapshot_utils_test.go +++ b/pkg/azureutils/azure_snapshot_utils_test.go @@ -20,9 +20,9 @@ import ( "fmt" "reflect" "testing" + "time" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" - "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "github.com/container-storage-interface/spec/lib/go/csi" "github.com/stretchr/testify/assert" "google.golang.org/grpc/codes" @@ -39,9 +39,9 @@ func TestGenerateCSISnapshot(t *testing.T) { { name: "snap shot property not exist", testFunc: func(t *testing.T) { - snapshot := compute.Snapshot{} + snapshot := &armcompute.Snapshot{} sourceVolumeID := "unit-test" - _, err := GenerateCSISnapshot(sourceVolumeID, &snapshot) + _, err := GenerateCSISnapshot(sourceVolumeID, snapshot) expectedErr := fmt.Errorf("snapshot property is nil") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) @@ -52,14 +52,14 @@ func TestGenerateCSISnapshot(t *testing.T) { name: "diskSizeGB of snapshot property is nil", testFunc: func(t *testing.T) { provisioningState := "true" - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - TimeCreated: &date.Time{}, + snapshot := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + TimeCreated: &time.Time{}, ProvisioningState: &provisioningState, }, } sourceVolumeID := "unit-test" - _, err := GenerateCSISnapshot(sourceVolumeID, &snapshot) + _, err := GenerateCSISnapshot(sourceVolumeID, snapshot) expectedErr := fmt.Errorf("diskSizeGB of snapshot property is nil") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr) @@ -72,9 +72,9 @@ func TestGenerateCSISnapshot(t *testing.T) { provisioningState := "succeeded" DiskSize := int32(10) snapshotID := "test" - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - TimeCreated: &date.Time{}, + snapshot := armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + TimeCreated: &time.Time{}, ProvisioningState: &provisioningState, DiskSizeGB: &DiskSize, }, @@ -82,10 +82,10 @@ func TestGenerateCSISnapshot(t *testing.T) { } sourceVolumeID := "unit-test" response, err := GenerateCSISnapshot(sourceVolumeID, &snapshot) - tp := timestamppb.New(snapshot.SnapshotProperties.TimeCreated.ToTime()) + tp := timestamppb.New(*snapshot.Properties.TimeCreated) ready := true expectedresponse := &csi.Snapshot{ - SizeBytes: volumehelper.GiBToBytes(int64(*snapshot.SnapshotProperties.DiskSizeGB)), + SizeBytes: volumehelper.GiBToBytes(int64(*snapshot.Properties.DiskSizeGB)), SnapshotId: *snapshot.ID, SourceVolumeId: sourceVolumeID, CreationTime: tp, @@ -104,23 +104,23 @@ func TestGenerateCSISnapshot(t *testing.T) { DiskSize := int32(10) snapshotID := "test" sourceResourceID := "unit test" - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - TimeCreated: &date.Time{}, + snapshot := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + TimeCreated: &time.Time{}, ProvisioningState: &provisioningState, DiskSizeGB: &DiskSize, - CreationData: &compute.CreationData{ + CreationData: &armcompute.CreationData{ SourceResourceID: &sourceResourceID, }, }, ID: &snapshotID, } sourceVolumeID := "" - response, err := GenerateCSISnapshot(sourceVolumeID, &snapshot) - tp := timestamppb.New(snapshot.SnapshotProperties.TimeCreated.ToTime()) + response, err := GenerateCSISnapshot(sourceVolumeID, snapshot) + tp := timestamppb.New(*snapshot.Properties.TimeCreated) ready := true expectedresponse := &csi.Snapshot{ - SizeBytes: volumehelper.GiBToBytes(int64(*snapshot.SnapshotProperties.DiskSizeGB)), + SizeBytes: volumehelper.GiBToBytes(int64(*snapshot.Properties.DiskSizeGB)), SnapshotId: *snapshot.ID, SourceVolumeId: sourceResourceID, CreationTime: tp, @@ -145,32 +145,32 @@ func TestGetEntriesAndNextToken(t *testing.T) { DiskSize := int32(10) snapshotID := "test" sourceVolumeID := "unit-test" - creationdate := compute.CreationData{ + creationdate := armcompute.CreationData{ SourceResourceID: &sourceVolumeID, } - snapshot := compute.Snapshot{ - SnapshotProperties: &compute.SnapshotProperties{ - TimeCreated: &date.Time{}, + snapshot := &armcompute.Snapshot{ + Properties: &armcompute.SnapshotProperties{ + TimeCreated: &time.Time{}, ProvisioningState: &provisioningState, DiskSizeGB: &DiskSize, CreationData: &creationdate, }, ID: &snapshotID, } - snapshots := []compute.Snapshot{} + snapshots := []*armcompute.Snapshot{} snapshots = append(snapshots, snapshot) entries := []*csi.ListSnapshotsResponse_Entry{} - csiSnapshot, _ := GenerateCSISnapshot(sourceVolumeID, &snapshot) + csiSnapshot, _ := GenerateCSISnapshot(sourceVolumeID, snapshot) entries = append(entries, &csi.ListSnapshotsResponse_Entry{Snapshot: csiSnapshot}) tests := []struct { request *csi.ListSnapshotsRequest - snapshots []compute.Snapshot + snapshots []*armcompute.Snapshot expectedResponse *csi.ListSnapshotsResponse expectedError error }{ { nil, - []compute.Snapshot{}, + []*armcompute.Snapshot{}, nil, status.Errorf(codes.Aborted, "request is nil"), }, @@ -179,7 +179,7 @@ func TestGetEntriesAndNextToken(t *testing.T) { MaxEntries: 2, StartingToken: "a", }, - []compute.Snapshot{}, + []*armcompute.Snapshot{}, nil, status.Errorf(codes.Aborted, "ListSnapshots starting token(a) parsing with error: strconv.Atoi: parsing \"a\": invalid syntax"), }, @@ -188,7 +188,7 @@ func TestGetEntriesAndNextToken(t *testing.T) { MaxEntries: 2, StartingToken: "01", }, - []compute.Snapshot{}, + []*armcompute.Snapshot{}, nil, status.Errorf(codes.Aborted, "ListSnapshots starting token(1) is greater than total number of snapshots"), }, @@ -197,7 +197,7 @@ func TestGetEntriesAndNextToken(t *testing.T) { MaxEntries: 2, StartingToken: "0", }, - []compute.Snapshot{}, + []*armcompute.Snapshot{}, nil, status.Errorf(codes.Aborted, "ListSnapshots starting token(0) is greater than total number of snapshots"), }, @@ -206,7 +206,7 @@ func TestGetEntriesAndNextToken(t *testing.T) { MaxEntries: 2, StartingToken: "-1", }, - []compute.Snapshot{}, + []*armcompute.Snapshot{}, nil, status.Errorf(codes.Aborted, "ListSnapshots starting token(-1) can not be negative"), }, @@ -215,7 +215,7 @@ func TestGetEntriesAndNextToken(t *testing.T) { MaxEntries: 2, StartingToken: "0", }, - append([]compute.Snapshot{}, compute.Snapshot{}), + append([]*armcompute.Snapshot{}, &armcompute.Snapshot{}), nil, fmt.Errorf("failed to generate snapshot entry: %v", fmt.Errorf("snapshot property is nil")), }, diff --git a/pkg/tool/gen-disk-skus-map.go b/pkg/tool/gen-disk-skus-map.go index 2016132f63..6f6783cb70 100644 --- a/pkg/tool/gen-disk-skus-map.go +++ b/pkg/tool/gen-disk-skus-map.go @@ -26,7 +26,7 @@ import ( "strconv" "strings" - compute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" "k8s.io/klog/v2" "sigs.k8s.io/azuredisk-csi-driver/pkg/optimization" @@ -88,7 +88,7 @@ import ( skuMap := map[string]bool{} - var resources []compute.ResourceSku + var resources []*armcompute.ResourceSKU if err := getAllSkus(skusFullfilePath); err != nil { klog.Errorf("Could not get skus. Error: %v", err) @@ -134,7 +134,7 @@ import ( if _, ok := diskSkuInfoMap[account]; !ok { diskSkuInfoMap[account] = map[string]optimization.DiskSkuInfo{} } - diskSkuInfoMap[account][diskSize], err = getDiskCapabilities(&sku) + diskSkuInfoMap[account][diskSize], err = getDiskCapabilities(sku) if err != nil { klog.Errorf("populateSkuMap: Failed to get disk capabilities for disk %s %s %s. Error: %v", *sku.Name, *sku.Size, *sku.Tier, err) os.Exit(1) @@ -143,7 +143,7 @@ import ( nodeInfo := optimization.NodeInfo{} nodeInfo.SkuName = *sku.Name - err = populateNodeCapabilities(&sku, &nodeInfo) + err = populateNodeCapabilities(sku, &nodeInfo) if err != nil { klog.Errorf("populateSkuMap: Failed to populate node capabilities. Error: %v", err) os.Exit(1) @@ -236,9 +236,9 @@ func getAllSkus(filePath string) (err error) { } // populateNodeCapabilities populates node capabilities from SkuInfo -func populateNodeCapabilities(sku *compute.ResourceSku, nodeInfo *optimization.NodeInfo) (err error) { +func populateNodeCapabilities(sku *armcompute.ResourceSKU, nodeInfo *optimization.NodeInfo) (err error) { if sku.Capabilities != nil { - for _, capability := range *sku.Capabilities { + for _, capability := range sku.Capabilities { err = nil if capability.Name != nil { switch strings.ToLower(*capability.Name) { @@ -279,14 +279,14 @@ func populateNodeCapabilities(sku *compute.ResourceSku, nodeInfo *optimization.N } // getDiskCapabilities gets disk capabilities from SkuInfo -func getDiskCapabilities(sku *compute.ResourceSku) (diskSku optimization.DiskSkuInfo, err error) { +func getDiskCapabilities(sku *armcompute.ResourceSKU) (diskSku optimization.DiskSkuInfo, err error) { diskSku = optimization.DiskSkuInfo{} diskSku.StorageAccountType = *sku.Name diskSku.StorageTier = *sku.Tier diskSku.DiskSize = *sku.Size if sku.Capabilities != nil { - for _, capability := range *sku.Capabilities { + for _, capability := range sku.Capabilities { err = nil if capability.Name != nil { switch strings.ToLower(*capability.Name) { diff --git a/vendor/modules.txt b/vendor/modules.txt index f980ec3392..86b448e7a4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1655,6 +1655,7 @@ sigs.k8s.io/cloud-provider-azure/pkg/azclient/routetableclient sigs.k8s.io/cloud-provider-azure/pkg/azclient/secretclient sigs.k8s.io/cloud-provider-azure/pkg/azclient/securitygroupclient sigs.k8s.io/cloud-provider-azure/pkg/azclient/snapshotclient +sigs.k8s.io/cloud-provider-azure/pkg/azclient/snapshotclient/mock_snapshotclient sigs.k8s.io/cloud-provider-azure/pkg/azclient/sshpublickeyresourceclient sigs.k8s.io/cloud-provider-azure/pkg/azclient/subnetclient sigs.k8s.io/cloud-provider-azure/pkg/azclient/utils diff --git a/vendor/sigs.k8s.io/cloud-provider-azure/pkg/azclient/snapshotclient/mock_snapshotclient/interface.go b/vendor/sigs.k8s.io/cloud-provider-azure/pkg/azclient/snapshotclient/mock_snapshotclient/interface.go new file mode 100644 index 0000000000..b7b6e97021 --- /dev/null +++ b/vendor/sigs.k8s.io/cloud-provider-azure/pkg/azclient/snapshotclient/mock_snapshotclient/interface.go @@ -0,0 +1,116 @@ +// /* +// Copyright The Kubernetes Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// */ + +// Code generated by MockGen. DO NOT EDIT. +// Source: snapshotclient/interface.go +// +// Generated by this command: +// +// mockgen -package mock_snapshotclient -source snapshotclient/interface.go +// + +// Package mock_snapshotclient is a generated GoMock package. +package mock_snapshotclient + +import ( + context "context" + reflect "reflect" + + armcompute "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" + gomock "go.uber.org/mock/gomock" +) + +// MockInterface is a mock of Interface interface. +type MockInterface struct { + ctrl *gomock.Controller + recorder *MockInterfaceMockRecorder +} + +// MockInterfaceMockRecorder is the mock recorder for MockInterface. +type MockInterfaceMockRecorder struct { + mock *MockInterface +} + +// NewMockInterface creates a new mock instance. +func NewMockInterface(ctrl *gomock.Controller) *MockInterface { + mock := &MockInterface{ctrl: ctrl} + mock.recorder = &MockInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { + return m.recorder +} + +// CreateOrUpdate mocks base method. +func (m *MockInterface) CreateOrUpdate(ctx context.Context, resourceGroupName, resourceName string, resourceParam armcompute.Snapshot) (*armcompute.Snapshot, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateOrUpdate", ctx, resourceGroupName, resourceName, resourceParam) + ret0, _ := ret[0].(*armcompute.Snapshot) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateOrUpdate indicates an expected call of CreateOrUpdate. +func (mr *MockInterfaceMockRecorder) CreateOrUpdate(ctx, resourceGroupName, resourceName, resourceParam any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdate", reflect.TypeOf((*MockInterface)(nil).CreateOrUpdate), ctx, resourceGroupName, resourceName, resourceParam) +} + +// Delete mocks base method. +func (m *MockInterface) Delete(ctx context.Context, resourceGroupName, resourceName string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", ctx, resourceGroupName, resourceName) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockInterfaceMockRecorder) Delete(ctx, resourceGroupName, resourceName any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockInterface)(nil).Delete), ctx, resourceGroupName, resourceName) +} + +// Get mocks base method. +func (m *MockInterface) Get(ctx context.Context, resourceGroupName, resourceName string) (*armcompute.Snapshot, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", ctx, resourceGroupName, resourceName) + ret0, _ := ret[0].(*armcompute.Snapshot) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockInterfaceMockRecorder) Get(ctx, resourceGroupName, resourceName any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockInterface)(nil).Get), ctx, resourceGroupName, resourceName) +} + +// List mocks base method. +func (m *MockInterface) List(ctx context.Context, resourceGroupName string) ([]*armcompute.Snapshot, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", ctx, resourceGroupName) + ret0, _ := ret[0].([]*armcompute.Snapshot) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockInterfaceMockRecorder) List(ctx, resourceGroupName any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockInterface)(nil).List), ctx, resourceGroupName) +}