Skip to content

Commit 94f7938

Browse files
committed
chore(lint): Update to golangci-lint v1.58.2 and fix lint issues
1 parent 029c698 commit 94f7938

File tree

27 files changed

+242
-186
lines changed

27 files changed

+242
-186
lines changed

.github/workflows/pr-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: golangci-lint
1313
uses: golangci/golangci-lint-action@v3
1414
with:
15-
version: v1.56.2
15+
version: v1.58.2
1616
args: --timeout=5m
1717

1818
build:

.golangci.yml

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,34 @@ issues:
44
max-same-issues: 0 # disable
55

66
linters-settings:
7-
8-
staticcheck:
9-
go: "1.15"
10-
checks: [ "all" ]
11-
12-
stylecheck:
13-
go: "1.15"
14-
checks: [ "all" ]
15-
7+
gci:
8+
sections:
9+
- standard
10+
- default
11+
- prefix(github.com/leaseweb/cloudstack-csi-driver)
1612
goimports:
17-
local-prefixes: github.com/apalia/cloudstack-csi-driver
13+
local-prefixes: github.com/leaseweb/cloudstack-csi-driver
1814

1915
misspell:
2016
locale: US
2117

2218
linters:
23-
disable-all: true
24-
enable:
25-
- errcheck
26-
- gosimple
27-
- govet
28-
- ineffassign
29-
- staticcheck
30-
- stylecheck
31-
- goimports
32-
- typecheck
33-
- unused
34-
- misspell
19+
enable-all: true
20+
disable:
21+
- cyclop
22+
- depguard
23+
- err113
24+
- exhaustruct
25+
- funlen
26+
- gochecknoglobals
27+
- gomnd
28+
- inamedparam
29+
- ireturn
30+
- lll
31+
- mnd
32+
- paralleltest
33+
- tagliatelle
34+
- testpackage
35+
- varnamelen
36+
- wrapcheck
37+
- wsl

cmd/cloudstack-csi-driver/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var (
2525
debug = flag.Bool("debug", false, "Enable debug logging")
2626
showVersion = flag.Bool("version", false, "Show version")
2727

28-
// Version is set by the build process
28+
// Version is set by the build process.
2929
version = ""
3030
isDevEnv = false
3131
)
@@ -35,7 +35,8 @@ func main() {
3535

3636
if *showVersion {
3737
baseName := path.Base(os.Args[0])
38-
fmt.Println(baseName, version)
38+
fmt.Println(baseName, version) //nolint:forbidigo
39+
3940
return
4041
}
4142

@@ -48,7 +49,7 @@ func main() {
4849
}
4950

5051
func run() {
51-
// Setup logging
52+
// Setup logging.
5253
var logConfig zap.Config
5354
if isDevEnv {
5455
logConfig = zap.NewDevelopmentConfig()
@@ -63,11 +64,11 @@ func run() {
6364
undo := zap.ReplaceGlobals(logger)
6465
defer undo()
6566

66-
// Setup cloud connector
67+
// Setup cloud connector.
6768
config, err := cloud.ReadConfig(*cloudstackconfig)
6869
if err != nil {
6970
logger.Sugar().Errorw("Cannot read CloudStack configuration", "error", err)
70-
os.Exit(1)
71+
os.Exit(1) //nolint:gocritic
7172
}
7273
logger.Sugar().Debugf("Successfully read CloudStack configuration %v", *cloudstackconfig)
7374
csConnector := cloud.New(config)

cmd/cloudstack-csi-sc-syncer/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ var (
2020
kubeconfig = flag.String("kubeconfig", path.Join(os.Getenv("HOME"), ".kube/config"), "Kubernetes configuration file. Use \"-\" to use in-cluster configuration.")
2121
label = flag.String("label", "app.kubernetes.io/managed-by="+agent, "")
2222
namePrefix = flag.String("namePrefix", "cloudstack-", "")
23-
delete = flag.Bool("delete", false, "Delete")
23+
deleteUnused = flag.Bool("delete", false, "Delete")
2424
volumeExpansion = flag.Bool("volumeExpansion", false, "VolumeExpansion")
2525
showVersion = flag.Bool("version", false, "Show version")
2626

27-
// Version is set by the build process
27+
// Version is set by the build process.
2828
version = ""
2929
)
3030

@@ -33,7 +33,8 @@ func main() {
3333

3434
if *showVersion {
3535
baseName := path.Base(os.Args[0])
36-
fmt.Println(baseName, version)
36+
fmt.Println(baseName, version) //nolint:forbidigo
37+
3738
return
3839
}
3940

@@ -43,7 +44,7 @@ func main() {
4344
KubeConfig: *kubeconfig,
4445
Label: *label,
4546
NamePrefix: *namePrefix,
46-
Delete: *delete,
47+
Delete: *deleteUnused,
4748
VolumeExpansion: *volumeExpansion,
4849
})
4950
if err != nil {

pkg/cloud/cloud.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type VM struct {
4646
ZoneID string
4747
}
4848

49-
// Specific errors
49+
// Specific errors.
5050
var (
5151
ErrNotFound = errors.New("not found")
5252
ErrTooManyResults = errors.New("too many results")
@@ -60,5 +60,6 @@ type client struct {
6060
// New creates a new cloud connector, given its configuration.
6161
func New(config *Config) Interface {
6262
csClient := cloudstack.NewAsyncClient(config.APIURL, config.APIKey, config.SecretKey, config.VerifySSL)
63+
6364
return &client{csClient}
6465
}

pkg/cloud/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Config struct {
1717
// csConfig wraps the config for the CloudStack cloud provider.
1818
// It is taken from https://github.com/apache/cloudstack-kubernetes-provider
1919
// in order to have the same config in cloudstack-kubernetes-provider
20-
// and in this cloudstack-csi-driver
20+
// and in this cloudstack-csi-driver.
2121
type csConfig struct {
2222
Global struct {
2323
APIURL string `gcfg:"api-url"`

pkg/cloud/fake/fake.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,49 @@ func New() cloud.Interface {
3535
ID: "0d7107a3-94d2-44e7-89b8-8930881309a5",
3636
ZoneID: zoneID,
3737
}
38+
3839
return &fakeConnector{
3940
node: node,
4041
volumesByID: map[string]cloud.Volume{volume.ID: volume},
4142
volumesByName: map[string]cloud.Volume{volume.Name: volume},
4243
}
4344
}
4445

45-
func (f *fakeConnector) GetVMByID(ctx context.Context, vmID string) (*cloud.VM, error) {
46+
func (f *fakeConnector) GetVMByID(_ context.Context, vmID string) (*cloud.VM, error) {
4647
if vmID == f.node.ID {
4748
return f.node, nil
4849
}
50+
4951
return nil, cloud.ErrNotFound
5052
}
5153

52-
func (f *fakeConnector) GetNodeInfo(ctx context.Context, vmName string) (*cloud.VM, error) {
54+
func (f *fakeConnector) GetNodeInfo(_ context.Context, _ string) (*cloud.VM, error) {
5355
return f.node, nil
5456
}
5557

56-
func (f *fakeConnector) ListZonesID(ctx context.Context) ([]string, error) {
58+
func (f *fakeConnector) ListZonesID(_ context.Context) ([]string, error) {
5759
return []string{zoneID}, nil
5860
}
5961

60-
func (f *fakeConnector) GetVolumeByID(ctx context.Context, volumeID string) (*cloud.Volume, error) {
62+
func (f *fakeConnector) GetVolumeByID(_ context.Context, volumeID string) (*cloud.Volume, error) {
6163
vol, ok := f.volumesByID[volumeID]
6264
if ok {
6365
return &vol, nil
6466
}
67+
6568
return nil, cloud.ErrNotFound
6669
}
6770

68-
func (f *fakeConnector) GetVolumeByName(ctx context.Context, name string) (*cloud.Volume, error) {
71+
func (f *fakeConnector) GetVolumeByName(_ context.Context, name string) (*cloud.Volume, error) {
6972
vol, ok := f.volumesByName[name]
7073
if ok {
7174
return &vol, nil
7275
}
76+
7377
return nil, cloud.ErrNotFound
7478
}
7579

76-
func (f *fakeConnector) CreateVolume(ctx context.Context, diskOfferingID, zoneID, name string, sizeInGB int64) (string, error) {
80+
func (f *fakeConnector) CreateVolume(_ context.Context, diskOfferingID, zoneID, name string, sizeInGB int64) (string, error) {
7781
id, _ := uuid.GenerateUUID()
7882
vol := cloud.Volume{
7983
ID: id,
@@ -84,37 +88,39 @@ func (f *fakeConnector) CreateVolume(ctx context.Context, diskOfferingID, zoneID
8488
}
8589
f.volumesByID[vol.ID] = vol
8690
f.volumesByName[vol.Name] = vol
91+
8792
return vol.ID, nil
8893
}
8994

90-
func (f *fakeConnector) DeleteVolume(ctx context.Context, id string) error {
95+
func (f *fakeConnector) DeleteVolume(_ context.Context, id string) error {
9196
if vol, ok := f.volumesByID[id]; ok {
9297
name := vol.Name
9398
delete(f.volumesByName, name)
9499
}
95100
delete(f.volumesByID, id)
101+
96102
return nil
97103
}
98104

99-
func (f *fakeConnector) AttachVolume(ctx context.Context, volumeID, vmID string) (string, error) {
105+
func (f *fakeConnector) AttachVolume(_ context.Context, _, _ string) (string, error) {
100106
return "1", nil
101107
}
102108

103-
func (f *fakeConnector) DetachVolume(ctx context.Context, volumeID string) error {
109+
func (f *fakeConnector) DetachVolume(_ context.Context, _ string) error {
104110
return nil
105111
}
106-
func (f *fakeConnector) ExpandVolume(ctx context.Context, volumeID string, newSizeInGB int64) error {
112+
113+
func (f *fakeConnector) ExpandVolume(_ context.Context, volumeID string, newSizeInGB int64) error {
107114
if vol, ok := f.volumesByID[volumeID]; ok {
108115
newSizeInBytes := newSizeInGB * 1024 * 1024 * 1024
109116
if newSizeInBytes > vol.Size {
110117
vol.Size = newSizeInBytes
111118
f.volumesByID[volumeID] = vol
112119
f.volumesByName[vol.Name] = vol
113-
return nil
114-
} else {
115-
return nil
116120
}
117-
} else {
121+
118122
return nil
119123
}
124+
125+
return cloud.ErrNotFound
120126
}

pkg/cloud/metadata.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
87
"os"
98
"strings"
109

@@ -22,6 +21,7 @@ func (c *client) metadataInstanceID(ctx context.Context) string {
2221
// Try a NODE_ID environment variable
2322
if envNodeID := os.Getenv("NODE_ID"); envNodeID != "" {
2423
slog.Debugf("Found CloudStack VM ID from environment variable NODE_ID: %s", envNodeID)
24+
2525
return envNodeID
2626
}
2727

@@ -32,11 +32,10 @@ func (c *client) metadataInstanceID(ctx context.Context) string {
3232
ciData, err := c.readCloudInit(ctx, cloudInitInstanceFilePath)
3333
if err != nil {
3434
slog.Errorf("Cannot read cloud-init instance data: %v", err)
35-
} else {
36-
if ciData.V1.InstanceID != "" {
37-
slog.Debugf("Found CloudStack VM ID from cloud-init: %s", ciData.V1.InstanceID)
38-
return ciData.V1.InstanceID
39-
}
35+
} else if ciData.V1.InstanceID != "" {
36+
slog.Debugf("Found CloudStack VM ID from cloud-init: %s", ciData.V1.InstanceID)
37+
38+
return ciData.V1.InstanceID
4039
}
4140
slog.Error("cloud-init instance ID is not provided")
4241
} else if os.IsNotExist(err) {
@@ -46,6 +45,7 @@ func (c *client) metadataInstanceID(ctx context.Context) string {
4645
}
4746

4847
slog.Debug("CloudStack VM ID not found in meta-data.")
48+
4949
return ""
5050
}
5151

@@ -62,20 +62,23 @@ type cloudInitV1 struct {
6262
func (c *client) readCloudInit(ctx context.Context, instanceFilePath string) (*cloudInitInstanceData, error) {
6363
slog := ctxzap.Extract(ctx).Sugar()
6464

65-
b, err := ioutil.ReadFile(instanceFilePath)
65+
b, err := os.ReadFile(instanceFilePath)
6666
if err != nil {
6767
slog.Errorf("Cannot read %s", instanceFilePath)
68+
6869
return nil, err
6970
}
7071

7172
var data cloudInitInstanceData
7273
if err := json.Unmarshal(b, &data); err != nil {
7374
slog.Errorf("Cannot parse JSON file %s", instanceFilePath)
75+
7476
return nil, err
7577
}
7678

7779
if strings.ToLower(data.V1.CloudName) != cloudStackCloudName {
7880
slog.Errorf("Cloud-Init cloud name is %s, only %s is supported", data.V1.CloudName, cloudStackCloudName)
81+
7982
return nil, fmt.Errorf("Cloud-Init cloud name is %s, only %s is supported", data.V1.CloudName, cloudStackCloudName)
8083
}
8184

pkg/cloud/vms.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func (c *client) GetVMByID(ctx context.Context, vmID string) (*VM, error) {
2323
return nil, ErrTooManyResults
2424
}
2525
vm := l.VirtualMachines[0]
26+
2627
return &VM{
2728
ID: vm.Id,
2829
ZoneID: vm.Zoneid,
@@ -46,6 +47,7 @@ func (c *client) getVMByName(ctx context.Context, name string) (*VM, error) {
4647
return nil, ErrTooManyResults
4748
}
4849
vm := l.VirtualMachines[0]
50+
4951
return &VM{
5052
ID: vm.Id,
5153
ZoneID: vm.Zoneid,

0 commit comments

Comments
 (0)