Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci] fix golangci file name, address all unaddressed linter issues #227

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions .golanci.yml → .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ linters-settings:
- default
- blank
- dot
- prefix(github.com/linode)
- prefix(github.com/linode/linode-blockstorage-csi-driver)

govet:
check-shadowing: false
Expand All @@ -28,7 +28,7 @@ linters-settings:
simplify: true

goimports:
local-prefixes: github.com/linode/
local-prefixes: github.com/linode/linode-blockstorage-csi-driver

maligned:
suggest-new: true
Expand Down Expand Up @@ -70,10 +70,10 @@ linters:
enable:
- asasalint
- asciicheck
- bidicheck
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- decorder
- dogsled
- dupl
Expand All @@ -83,9 +83,7 @@ linters:
- errname
- errorlint
- errcheck
- exportloopref
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- gci
Expand All @@ -103,13 +101,11 @@ linters:
- maintidx
- makezero
- misspell
- mnd
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- parlalleltest
- prealloc
- predeclared
- reassign
Expand All @@ -131,11 +127,23 @@ linters:

issues:
exclude-rules:
- path: _test\.go
# Exclude some linters from running on tests files.
- path: _test(ing)?\.go
linters:
- gocyclo
- maintidx
- errcheck
- dupl
- exportloopref
- gosec
- copyloopvar
- unparam
- varnamelen

# Ease some gocritic warnings on test files.
- path: _test\.go
text: "(unnamedResult|exitAfterDefer)"
linters:
- gocritic

- text: "G101:"
linters:
Expand Down
12 changes: 5 additions & 7 deletions internal/driver/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
log.V(4).Info("CreateVolume details", "storage_size_giga_bytes", targetSizeGB, "volume_name", volumeName)

volumeContext := make(map[string]string)
if req.Parameters[LuksEncryptedAttribute] == "true" {
if req.GetParameters()[LuksEncryptedAttribute] == "true" {
// if luks encryption is enabled add a volume context
volumeContext[LuksEncryptedAttribute] = "true"
volumeContext[PublishInfoVolumeName] = volumeName
volumeContext[LuksCipherAttribute] = req.Parameters[LuksCipherAttribute]
volumeContext[LuksKeySizeAttribute] = req.Parameters[LuksKeySizeAttribute]
volumeContext[LuksCipherAttribute] = req.GetParameters()[LuksCipherAttribute]
volumeContext[LuksKeySizeAttribute] = req.GetParameters()[LuksKeySizeAttribute]
}

// Attempt to get info about the source volume for
Expand All @@ -182,7 +182,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
ctx,
volumeName,
targetSizeGB,
req.Parameters[VolumeTags],
req.GetParameters()[VolumeTags],
sourceVolumeInfo,
)
if err != nil {
Expand Down Expand Up @@ -497,7 +497,6 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req
return &csi.ValidateVolumeCapabilitiesResponse{}, errInternal("get volume: %v", err)
}


resp := &csi.ValidateVolumeCapabilitiesResponse{}
if validVolumeCapabilities(volumeCapabilities) {
resp.Confirmed = &csi.ValidateVolumeCapabilitiesResponse_Confirmed{VolumeCapabilities: volumeCapabilities}
Expand Down Expand Up @@ -532,7 +531,6 @@ func (cs *ControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolume
nextToken = strconv.Itoa(listOpts.Page + 1)
}


// List all volumes
log.V(4).Info("Listing volumes", "list_opts", listOpts)
volumes, err := cs.client.ListVolumes(ctx, listOpts)
Expand Down Expand Up @@ -606,7 +604,7 @@ func (cs *ControllerServer) ControllerGetCapabilities(ctx context.Context, req *
func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
log, ctx, done := logger.GetLogger(ctx).WithMethod("ControllerExpandVolume")
defer done()

log.V(2).Info("Processing request", "req", req)

volumeID, statusErr := linodevolumes.VolumeIdAsInt("ControllerExpandVolume", req)
Expand Down
11 changes: 6 additions & 5 deletions internal/driver/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"testing"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/linode/linodego"

linodeclient "github.com/linode/linode-blockstorage-csi-driver/pkg/linode-client"
linodevolumes "github.com/linode/linode-blockstorage-csi-driver/pkg/linode-volumes"
"github.com/linode/linodego"
)

func TestListVolumes(t *testing.T) {
Expand Down Expand Up @@ -101,7 +102,7 @@ func TestListVolumes(t *testing.T) {
var linodeVolume *linodego.Volume
for _, v := range tt.volumes {
key := linodevolumes.CreateLinodeVolumeKey(v.ID, v.Label)
if volume.VolumeId == key.GetVolumeKey() {
if volume.GetVolumeId() == key.GetVolumeKey() {
v := v
linodeVolume = &v
break
Expand All @@ -111,11 +112,11 @@ func TestListVolumes(t *testing.T) {
t.Fatalf("no matching linode volume for %#v", volume)
}

if want, got := int64(linodeVolume.Size<<30), volume.CapacityBytes; want != got {
if want, got := int64(linodeVolume.Size<<30), volume.GetCapacityBytes(); want != got {
t.Errorf("mismatched volume size: want=%d got=%d", want, got)
}
for _, topology := range volume.GetAccessibleTopology() {
region, ok := topology.Segments[VolumeTopologyRegion]
region, ok := topology.GetSegments()[VolumeTopologyRegion]
if !ok {
t.Error("region not set in volume topology")
}
Expand All @@ -129,7 +130,7 @@ func TestListVolumes(t *testing.T) {
t.Error("nil status")
continue
}
if status.VolumeCondition.Abnormal {
if status.GetVolumeCondition().GetAbnormal() {
t.Error("abnormal volume condition")
}

Expand Down
10 changes: 5 additions & 5 deletions internal/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"sync"

"github.com/container-storage-interface/spec/lib/go/csi"
linodeclient "github.com/linode/linode-blockstorage-csi-driver/pkg/linode-client"

"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
mountmanager "github.com/linode/linode-blockstorage-csi-driver/pkg/mount-manager"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/mount-utils"

linodeclient "github.com/linode/linode-blockstorage-csi-driver/pkg/linode-client"
"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
mountmanager "github.com/linode/linode-blockstorage-csi-driver/pkg/mount-manager"
)

// Name is the name of the driver provided by this package.
Expand Down Expand Up @@ -141,7 +141,7 @@ func (linodeDriver *LinodeDriver) ValidateControllerServiceRequest(ctx context.C
}

for _, cap := range linodeDriver.cscap {
if c == cap.GetRpc().Type {
if c == cap.GetRpc().GetType() {
log.V(4).Info("Controller service request validated successfully")
return nil
}
Expand Down
9 changes: 4 additions & 5 deletions internal/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"os"
"testing"

"github.com/linode/linodego"
"go.uber.org/mock/gomock"
"k8s.io/mount-utils"

"github.com/linode/linode-blockstorage-csi-driver/mocks"
drivertest "github.com/linode/linode-blockstorage-csi-driver/pkg/driver-test"
linodeclient "github.com/linode/linode-blockstorage-csi-driver/pkg/linode-client"
"k8s.io/mount-utils"

"github.com/linode/linodego"

"go.uber.org/mock/gomock"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion internal/driver/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
"fmt"

csi "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/wrapperspb"

"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
)

// IdentityServer implements the CSI Identity service for the Linode Block Storage CSI Driver.
Expand Down
3 changes: 1 addition & 2 deletions internal/driver/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"k8s.io/klog/v2"
utilexec "k8s.io/utils/exec"

"github.com/linode/linode-blockstorage-csi-driver/pkg/mount-manager"
mountmanager "github.com/linode/linode-blockstorage-csi-driver/pkg/mount-manager"
)

type LuksContext struct {
Expand Down Expand Up @@ -243,7 +243,6 @@ func (e *Encryption) isLuksMapping(volume string) (bool, string, error) {
return false, mappingName, nil
}
}

}
return false, "", nil
}
Expand Down
7 changes: 4 additions & 3 deletions internal/driver/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"strconv"

metadata "github.com/linode/go-metadata"
"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
"github.com/linode/linodego"

"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
)

// Metadata contains metadata about the node/instance the CSI node plugin
Expand Down Expand Up @@ -45,7 +46,7 @@ func GetMetadata(ctx context.Context) (Metadata, error) {
return Metadata{}, fmt.Errorf("get instance data: %w", err)
}

log.V(4).Info("Successfully retrieved metadata",
log.V(4).Info("Successfully retrieved metadata",
"instanceID", data.ID,
"instanceLabel", data.Label,
"region", data.Region,
Expand Down Expand Up @@ -140,7 +141,7 @@ func GetMetadataFromAPI(ctx context.Context, client *linodego.Client) (Metadata,
Memory: memory,
}

log.V(4).Info("Successfully retrieved metadata",
log.V(4).Info("Successfully retrieved metadata",
"instanceID", metadata.ID,
"instanceLabel", metadata.Label,
"region", metadata.Region,
Expand Down
11 changes: 6 additions & 5 deletions internal/driver/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"sync"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/linode/linodego"
"golang.org/x/net/context"
"k8s.io/mount-utils"

linodeclient "github.com/linode/linode-blockstorage-csi-driver/pkg/linode-client"
linodevolumes "github.com/linode/linode-blockstorage-csi-driver/pkg/linode-volumes"
"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
mountmanager "github.com/linode/linode-blockstorage-csi-driver/pkg/mount-manager"
"github.com/linode/linodego"
"golang.org/x/net/context"
"k8s.io/mount-utils"
)

type NodeServer struct {
Expand Down Expand Up @@ -227,7 +228,7 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol

// Check if the volume mode is set to 'Block'
// Do nothing else with the mount point for stage
if blk := req.VolumeCapability.GetBlock(); blk != nil {
if blk := req.GetVolumeCapability().GetBlock(); blk != nil {
log.V(4).Info("Volume is a block volume", "volumeID", volumeID)
return &csi.NodeStageVolumeResponse{}, nil
}
Expand Down Expand Up @@ -307,7 +308,7 @@ func (ns *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV

log.V(2).Info("Successfully completed", "volumeID", volumeID)
return &csi.NodeExpandVolumeResponse{
CapacityBytes: req.CapacityRange.RequiredBytes,
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(),
}, nil
}

Expand Down
9 changes: 5 additions & 4 deletions internal/driver/nodeserver_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ import (
"fmt"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
"golang.org/x/sys/unix"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
)

func nodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
log := logger.GetLogger(ctx)

if req.VolumeId == "" || req.VolumePath == "" {
if req.GetVolumeId() == "" || req.GetVolumePath() == "" {
return nil, status.Error(codes.InvalidArgument, "volume ID or path empty")
}

var statfs unix.Statfs_t
// See http://man7.org/linux/man-pages/man2/statfs.2.html for details.
err := unix.Statfs(req.VolumePath, &statfs)
err := unix.Statfs(req.GetVolumePath(), &statfs)
if err != nil && !errors.Is(err, unix.EIO) {
if errors.Is(err, unix.ENOENT) {
return nil, status.Errorf(codes.NotFound, "volume path not found: %v", err.Error())
Expand Down Expand Up @@ -58,6 +59,6 @@ func nodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest)
},
}

log.V(2).Info("Successfully retrieved volume stats", "volumeID", req.VolumeId, "volumePath", req.VolumePath, "response", response)
log.V(2).Info("Successfully retrieved volume stats", "volumeID", req.GetVolumeId(), "volumePath", req.GetVolumePath(), "response", response)
return response, nil
}
Loading