Skip to content

Commit

Permalink
Fix errors reported by golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng Pan committed Nov 6, 2018
1 parent ea4ae91 commit 6e1d41d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions hack/verify-golint
Original file line number Diff line number Diff line change
Expand Up @@ -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."

12 changes: 5 additions & 7 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions pkg/cloud/devicemanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/devicemanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/cloud/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
4 changes: 2 additions & 2 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down
4 changes: 1 addition & 3 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (

const (
endpoint = "tcp://127.0.0.1:10000"
region = "us-east-1"
)

var (
Expand All @@ -58,7 +57,10 @@ 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()
Expect(err).To(BeNil())
}()

// Create CSI Controller client
csiClient, err = newCSIClient()
Expand Down

0 comments on commit 6e1d41d

Please sign in to comment.