Skip to content

Commit

Permalink
refactor: fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Jan 23, 2024
1 parent eb57ac2 commit 2a3360f
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 119 deletions.
43 changes: 43 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
linters-settings:
errcheck:
exclude-functions:
- (github.com/go-kit/log.Logger).Log
misspell:
locale: US
gci:
sections:
- standard
- default
- prefix(github.com/hetznercloud)

linters:
disable-all: true
enable:
- bodyclose
- errcheck
- exportloopref
- gci
- gocritic
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- prealloc
- revive
- rowserrcheck
- staticcheck
- typecheck
- unparam
- unused
- whitespace

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- path: _test\.go
text: unused-parameter
2 changes: 1 addition & 1 deletion api/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/hetznercloud/hcloud-go/v2/hcloud"

"github.com/hetznercloud/csi-driver/csi"
"github.com/hetznercloud/csi-driver/volumes"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

type VolumeService struct {
Expand Down
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/prometheus/client_golang/prometheus"
"google.golang.org/grpc"

"github.com/hetznercloud/csi-driver/driver"
"github.com/hetznercloud/csi-driver/metrics"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/metadata"
"github.com/prometheus/client_golang/prometheus"
"google.golang.org/grpc"
)

func parseLogLevel(lvl string) level.Option {
Expand Down
1 change: 1 addition & 0 deletions cmd/aio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
proto "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/go-kit/log"
"github.com/go-kit/log/level"

"github.com/hetznercloud/csi-driver/api"
"github.com/hetznercloud/csi-driver/app"
"github.com/hetznercloud/csi-driver/driver"
Expand Down
1 change: 1 addition & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
proto "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/go-kit/log"
"github.com/go-kit/log/level"

"github.com/hetznercloud/csi-driver/api"
"github.com/hetznercloud/csi-driver/app"
"github.com/hetznercloud/csi-driver/driver"
Expand Down
1 change: 1 addition & 0 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
proto "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/go-kit/log"
"github.com/go-kit/log/level"

"github.com/hetznercloud/csi-driver/app"
"github.com/hetznercloud/csi-driver/driver"
"github.com/hetznercloud/csi-driver/volumes"
Expand Down
8 changes: 4 additions & 4 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *ControllerService) CreateVolume(ctx context.Context, req *proto.CreateV
"err", err,
)
code := codes.Internal
switch err {
switch err { //nolint:gocritic
case volumes.ErrVolumeAlreadyExists:
code = codes.AlreadyExists
}
Expand Down Expand Up @@ -368,7 +368,7 @@ func (s *ControllerService) ControllerExpandVolume(ctx context.Context, req *pro

if err := s.volumeService.Resize(ctx, volume, minSize); err != nil {
code := codes.Internal
switch err {
switch err { //nolint:gocritic
case volumes.ErrVolumeNotFound:
code = codes.NotFound
}
Expand All @@ -377,7 +377,7 @@ func (s *ControllerService) ControllerExpandVolume(ctx context.Context, req *pro

if volume, err = s.volumeService.GetByID(ctx, volumeID); err != nil {
code := codes.Internal
switch err {
switch err { //nolint:gocritic
case volumes.ErrVolumeNotFound:
code = codes.NotFound
}
Expand All @@ -391,6 +391,6 @@ func (s *ControllerService) ControllerExpandVolume(ctx context.Context, req *pro
return resp, nil
}

func (s *ControllerService) ControllerGetVolume(ctx context.Context, req *proto.ControllerGetVolumeRequest) (*proto.ControllerGetVolumeResponse, error) {
func (s *ControllerService) ControllerGetVolume(_ context.Context, _ *proto.ControllerGetVolumeRequest) (*proto.ControllerGetVolumeResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ControllerGetVolume not implemented")
}
52 changes: 26 additions & 26 deletions driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

proto "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/go-kit/log"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/hetznercloud/csi-driver/csi"
"github.com/hetznercloud/csi-driver/mock"
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestControllerServiceCreateVolume(t *testing.T) {
LimitBytes: 2 * MinVolumeSize * GB,
},
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessType: &proto.VolumeCapability_Mount{
Mount: &proto.VolumeCapability_MountVolume{},
},
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestControllerServiceCreateVolumeWithLocation(t *testing.T) {
LimitBytes: 10 * GB,
},
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessType: &proto.VolumeCapability_Mount{
Mount: &proto.VolumeCapability_MountVolume{},
},
Expand All @@ -132,7 +132,7 @@ func TestControllerServiceCreateVolumeWithLocation(t *testing.T) {
},
AccessibilityRequirements: &proto.TopologyRequirement{
Preferred: []*proto.Topology{
&proto.Topology{
{
Segments: map[string]string{
TopologySegmentLocation: "explicit",
},
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestControllerServiceCreateVolumeInputErrors(t *testing.T) {
LimitBytes: 10 * GB,
},
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessType: &proto.VolumeCapability_Mount{
Mount: &proto.VolumeCapability_MountVolume{},
},
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestControllerServiceCreateVolumeInputErrors(t *testing.T) {
LimitBytes: 5 * GB,
},
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessType: &proto.VolumeCapability_Mount{
Mount: &proto.VolumeCapability_MountVolume{},
},
Expand All @@ -223,7 +223,7 @@ func TestControllerServiceCreateVolumeInputErrors(t *testing.T) {
LimitBytes: 10 * GB,
},
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessType: &proto.VolumeCapability_Mount{
Mount: &proto.VolumeCapability_MountVolume{},
},
Expand All @@ -240,7 +240,7 @@ func TestControllerServiceCreateVolumeInputErrors(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.Name, func(t *testing.T) {
_, err := env.service.CreateVolume(env.ctx, testCase.Req)
if grpc.Code(err) != testCase.Code {
if status.Code(err) != testCase.Code {
t.Fatalf("unexpected error: %v", err)
}
})
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestControllerServiceCreateVolumeCreateErrors(t *testing.T) {
LimitBytes: 10 * GB,
},
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessType: &proto.VolumeCapability_Mount{
Mount: &proto.VolumeCapability_MountVolume{},
},
Expand All @@ -290,7 +290,7 @@ func TestControllerServiceCreateVolumeCreateErrors(t *testing.T) {
},
},
})
if grpc.Code(err) != testCase.Code {
if status.Code(err) != testCase.Code {
t.Fatalf("unexpected error: %v", err)
}
})
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestControllerServiceDeleteVolumeInputErrors(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.Name, func(t *testing.T) {
_, err := env.service.DeleteVolume(env.ctx, testCase.Req)
if grpc.Code(err) != testCase.Code {
if status.Code(err) != testCase.Code {
t.Fatalf("unexpected error: %v", err)
}
})
Expand All @@ -353,7 +353,7 @@ func TestControllerServiceDeleteVolumeAttached(t *testing.T) {
_, err := env.service.DeleteVolume(env.ctx, &proto.DeleteVolumeRequest{
VolumeId: "1",
})
if grpc.Code(err) != codes.FailedPrecondition {
if status.Code(err) != codes.FailedPrecondition {
t.Fatalf("unexpected error: %v", err)
}
}
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestControllerServiceDeleteVolumeInternalError(t *testing.T) {
_, err := env.service.DeleteVolume(env.ctx, &proto.DeleteVolumeRequest{
VolumeId: "1",
})
if grpc.Code(err) != codes.Internal {
if status.Code(err) != codes.Internal {
t.Fatalf("unexpected error: %v", err)
}
}
Expand Down Expand Up @@ -531,7 +531,7 @@ func TestControllerServicePublishVolumeInputErrors(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.Name, func(t *testing.T) {
_, err := env.service.ControllerPublishVolume(env.ctx, testCase.Req)
if grpc.Code(err) != testCase.Code {
if status.Code(err) != testCase.Code {
t.Fatalf("unexpected error: %v", err)
}
})
Expand Down Expand Up @@ -587,7 +587,7 @@ func TestControllerServicePublishVolumeAttachErrors(t *testing.T) {
},
},
})
if grpc.Code(err) != testCase.Code {
if status.Code(err) != testCase.Code {
t.Fatalf("unexpected error: %v", err)
}
})
Expand Down Expand Up @@ -678,7 +678,7 @@ func TestControllerServiceUnpublishVolumeInputErrors(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.Name, func(t *testing.T) {
_, err := env.service.ControllerUnpublishVolume(env.ctx, testCase.Req)
if grpc.Code(err) != testCase.Code {
if status.Code(err) != testCase.Code {
t.Fatalf("unexpected error: %v", err)
}
})
Expand Down Expand Up @@ -714,7 +714,7 @@ func TestControllerServiceUnpublishVolumeDetachErrors(t *testing.T) {
VolumeId: "1",
NodeId: "2",
})
if grpc.Code(err) != testCase.Code {
if status.Code(err) != testCase.Code {
t.Fatalf("unexpected error: %v", err)
}
})
Expand Down Expand Up @@ -744,7 +744,7 @@ func TestControllerServiceValidateVolumeCapabilities(t *testing.T) {
req := &proto.ValidateVolumeCapabilitiesRequest{
VolumeId: "1",
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessMode: &proto.VolumeCapability_AccessMode{
Mode: proto.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
Expand Down Expand Up @@ -776,7 +776,7 @@ func TestControllerServiceValidateVolumeCapabilitiesInputErrors(t *testing.T) {
Req: &proto.ValidateVolumeCapabilitiesRequest{
VolumeId: "",
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessMode: &proto.VolumeCapability_AccessMode{
Mode: proto.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
Expand All @@ -797,7 +797,7 @@ func TestControllerServiceValidateVolumeCapabilitiesInputErrors(t *testing.T) {
Req: &proto.ValidateVolumeCapabilitiesRequest{
VolumeId: "xxx",
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessMode: &proto.VolumeCapability_AccessMode{
Mode: proto.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
Expand All @@ -811,7 +811,7 @@ func TestControllerServiceValidateVolumeCapabilitiesInputErrors(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.Name, func(t *testing.T) {
_, err := env.service.ValidateVolumeCapabilities(env.ctx, testCase.Req)
if grpc.Code(err) != testCase.Code {
if status.Code(err) != testCase.Code {
t.Fatalf("unexpected error: %v", err)
}
})
Expand All @@ -828,15 +828,15 @@ func TestControllerServiceValidateVolumeCapabilitiesVolumeNotFound(t *testing.T)
req := &proto.ValidateVolumeCapabilitiesRequest{
VolumeId: "1",
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessMode: &proto.VolumeCapability_AccessMode{
Mode: proto.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
}
_, err := env.service.ValidateVolumeCapabilities(env.ctx, req)
if grpc.Code(err) != codes.NotFound {
if status.Code(err) != codes.NotFound {
t.Fatalf("unexpected error: %v", err)
}
}
Expand All @@ -851,15 +851,15 @@ func TestControllerServiceValidateVolumeCapabilitiesInternalError(t *testing.T)
req := &proto.ValidateVolumeCapabilitiesRequest{
VolumeId: "1",
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessMode: &proto.VolumeCapability_AccessMode{
Mode: proto.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
}
_, err := env.service.ValidateVolumeCapabilities(env.ctx, req)
if grpc.Code(err) != codes.Internal {
if status.Code(err) != codes.Internal {
t.Fatalf("unexpected error: %v", err)
}
}
Expand All @@ -874,7 +874,7 @@ func TestControllerServiceValidateVolumeCapabilitiesUnsupportedCapability(t *tes
req := &proto.ValidateVolumeCapabilitiesRequest{
VolumeId: "1",
VolumeCapabilities: []*proto.VolumeCapability{
&proto.VolumeCapability{
{
AccessMode: &proto.VolumeCapability_AccessMode{
Mode: proto.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
},
Expand Down
Loading

0 comments on commit 2a3360f

Please sign in to comment.