diff --git a/hack/verify-golint b/hack/verify-golint index 059760e41b..89942cb6b7 100755 --- a/hack/verify-golint +++ b/hack/verify-golint @@ -17,11 +17,11 @@ set -euo pipefail if ! which golangci-lint > /dev/null; then - echo 'Cannot find golangci-lint. Installing golangci-lint...' + echo "Cannot find golangci-lint. Installing golangci-lint..." go get -v github.com/golangci/golangci-lint/cmd/golangci-lint fi golangci-lint run --deadline=10m -echo "Congratulations! All Go source files have been linted.' +echo "Congratulations! All Go source files have been linted." diff --git a/pkg/cloud/cloud.go b/pkg/cloud/cloud.go index a28780a993..d77c10a717 100644 --- a/pkg/cloud/cloud.go +++ b/pkg/cloud/cloud.go @@ -156,15 +156,15 @@ func NewCloud() (Cloud, error) { } awsConfig := &aws.Config{ - Region: aws.String(metadata.GetRegion()), - Credentials: credentials.NewChainCredentials(provider), + Region: aws.String(metadata.GetRegion()), + Credentials: credentials.NewChainCredentials(provider), + CredentialsChainVerboseErrors: aws.Bool(true), } - awsConfig = awsConfig.WithCredentialsChainVerboseErrors(true) return &cloud{ metadata: metadata, dm: dm.NewDeviceManager(), - ec2: ec2.New(session.New(awsConfig)), + ec2: ec2.New(session.Must(session.NewSession(awsConfig))), }, nil } @@ -405,9 +405,7 @@ func (c *cloud) getVolume(ctx context.Context, request *ec2.DescribeVolumesInput if err != nil { return nil, err } - for _, volume := range response.Volumes { - volumes = append(volumes, volume) - } + volumes = append(volumes, response.Volumes...) nextToken = response.NextToken if aws.StringValue(nextToken) == "" { break diff --git a/pkg/cloud/devicemanager/manager.go b/pkg/cloud/devicemanager/manager.go index 2df906f4a5..9bc2a5973a 100644 --- a/pkg/cloud/devicemanager/manager.go +++ b/pkg/cloud/devicemanager/manager.go @@ -46,6 +46,7 @@ func (d *Device) Release(force bool) { } } +// Taint marks the device as no longer reusable func (d *Device) Taint() { d.isTainted = true } @@ -214,12 +215,10 @@ func (d *deviceManager) getDeviceNamesInUse(instance *ec2.Instance, nodeID strin inUse := map[string]string{} for _, blockDevice := range instance.BlockDeviceMappings { name := aws.StringValue(blockDevice.DeviceName) - if strings.HasPrefix(name, "/dev/sd") { - name = name[7:] - } - if strings.HasPrefix(name, "/dev/xvd") { - name = name[8:] - } + // trims /dev/sd or /dev/xvd from device name + name = strings.TrimPrefix(name, "/dev/sd") + name = strings.TrimPrefix(name, "/dev/xvd") + if len(name) < 1 || len(name) > 2 { glog.Warningf("Unexpected EBS DeviceName: %q", aws.StringValue(blockDevice.DeviceName)) } diff --git a/pkg/cloud/devicemanager/manager_test.go b/pkg/cloud/devicemanager/manager_test.go index aef4ce23bb..fab13ac610 100644 --- a/pkg/cloud/devicemanager/manager_test.go +++ b/pkg/cloud/devicemanager/manager_test.go @@ -160,7 +160,7 @@ func TestReleaseDevice(t *testing.T) { dev.Release(false) dev2, err := dm.GetDevice(fakeInstance, tc.volumeID) assertDevice(t, dev2, true /*IsAlreadyAssigned*/, err) - if dev2.Path != dev2.Path { + if dev.Path != dev2.Path { t.Fatalf("Expected device to be already assigned, got unassigned") } diff --git a/pkg/cloud/fakes.go b/pkg/cloud/fakes.go index fc9b383fa3..c8b2d8dcc8 100644 --- a/pkg/cloud/fakes.go +++ b/pkg/cloud/fakes.go @@ -112,8 +112,5 @@ func (c *FakeCloudProvider) GetDiskByID(ctx context.Context, volumeID string) (* } func (c *FakeCloudProvider) IsExistInstance(ctx context.Context, nodeID string) bool { - if nodeID != c.m.GetInstanceID() { - return false - } - return true + return nodeID == c.m.GetInstanceID() } diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index cc19d03fe0..c052a17398 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -48,7 +48,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } volCaps := req.GetVolumeCapabilities() - if volCaps == nil || len(volCaps) == 0 { + if len(volCaps) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume capabilities not provided") } @@ -231,7 +231,7 @@ func (d *Driver) ValidateVolumeCapabilities(ctx context.Context, req *csi.Valida } volCaps := req.GetVolumeCapabilities() - if volCaps == nil || len(volCaps) == 0 { + if len(volCaps) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume capabilities not provided") } diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 65f269d6df..a63322d77f 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -230,9 +230,7 @@ func describeVolumes(params *ec2.DescribeVolumesInput) ([]*ec2.Volume, error) { if err != nil { return nil, err } - for _, volume := range response.Volumes { - volumes = append(volumes, volume) - } + volumes = append(volumes, response.Volumes...) nextToken = response.NextToken if aws.StringValue(nextToken) == "" { break diff --git a/tests/integration/setup_test.go b/tests/integration/setup_test.go index 87c1b8501a..8c740cfa8f 100644 --- a/tests/integration/setup_test.go +++ b/tests/integration/setup_test.go @@ -36,7 +36,6 @@ import ( const ( endpoint = "tcp://127.0.0.1:10000" - region = "us-east-1" ) var ( @@ -58,7 +57,12 @@ var _ = BeforeSuite(func() { ebs, err = cloud.NewCloud() Expect(err).To(BeNil(), "Set up Cloud client failed with error") drv = driver.NewDriver(ebs, nil, endpoint) - go drv.Run() + go func() { + err := drv.Run() + if err != nil { + fmt.Println("Driver exits: ", err) + } + }() // Create CSI Controller client csiClient, err = newCSIClient()