From c2490574ac2a1389b2d6c6d31cf713d6f7a57ff2 Mon Sep 17 00:00:00 2001 From: torredil Date: Thu, 4 Apr 2024 13:32:40 +0000 Subject: [PATCH] Improve relationship between driver and cloud Signed-off-by: torredil --- cmd/main.go | 25 ++- pkg/driver/controller.go | 77 +++----- pkg/driver/controller_modify_volume.go | 12 +- pkg/driver/controller_test.go | 239 +++++++------------------ pkg/driver/driver.go | 36 ++-- pkg/driver/request_coalescing_test.go | 20 +-- 6 files changed, 147 insertions(+), 262 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index d4bfc1825c..fa68fb000f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -24,6 +24,7 @@ import ( "time" "github.com/kubernetes-sigs/aws-ebs-csi-driver/cmd/hooks" + "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud/metadata" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/metrics" @@ -132,7 +133,29 @@ func main() { r.InitializeMetricsHandler(options.HttpEndpoint, "/metrics") } - drv, err := driver.NewDriver(&options) + region := os.Getenv("AWS_REGION") + if region == "" { + klog.V(5).InfoS("[Debug] Retrieving region from metadata service") + cfg := metadata.MetadataServiceConfig{ + EC2MetadataClient: metadata.DefaultEC2MetadataClient, + K8sAPIClient: metadata.DefaultKubernetesAPIClient, + } + metadata, metadataErr := metadata.NewMetadataService(cfg, region) + if metadataErr != nil { + klog.ErrorS(err, "Could not determine region from any metadata service. The region can be manually supplied via the AWS_REGION environment variable.") + panic(err) + } + region = metadata.GetRegion() + } + + klog.InfoS("batching", "status", options.Batching) + cloud, err := cloud.NewCloud(region, options.AwsSdkDebugLog, options.UserAgentExtra, options.Batching) + if err != nil { + klog.ErrorS(err, "failed to create cloud service") + klog.FlushAndExit(klog.ExitFlushTimeout, 1) + } + + drv, err := driver.NewDriver(cloud, &options) if err != nil { klog.ErrorS(err, "failed to create driver") klog.FlushAndExit(klog.ExitFlushTimeout, 1) diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index ae16b4bddd..71ecaa47eb 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "os" "strconv" "strings" @@ -28,7 +27,6 @@ import ( "github.com/awslabs/volume-modifier-for-k8s/pkg/rpc" csi "github.com/container-storage-interface/spec/lib/go/csi" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud" - "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud/metadata" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver/internal" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util/template" @@ -58,59 +56,26 @@ var ( const isManagedByDriver = "true" -// controllerService represents the controller service of CSI driver -type controllerService struct { +// ControllerService represents the controller service of CSI driver +type ControllerService struct { cloud cloud.Cloud inFlight *internal.InFlight options *Options modifyVolumeManager *modifyVolumeManager - rpc.UnimplementedModifyServer } -var ( - // NewMetadataFunc is a variable for the cloud.NewMetadata function that can - // be overwritten in unit tests. - NewMetadataFunc = metadata.NewMetadataService - // NewCloudFunc is a variable for the cloud.NewCloud function that can - // be overwritten in unit tests. - NewCloudFunc = cloud.NewCloud -) - -// newControllerService creates a new controller service -// it panics if failed to create the service -func newControllerService(o *Options) controllerService { - region := os.Getenv("AWS_REGION") - if region == "" { - klog.V(5).InfoS("[Debug] Retrieving region from metadata service") - - cfg := metadata.MetadataServiceConfig{ - EC2MetadataClient: metadata.DefaultEC2MetadataClient, - K8sAPIClient: metadata.DefaultKubernetesAPIClient, - } - metadata, err := NewMetadataFunc(cfg, region) - if err != nil { - klog.ErrorS(err, "Could not determine region from any metadata service. The region can be manually supplied via the AWS_REGION environment variable.") - panic(err) - } - region = metadata.GetRegion() - } - - klog.InfoS("batching", "status", o.Batching) - cloudSrv, err := NewCloudFunc(region, o.AwsSdkDebugLog, o.UserAgentExtra, o.Batching) - if err != nil { - panic(err) - } - - return controllerService{ - cloud: cloudSrv, - inFlight: internal.NewInFlight(), +// NewControllerService creates a new controller service +func NewControllerService(c cloud.Cloud, o *Options) *ControllerService { + return &ControllerService{ + cloud: c, options: o, + inFlight: internal.NewInFlight(), modifyVolumeManager: newModifyVolumeManager(), } } -func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { +func (d *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { klog.V(4).InfoS("CreateVolume: called", "args", *req) if err := validateCreateVolumeRequest(req); err != nil { return nil, err @@ -399,7 +364,7 @@ func validateCreateVolumeRequest(req *csi.CreateVolumeRequest) error { return nil } -func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) { +func (d *ControllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) { klog.V(4).InfoS("DeleteVolume: called", "args", *req) if err := validateDeleteVolumeRequest(req); err != nil { return nil, err @@ -431,7 +396,7 @@ func validateDeleteVolumeRequest(req *csi.DeleteVolumeRequest) error { return nil } -func (d *controllerService) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) { +func (d *ControllerService) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) { klog.V(4).InfoS("ControllerPublishVolume: called", "args", *req) if err := validateControllerPublishVolumeRequest(req); err != nil { return nil, err @@ -480,7 +445,7 @@ func validateControllerPublishVolumeRequest(req *csi.ControllerPublishVolumeRequ return nil } -func (d *controllerService) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) { +func (d *ControllerService) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) { klog.V(4).InfoS("ControllerUnpublishVolume: called", "args", *req) if err := validateControllerUnpublishVolumeRequest(req); err != nil { @@ -520,7 +485,7 @@ func validateControllerUnpublishVolumeRequest(req *csi.ControllerUnpublishVolume return nil } -func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) { +func (d *ControllerService) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) { klog.V(4).InfoS("ControllerGetCapabilities: called", "args", *req) var caps []*csi.ControllerServiceCapability for _, cap := range controllerCaps { @@ -536,17 +501,17 @@ func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req * return &csi.ControllerGetCapabilitiesResponse{Capabilities: caps}, nil } -func (d *controllerService) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) { +func (d *ControllerService) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) { klog.V(4).InfoS("GetCapacity: called", "args", *req) return nil, status.Error(codes.Unimplemented, "") } -func (d *controllerService) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { +func (d *ControllerService) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { klog.V(4).InfoS("ListVolumes: called", "args", *req) return nil, status.Error(codes.Unimplemented, "") } -func (d *controllerService) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) { +func (d *ControllerService) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) { klog.V(4).InfoS("ValidateVolumeCapabilities: called", "args", *req) volumeID := req.GetVolumeId() if len(volumeID) == 0 { @@ -574,7 +539,7 @@ func (d *controllerService) ValidateVolumeCapabilities(ctx context.Context, req }, nil } -func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) { +func (d *ControllerService) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) { klog.V(4).InfoS("ControllerExpandVolume: called", "args", *req) volumeID := req.GetVolumeId() if len(volumeID) == 0 { @@ -627,7 +592,7 @@ func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi }, nil } -func (d *controllerService) ControllerModifyVolume(ctx context.Context, req *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error) { +func (d *ControllerService) ControllerModifyVolume(ctx context.Context, req *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error) { klog.V(4).InfoS("ControllerModifyVolume: called", "args", *req) volumeID := req.GetVolumeId() @@ -648,7 +613,7 @@ func (d *controllerService) ControllerModifyVolume(ctx context.Context, req *csi return &csi.ControllerModifyVolumeResponse{}, nil } -func (d *controllerService) ControllerGetVolume(ctx context.Context, req *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) { +func (d *ControllerService) ControllerGetVolume(ctx context.Context, req *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) { klog.V(4).InfoS("ControllerGetVolume: called", "args", *req) return nil, status.Error(codes.Unimplemented, "") } @@ -706,7 +671,7 @@ func isValidVolumeContext(volContext map[string]string) bool { return true } -func (d *controllerService) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) { +func (d *ControllerService) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) { klog.V(4).InfoS("CreateSnapshot: called", "args", req) if err := validateCreateSnapshotRequest(req); err != nil { return nil, err @@ -835,7 +800,7 @@ func validateCreateSnapshotRequest(req *csi.CreateSnapshotRequest) error { return nil } -func (d *controllerService) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) { +func (d *ControllerService) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) { klog.V(4).InfoS("DeleteSnapshot: called", "args", req) if err := validateDeleteSnapshotRequest(req); err != nil { return nil, err @@ -868,7 +833,7 @@ func validateDeleteSnapshotRequest(req *csi.DeleteSnapshotRequest) error { return nil } -func (d *controllerService) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { +func (d *ControllerService) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { klog.V(4).InfoS("ListSnapshots: called", "args", req) var snapshots []*cloud.Snapshot diff --git a/pkg/driver/controller_modify_volume.go b/pkg/driver/controller_modify_volume.go index 2e910c162b..9e033f39df 100644 --- a/pkg/driver/controller_modify_volume.go +++ b/pkg/driver/controller_modify_volume.go @@ -120,7 +120,7 @@ func (h *modifyVolumeRequestHandler) mergeModifyVolumeRequest(r *modifyVolumeReq // the ec2 API call to the CSI Driver main thread via response channels. // This method receives requests from CSI driver main thread via the request channel. When a new request is received from the request channel, we first // validate the new request. If the new request is acceptable, it will be merged with the existing request for the volume. -func (d *controllerService) processModifyVolumeRequests(h *modifyVolumeRequestHandler, responseChans []chan modifyVolumeResponse) { +func (d *ControllerService) processModifyVolumeRequests(h *modifyVolumeRequestHandler, responseChans []chan modifyVolumeResponse) { klog.V(4).InfoS("Start processing ModifyVolumeRequest for ", "volume ID", h.volumeID) process := func(req *modifyVolumeRequest) { if err := h.validateModifyVolumeRequest(req); err != nil { @@ -167,7 +167,7 @@ func (d *controllerService) processModifyVolumeRequests(h *modifyVolumeRequestHa // If there’s ModifyVolumeRequestHandler for the volume, meaning that there is inflight request(s) for the volume, we will send the new request // to the goroutine for the volume via the receiving channel. // Note that each volume with inflight requests has their own goroutine which follows timeout schedule of their own. -func (d *controllerService) addModifyVolumeRequest(volumeID string, r *modifyVolumeRequest) { +func (d *ControllerService) addModifyVolumeRequest(volumeID string, r *modifyVolumeRequest) { requestHandler := newModifyVolumeRequestHandler(volumeID, r) handler, loaded := d.modifyVolumeManager.requestHandlerMap.LoadOrStore(volumeID, requestHandler) if loaded { @@ -179,7 +179,7 @@ func (d *controllerService) addModifyVolumeRequest(volumeID string, r *modifyVol } } -func (d *controllerService) executeModifyVolumeRequest(volumeID string, req *modifyVolumeRequest) (int32, error) { +func (d *ControllerService) executeModifyVolumeRequest(volumeID string, req *modifyVolumeRequest) (int32, error) { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() actualSizeGiB, err := d.cloud.ResizeOrModifyDisk(ctx, volumeID, req.newSize, &req.modifyDiskOptions) @@ -190,14 +190,14 @@ func (d *controllerService) executeModifyVolumeRequest(volumeID string, req *mod } } -func (d *controllerService) GetCSIDriverModificationCapability( +func (d *ControllerService) GetCSIDriverModificationCapability( _ context.Context, _ *rpc.GetCSIDriverModificationCapabilityRequest, ) (*rpc.GetCSIDriverModificationCapabilityResponse, error) { return &rpc.GetCSIDriverModificationCapabilityResponse{}, nil } -func (d *controllerService) ModifyVolumeProperties( +func (d *ControllerService) ModifyVolumeProperties( ctx context.Context, req *rpc.ModifyVolumePropertiesRequest, ) (*rpc.ModifyVolumePropertiesResponse, error) { @@ -260,7 +260,7 @@ func parseModifyVolumeParameters(params map[string]string) (*cloud.ModifyDiskOpt return &options, nil } -func (d *controllerService) modifyVolumeWithCoalescing(ctx context.Context, volume string, options *cloud.ModifyDiskOptions) error { +func (d *ControllerService) modifyVolumeWithCoalescing(ctx context.Context, volume string, options *cloud.ModifyDiskOptions) error { responseChan := make(chan modifyVolumeResponse) request := modifyVolumeRequest{ modifyDiskOptions: *options, diff --git a/pkg/driver/controller_test.go b/pkg/driver/controller_test.go index a5f1f7b1b9..9ae985b639 100644 --- a/pkg/driver/controller_test.go +++ b/pkg/driver/controller_test.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "math/rand" - "os" "reflect" "strings" "testing" @@ -34,7 +33,6 @@ import ( "github.com/container-storage-interface/spec/lib/go/csi" "github.com/golang/mock/gomock" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud" - "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud/metadata" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver/internal" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util" "github.com/stretchr/testify/assert" @@ -49,107 +47,6 @@ const ( expDevicePath = "/dev/xvda" ) -func TestNewControllerService(t *testing.T) { - - var ( - cloudObj cloud.Cloud - testErr = errors.New("test error") - testRegion = "test-region" - - getNewCloudFunc = func(expectedRegion string, _ bool) func(region string, awsSdkDebugLog bool, userAgentExtra string, batching bool) (cloud.Cloud, error) { - return func(region string, awsSdkDebugLog bool, userAgentExtra string, batching bool) (cloud.Cloud, error) { - if region != expectedRegion { - t.Fatalf("expected region %q but got %q", expectedRegion, region) - } - return cloudObj, nil - } - } - ) - - testCases := []struct { - name string - region string - newCloudFunc func(string, bool, string, bool) (cloud.Cloud, error) - newMetadataFuncErrors bool - expectPanic bool - }{ - { - name: "AWS_REGION variable set, newCloud does not error", - region: "foo", - newCloudFunc: getNewCloudFunc("foo", false), - }, - { - name: "AWS_REGION variable set, newCloud errors", - region: "foo", - newCloudFunc: func(region string, awsSdkDebugLog bool, userAgentExtra string, batching bool) (cloud.Cloud, error) { - return nil, testErr - }, - expectPanic: true, - }, - { - name: "AWS_REGION variable not set, newMetadata does not error", - newCloudFunc: getNewCloudFunc(testRegion, false), - }, - { - name: "AWS_REGION variable not set, newMetadata errors", - newCloudFunc: getNewCloudFunc(testRegion, false), - newMetadataFuncErrors: true, - expectPanic: true, - }, - } - - Options := &Options{ - Endpoint: "test", - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - oldNewCloudFunc := NewCloudFunc - defer func() { NewCloudFunc = oldNewCloudFunc }() - NewCloudFunc = tc.newCloudFunc - - if tc.region == "" { - mockCtl := gomock.NewController(t) - defer mockCtl.Finish() - mockMetadataService := metadata.NewMockMetadataService(mockCtl) - - oldNewMetadataFunc := NewMetadataFunc - defer func() { NewMetadataFunc = oldNewMetadataFunc }() - NewMetadataFunc = func(cfg metadata.MetadataServiceConfig, region string) (metadata.MetadataService, error) { - if tc.newMetadataFuncErrors { - return nil, testErr - } - return mockMetadataService, nil - } - - if !tc.newMetadataFuncErrors { - mockMetadataService.EXPECT().GetRegion().Return(testRegion) - } - } else { - os.Setenv("AWS_REGION", tc.region) - defer os.Unsetenv("AWS_REGION") - } - - if tc.expectPanic { - defer func() { - if r := recover(); r == nil { - t.Errorf("The code did not panic") - } - }() - } - - controllerSvc := newControllerService(Options) - - if controllerSvc.cloud != cloudObj { - t.Fatalf("expected cloud attribute to be equal to instantiated cloud object") - } - if !reflect.DeepEqual(controllerSvc.options, Options) { - t.Fatalf("expected Options attribute to be equal to input") - } - }) - } -} - func TestCreateVolume(t *testing.T) { stdVolCap := []*csi.VolumeCapability{ { @@ -222,7 +119,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -292,7 +189,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -359,7 +256,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -415,7 +312,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -464,7 +361,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(nil, cloud.ErrIdempotentParameterMismatch) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -491,7 +388,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -545,7 +442,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -631,7 +528,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -689,7 +586,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -750,7 +647,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -806,7 +703,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -848,7 +745,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -890,7 +787,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -932,7 +829,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -974,7 +871,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1015,7 +912,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1056,7 +953,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1097,7 +994,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1139,7 +1036,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1188,7 +1085,7 @@ func TestCreateVolume(t *testing.T) { assert.Equal(t, int32(4000), diskOptions.IOPS) return mockDisk, nil }) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1224,7 +1121,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1264,7 +1161,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1304,7 +1201,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1378,7 +1275,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1459,7 +1356,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Eq(diskOptions)).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -1524,7 +1421,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Eq(diskOptions)).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -1590,7 +1487,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Eq(diskOptions)).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1627,7 +1524,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1668,7 +1565,7 @@ func TestCreateVolume(t *testing.T) { inFlight.Insert(req.GetName()) defer inFlight.Delete(req.GetName()) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: inFlight, options: &Options{}, @@ -1696,7 +1593,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(nil, cloud.ErrIdempotentParameterMismatch) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1730,7 +1627,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().CreateDisk(gomock.Eq(ctx), gomock.Eq(req.GetName()), gomock.Any()).Return(mockDisk, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1761,7 +1658,7 @@ func TestCreateVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1922,7 +1819,7 @@ func TestCreateVolumeWithFormattingParameters(t *testing.T) { defer mockCtl.Finish() } - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -1970,7 +1867,7 @@ func TestDeleteVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().DeleteDisk(gomock.Eq(ctx), gomock.Eq(req.GetVolumeId())).Return(true, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2002,7 +1899,7 @@ func TestDeleteVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().DeleteDisk(gomock.Eq(ctx), gomock.Eq(req.GetVolumeId())).Return(false, cloud.ErrNotFound) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2033,7 +1930,7 @@ func TestDeleteVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().DeleteDisk(gomock.Eq(ctx), gomock.Eq(req.GetVolumeId())).Return(false, fmt.Errorf("DeleteDisk could not delete volume")) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2071,7 +1968,7 @@ func TestDeleteVolume(t *testing.T) { inFlight := internal.NewInFlight() inFlight.Insert(req.GetVolumeId()) defer inFlight.Delete(req.GetVolumeId()) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: inFlight, options: &Options{}, @@ -2345,7 +2242,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().CreateSnapshot(gomock.Eq(ctx), gomock.Eq(req.GetSourceVolumeId()), gomock.Any()).Return(mockSnapshot, nil) mockCloud.EXPECT().GetSnapshotByName(gomock.Eq(ctx), gomock.Eq(req.GetName())).Return(nil, cloud.ErrNotFound) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2402,7 +2299,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().CreateSnapshot(gomock.Eq(ctx), gomock.Eq(req.GetSourceVolumeId()), gomock.Eq(snapshotOptions)).Return(mockSnapshot, nil) mockCloud.EXPECT().GetSnapshotByName(gomock.Eq(ctx), gomock.Eq(req.GetName())).Return(nil, cloud.ErrNotFound) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -2457,7 +2354,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().CreateSnapshot(gomock.Eq(ctx), gomock.Eq(req.GetSourceVolumeId()), gomock.Eq(snapshotOptions)).Return(mockSnapshot, nil) mockCloud.EXPECT().GetSnapshotByName(gomock.Eq(ctx), gomock.Eq(req.GetName())).Return(nil, cloud.ErrNotFound) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -2489,7 +2386,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2538,7 +2435,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().GetSnapshotByName(gomock.Eq(ctx), gomock.Eq(req.GetName())).Return(nil, cloud.ErrNotFound) mockCloud.EXPECT().CreateSnapshot(gomock.Eq(ctx), gomock.Eq(req.GetSourceVolumeId()), gomock.Any()).Return(mockSnapshot, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2605,7 +2502,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().GetSnapshotByName(gomock.Eq(ctx), gomock.Eq(req.GetName())).Return(nil, cloud.ErrNotFound) mockCloud.EXPECT().CreateSnapshot(gomock.Eq(ctx), gomock.Eq(req.GetSourceVolumeId()), gomock.Any()).Return(mockSnapshot, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2644,7 +2541,7 @@ func TestCreateSnapshot(t *testing.T) { inFlight.Insert(req.GetName()) defer inFlight.Delete(req.GetName()) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: inFlight, options: &Options{}, @@ -2696,7 +2593,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().CreateSnapshot(gomock.Eq(ctx), gomock.Eq(req.GetSourceVolumeId()), gomock.Eq(snapshotOptions)).Return(mockSnapshot, nil) mockCloud.EXPECT().GetSnapshotByName(gomock.Eq(ctx), gomock.Eq(req.GetName())).Return(nil, cloud.ErrNotFound) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2754,7 +2651,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().CreateSnapshot(gomock.Eq(ctx), gomock.Eq(req.GetSourceVolumeId()), gomock.Eq(snapshotOptions)).Return(mockSnapshot, nil) mockCloud.EXPECT().GetSnapshotByName(gomock.Eq(ctx), gomock.Eq(req.GetName())).Return(nil, cloud.ErrNotFound) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{KubernetesClusterID: clusterId}, @@ -2818,7 +2715,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().CreateSnapshot(gomock.Eq(ctx), gomock.Eq(req.GetSourceVolumeId()), gomock.Eq(snapshotOptions)).Return(mockSnapshot, nil).AnyTimes() mockCloud.EXPECT().EnableFastSnapshotRestores(gomock.Eq(ctx), gomock.Eq([]string{"us-east-1a", "us-east-1f"}), gomock.Eq(mockSnapshot.SnapshotID)).Return(expOutput, nil).AnyTimes() - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2882,7 +2779,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().CreateSnapshot(gomock.Eq(ctx), gomock.Eq(req.GetSourceVolumeId()), gomock.Eq(snapshotOptions)).Return(mockSnapshot, nil).AnyTimes() mockCloud.EXPECT().EnableFastSnapshotRestores(gomock.Eq(ctx), gomock.Eq([]string{"us-east-1a", "us-east-1f"}), gomock.Eq(mockSnapshot.SnapshotID)).Return(expOutput, nil).AnyTimes() - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2951,7 +2848,7 @@ func TestCreateSnapshot(t *testing.T) { Return(expOutput, fmt.Errorf("Failed to create Fast Snapshot Restores")).AnyTimes() mockCloud.EXPECT().DeleteSnapshot(gomock.Eq(ctx), gomock.Eq(mockSnapshot.SnapshotID)).Return(true, nil).AnyTimes() - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -2987,7 +2884,7 @@ func TestCreateSnapshot(t *testing.T) { mockCloud.EXPECT().AvailabilityZones(gomock.Eq(ctx)).Return(map[string]struct{}{ "us-east-1a": {}, "us-east-1b": {}}, nil).AnyTimes() - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3040,7 +2937,7 @@ func TestCreateSnapshot(t *testing.T) { gomock.Eq(mockSnapshot.SnapshotID)).Return(nil, fmt.Errorf("error")).AnyTimes() mockCloud.EXPECT().DeleteSnapshot(gomock.Eq(ctx), gomock.Eq(mockSnapshot.SnapshotID)).Return(true, nil).AnyTimes() - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3073,7 +2970,7 @@ func TestDeleteSnapshot(t *testing.T) { defer mockCtl.Finish() mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3098,7 +2995,7 @@ func TestDeleteSnapshot(t *testing.T) { defer mockCtl.Finish() mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3131,7 +3028,7 @@ func TestDeleteSnapshot(t *testing.T) { inFlight.Insert(req.GetSnapshotId()) defer inFlight.Delete(req.GetSnapshotId()) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: inFlight, options: &Options{}, @@ -3183,7 +3080,7 @@ func TestListSnapshots(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().ListSnapshots(gomock.Eq(ctx), gomock.Eq(""), gomock.Eq(int32(0)), gomock.Eq("")).Return(mockCloudSnapshotsResponse, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3210,7 +3107,7 @@ func TestListSnapshots(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().ListSnapshots(gomock.Eq(ctx), gomock.Eq(""), gomock.Eq(int32(0)), gomock.Eq("")).Return(nil, cloud.ErrNotFound) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3246,7 +3143,7 @@ func TestListSnapshots(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().GetSnapshotByID(gomock.Eq(ctx), gomock.Eq("snapshot-1")).Return(mockCloudSnapshotsResponse, nil) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3276,7 +3173,7 @@ func TestListSnapshots(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().GetSnapshotByID(gomock.Eq(ctx), gomock.Eq("snapshot-1")).Return(nil, cloud.ErrNotFound) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3306,7 +3203,7 @@ func TestListSnapshots(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().GetSnapshotByID(gomock.Eq(ctx), gomock.Eq("snapshot-1")).Return(nil, cloud.ErrMultiSnapshots) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3338,7 +3235,7 @@ func TestListSnapshots(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().ListSnapshots(gomock.Eq(ctx), gomock.Eq(""), gomock.Eq(int32(4)), gomock.Eq("")).Return(nil, cloud.ErrInvalidMaxResults) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3382,7 +3279,7 @@ func TestControllerPublishVolume(t *testing.T) { mockAttach func(mockCloud *cloud.MockCloud, ctx context.Context, volumeId string, nodeId string) expResp *csi.ControllerPublishVolumeResponse errorCode codes.Code - setupFunc func(controllerService *controllerService) + setupFunc func(ControllerService *ControllerService) }{ { name: "AttachDisk successfully with valid volume ID, node ID, and volume capability", @@ -3480,8 +3377,8 @@ func TestControllerPublishVolume(t *testing.T) { mockAttach: func(mockCloud *cloud.MockCloud, ctx context.Context, volumeId string, nodeId string) { }, errorCode: codes.Aborted, - setupFunc: func(controllerService *controllerService) { - controllerService.inFlight.Insert("vol-test" + expInstanceID) + setupFunc: func(ControllerService *ControllerService) { + ControllerService.inFlight.Insert("vol-test" + expInstanceID) }, }, } @@ -3527,7 +3424,7 @@ func TestControllerUnpublishVolume(t *testing.T) { errorCode codes.Code mockDetach func(mockCloud *cloud.MockCloud, ctx context.Context, volumeId string, nodeId string) expResp *csi.ControllerUnpublishVolumeResponse - setupFunc func(driver *controllerService) + setupFunc func(driver *ControllerService) }{ { name: "DetachDisk successfully with valid volume ID and node ID", @@ -3576,7 +3473,7 @@ func TestControllerUnpublishVolume(t *testing.T) { volumeId: "vol-test", nodeId: expInstanceID, errorCode: codes.Aborted, - setupFunc: func(driver *controllerService) { + setupFunc: func(driver *ControllerService) { driver.inFlight.Insert("vol-test" + expInstanceID) }, }, @@ -3669,7 +3566,7 @@ func TestControllerExpandVolume(t *testing.T) { mockCloud := cloud.NewMockCloud(mockCtl) mockCloud.EXPECT().ResizeOrModifyDisk(gomock.Any(), gomock.Eq(tc.req.GetVolumeId()), gomock.Any(), gomock.Any()).Return(retSizeGiB, nil).AnyTimes() - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, @@ -3714,11 +3611,11 @@ func checkExpectedErrorCode(t *testing.T, err error, expectedCode codes.Code) { } } -func createControllerService(t *testing.T) (controllerService, *gomock.Controller, *cloud.MockCloud) { +func createControllerService(t *testing.T) (ControllerService, *gomock.Controller, *cloud.MockCloud) { t.Helper() mockCtl := gomock.NewController(t) mockCloud := cloud.NewMockCloud(mockCtl) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{}, diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index ce9e7a006d..544f8e3fe7 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -23,6 +23,7 @@ import ( "github.com/awslabs/volume-modifier-for-k8s/pkg/rpc" csi "github.com/container-storage-interface/spec/lib/go/csi" + "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "google.golang.org/grpc" @@ -42,12 +43,11 @@ const ( ) const ( - DriverName = "ebs.csi.aws.com" - AwsPartitionKey = "topology." + DriverName + "/partition" - AwsAccountIDKey = "topology." + DriverName + "/account-id" - AwsRegionKey = "topology." + DriverName + "/region" - AwsOutpostIDKey = "topology." + DriverName + "/outpost-id" - + DriverName = "ebs.csi.aws.com" + AwsPartitionKey = "topology." + DriverName + "/partition" + AwsAccountIDKey = "topology." + DriverName + "/account-id" + AwsRegionKey = "topology." + DriverName + "/region" + AwsOutpostIDKey = "topology." + DriverName + "/outpost-id" WellKnownZoneTopologyKey = "topology.kubernetes.io/zone" // DEPRECATED Use the WellKnownZoneTopologyKey instead ZoneTopologyKey = "topology." + DriverName + "/zone" @@ -55,37 +55,36 @@ const ( ) type Driver struct { - controllerService + controller *ControllerService nodeService - srv *grpc.Server options *Options } -func NewDriver(o *Options) (*Driver, error) { +func NewDriver(c cloud.Cloud, o *Options) (*Driver, error) { klog.InfoS("Driver Information", "Driver", DriverName, "Version", driverVersion) if err := ValidateDriverOptions(o); err != nil { return nil, fmt.Errorf("invalid driver options: %w", err) } - driver := Driver{ + driver := &Driver{ options: o, } switch o.Mode { case ControllerMode: - driver.controllerService = newControllerService(o) + driver.controller = NewControllerService(c, o) case NodeMode: driver.nodeService = newNodeService(o) case AllMode: - driver.controllerService = newControllerService(o) + driver.controller = NewControllerService(c, o) driver.nodeService = newNodeService(o) default: return nil, fmt.Errorf("unknown mode: %s", o.Mode) } - return &driver, nil + return driver, nil } func (d *Driver) Run() error { @@ -110,23 +109,24 @@ func (d *Driver) Run() error { opts := []grpc.ServerOption{ grpc.UnaryInterceptor(logErr), } + if d.options.EnableOtelTracing { opts = append(opts, grpc.StatsHandler(otelgrpc.NewServerHandler())) } - d.srv = grpc.NewServer(opts...) + d.srv = grpc.NewServer(opts...) csi.RegisterIdentityServer(d.srv, d) switch d.options.Mode { case ControllerMode: - csi.RegisterControllerServer(d.srv, d) - rpc.RegisterModifyServer(d.srv, d) + csi.RegisterControllerServer(d.srv, d.controller) + rpc.RegisterModifyServer(d.srv, d.controller) case NodeMode: csi.RegisterNodeServer(d.srv, d) case AllMode: - csi.RegisterControllerServer(d.srv, d) + csi.RegisterControllerServer(d.srv, d.controller) csi.RegisterNodeServer(d.srv, d) - rpc.RegisterModifyServer(d.srv, d) + rpc.RegisterModifyServer(d.srv, d.controller) default: return fmt.Errorf("unknown mode: %s", d.options.Mode) } diff --git a/pkg/driver/request_coalescing_test.go b/pkg/driver/request_coalescing_test.go index f306aea1cf..f44c578eb1 100644 --- a/pkg/driver/request_coalescing_test.go +++ b/pkg/driver/request_coalescing_test.go @@ -34,9 +34,9 @@ import ( "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud" ) -type modifyVolumeExecutor func(ctx context.Context, driver controllerService, name string, params map[string]string) error +type modifyVolumeExecutor func(ctx context.Context, driver ControllerService, name string, params map[string]string) error -func externalResizerModifyVolume(ctx context.Context, driver controllerService, name string, params map[string]string) error { +func externalResizerModifyVolume(ctx context.Context, driver ControllerService, name string, params map[string]string) error { _, err := driver.ControllerModifyVolume(ctx, &csi.ControllerModifyVolumeRequest{ VolumeId: name, MutableParameters: params, @@ -44,7 +44,7 @@ func externalResizerModifyVolume(ctx context.Context, driver controllerService, return err } -func modifierForK8sModifyVolume(ctx context.Context, driver controllerService, name string, params map[string]string) error { +func modifierForK8sModifyVolume(ctx context.Context, driver ControllerService, name string, params map[string]string) error { _, err := driver.ModifyVolumeProperties(ctx, &rpc.ModifyVolumePropertiesRequest{ Name: name, Parameters: params, @@ -121,7 +121,7 @@ func testBasicRequestCoalescingSuccess(t *testing.T, executor modifyVolumeExecut return newSize, nil }) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -175,7 +175,7 @@ func testRequestFail(t *testing.T, executor modifyVolumeExecutor) { return 0, fmt.Errorf("ResizeOrModifyDisk failed") }) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -243,7 +243,7 @@ func testPartialFail(t *testing.T, executor modifyVolumeExecutor) { return newSize, nil }) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -324,7 +324,7 @@ func testSequentialRequests(t *testing.T, executor modifyVolumeExecutor) { return newSize, nil }).Times(2) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -381,7 +381,7 @@ func testDuplicateRequest(t *testing.T, executor modifyVolumeExecutor) { return newSize, nil }) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -445,7 +445,7 @@ func testContextTimeout(t *testing.T, executor modifyVolumeExecutor) { return newSize, nil }) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{ @@ -510,7 +510,7 @@ func testResponseReturnTiming(t *testing.T, executor modifyVolumeExecutor) { return newSize, nil }) - awsDriver := controllerService{ + awsDriver := ControllerService{ cloud: mockCloud, inFlight: internal.NewInFlight(), options: &Options{