Skip to content

Commit 5b423de

Browse files
committed
chore: update golangci-lint version to 2.7.2
1 parent 5f2a170 commit 5b423de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+199
-221
lines changed

.golangci.yaml

Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
version: "2"
12
linters:
2-
disable-all: true
3+
default: none
34
enable:
45
- containedctx
56
- dogsled
@@ -8,86 +9,86 @@ linters:
89
- errcheck
910
- errname
1011
- errorlint
11-
- gci
1212
- gocognit
1313
- goconst
1414
- gocritic
15-
# - godot
16-
- gofmt
17-
- gofumpt
1815
- goprintffuncname
1916
- gosec
20-
- gosimple
2117
- govet
2218
- ineffassign
19+
- intrange
2320
- lll
24-
# TODO FIX THE FOLLOWING
25-
# - misspell
26-
# - nakedret
27-
# - paralleltest
21+
- misspell
22+
- modernize
23+
- nakedret
24+
- nilerr
25+
- predeclared
2826
- revive
2927
- sqlclosecheck
3028
- staticcheck
31-
# - stylecheck
32-
- typecheck
3329
- unconvert
3430
- unparam
35-
- unused
36-
# - whitespace
37-
38-
linters-settings:
39-
gocritic:
40-
enabled-all: true
41-
disabled-checks:
42-
- commentFormatting
43-
godot:
44-
scope: all
45-
gofumpt:
46-
module-path: github.com/castai/cluster-controller
47-
extra-rules: true
48-
goconst:
49-
min-len: 2
50-
min-occurrences: 5
51-
golint:
52-
min-confidence: 0
53-
gomnd:
54-
settings:
55-
mnd:
56-
# don't include the "operation" and "assign"
57-
checks: [argument,case,condition,return]
58-
govet:
59-
# shadow is marked as experimental feature, skip it for now.
60-
check-shadowing: false
61-
settings:
62-
printf:
63-
funcs:
64-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
65-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
66-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
67-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
68-
lll:
69-
line-length: 200
70-
maligned:
71-
suggest-new: true
72-
misspell:
73-
locale: US
74-
revive:
75-
rules:
76-
- name: redefines-builtin-id
77-
disabled: true
78-
79-
# Allow code like:
80-
# Items: binpacking.Items{
81-
# {
82-
# },
83-
# }
84-
- name: nested-structs
85-
disabled: true
86-
gci:
87-
sections:
88-
- standard
89-
- default
90-
- prefix(github.com/castai/cluster-controller)
91-
issues:
92-
exclude-dirs:
93-
- mock
31+
- usestdlibvars
32+
- usetesting
33+
- wastedassign
34+
- whitespace
35+
settings:
36+
goconst:
37+
min-len: 2
38+
min-occurrences: 5
39+
gocritic:
40+
disabled-checks:
41+
- commentFormatting
42+
godot:
43+
scope: all
44+
govet:
45+
settings:
46+
printf:
47+
funcs:
48+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
49+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
50+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
51+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
52+
lll:
53+
line-length: 200
54+
misspell:
55+
locale: US
56+
revive:
57+
rules:
58+
- name: redefines-builtin-id
59+
disabled: true
60+
- name: nested-structs
61+
disabled: true
62+
exclusions:
63+
generated: lax
64+
presets:
65+
- comments
66+
- common-false-positives
67+
- legacy
68+
- std-error-handling
69+
paths:
70+
- mock
71+
- third_party$
72+
- builtin$
73+
- examples$
74+
formatters:
75+
enable:
76+
- gci
77+
- gofmt
78+
- gofumpt
79+
settings:
80+
gci:
81+
sections:
82+
- standard
83+
- default
84+
- prefix(github.com/castai/cluster-controller)
85+
gofumpt:
86+
module-path: github.com/castai/cluster-controller
87+
extra-rules: true
88+
exclusions:
89+
generated: lax
90+
paths:
91+
- mock
92+
- third_party$
93+
- builtin$
94+
- examples$

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TOOLS_DIR=bin
77
ROOT_DIR=$(abspath .)
88
TOOLS_GOBIN_DIR := $(abspath $(TOOLS_DIR))
99

10-
GOLANGCI_LINT_VER := v1.64.8
10+
GOLANGCI_LINT_VER := v2.7.2
1111
GOLANGCI_LINT_BIN := golangci-lint
1212
GOLANGCI_LINT := $(TOOLS_GOBIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
1313

@@ -20,7 +20,7 @@ endif
2020

2121

2222
$(GOLANGCI_LINT):
23-
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
23+
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/v2/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
2424

2525
## build: Build the binary for the specified architecture and create a Docker image. Usually this means ARCH=amd64 should be set if running on an ARM machine. Use `go build .` for simple local build.
2626
build:

cmd/controller/run.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,14 @@ func runWithLeaderElection(
295295
// This method is always called(even if it was not a leader):
296296
// - when controller shuts dow (for example because of SIGTERM)
297297
// - we actually lost leader
298-
// So we need to check what whas reason of acutally stopping.
298+
// So we need to check what whas reason of actually stopping.
299299
if err := ctx.Err(); err != nil {
300300
log.Infof("main context done, stopping controller: %v", err)
301301
return
302302
}
303303
log.Infof("leader lost: %s", id)
304304
// We don't need to exit here.
305-
// Leader "on started leading" receive a context that gets cancelled when you're no longer the leader.
305+
// Leader "on started leading" receive a context that gets canceled when you're no longer the leader.
306306
},
307307
OnNewLeader: func(identity string) {
308308
// We're notified when new leader elected.
@@ -338,13 +338,14 @@ func (e *logContextError) Unwrap() error {
338338
return e.err
339339
}
340340

341-
func runningOnGKE(clientset *kubernetes.Clientset, cfg config.Config) (isGKE bool, err error) {
341+
func runningOnGKE(clientset *kubernetes.Clientset, cfg config.Config) (bool, error) {
342342
// When running locally, there is no node.
343343
if cfg.SelfPod.Node == "" {
344344
return false, nil
345345
}
346346

347-
err = waitext.Retry(context.Background(), waitext.DefaultExponentialBackoff(), 3, func(ctx context.Context) (bool, error) {
347+
var isGKE bool
348+
err := waitext.Retry(context.Background(), waitext.DefaultExponentialBackoff(), 3, func(ctx context.Context) (bool, error) {
348349
node, err := clientset.CoreV1().Nodes().Get(ctx, cfg.SelfPod.Node, metav1.GetOptions{})
349350
if err != nil && !apierrors.IsNotFound(err) {
350351
return true, fmt.Errorf("getting node: %w", err)
@@ -361,7 +362,7 @@ func runningOnGKE(clientset *kubernetes.Clientset, cfg config.Config) (isGKE boo
361362
}, func(err error) {
362363
})
363364

364-
return
365+
return isGKE, err
365366
}
366367

367368
func saveMetadata(clusterID string, cfg config.Config, log *logrus.Entry) error {

cmd/root.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"slices"
78

89
"github.com/spf13/cobra"
910

@@ -21,11 +22,8 @@ func Execute(ctx context.Context) {
2122
cmd := rootCmd.Commands()
2223

2324
for _, a := range cmd {
24-
for _, b := range os.Args[1:] {
25-
if a.Name() == b {
26-
cmdFound = true
27-
break
28-
}
25+
if slices.Contains(os.Args[1:], a.Name()) {
26+
cmdFound = true
2927
}
3028
}
3129
if !cmdFound {

health/healthz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (h *HealthzProvider) Check(_ *http.Request) (err error) {
4646

4747
if h.initStartedAt != nil {
4848
if time.Since(*h.initStartedAt) > h.cfg.StartTimeLimit {
49-
return fmt.Errorf("there was no sucessful poll action since start of application %s", h.cfg.StartTimeLimit)
49+
return fmt.Errorf("there was no successful poll action since start of application %s", h.cfg.StartTimeLimit)
5050
}
5151
return nil
5252
}

internal/actions/actions.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ func NewDefaultActionHandlers(
2222
helmClient helm.Client,
2323
) ActionHandlers {
2424
return ActionHandlers{
25-
reflect.TypeOf(&castai.ActionDeleteNode{}): NewDeleteNodeHandler(log, clientset),
26-
reflect.TypeOf(&castai.ActionDrainNode{}): NewDrainNodeHandler(log, clientset, castNamespace),
27-
reflect.TypeOf(&castai.ActionPatchNode{}): NewPatchNodeHandler(log, clientset),
28-
reflect.TypeOf(&castai.ActionCreateEvent{}): NewCreateEventHandler(log, clientset),
29-
reflect.TypeOf(&castai.ActionChartUpsert{}): NewChartUpsertHandler(log, helmClient),
30-
reflect.TypeOf(&castai.ActionChartUninstall{}): NewChartUninstallHandler(log, helmClient),
31-
reflect.TypeOf(&castai.ActionChartRollback{}): NewChartRollbackHandler(log, helmClient, k8sVersion),
32-
reflect.TypeOf(&castai.ActionDisconnectCluster{}): NewDisconnectClusterHandler(log, clientset),
33-
reflect.TypeOf(&castai.ActionCheckNodeDeleted{}): NewCheckNodeDeletedHandler(log, clientset),
34-
reflect.TypeOf(&castai.ActionCheckNodeStatus{}): NewCheckNodeStatusHandler(log, clientset),
35-
reflect.TypeOf(&castai.ActionEvictPod{}): NewEvictPodHandler(log, clientset),
36-
reflect.TypeOf(&castai.ActionPatch{}): NewPatchHandler(log, dynamicClient),
37-
reflect.TypeOf(&castai.ActionCreate{}): NewCreateHandler(log, dynamicClient),
38-
reflect.TypeOf(&castai.ActionDelete{}): NewDeleteHandler(log, dynamicClient),
25+
reflect.TypeFor[*castai.ActionDeleteNode](): NewDeleteNodeHandler(log, clientset),
26+
reflect.TypeFor[*castai.ActionDrainNode](): NewDrainNodeHandler(log, clientset, castNamespace),
27+
reflect.TypeFor[*castai.ActionPatchNode](): NewPatchNodeHandler(log, clientset),
28+
reflect.TypeFor[*castai.ActionCreateEvent](): NewCreateEventHandler(log, clientset),
29+
reflect.TypeFor[*castai.ActionChartUpsert](): NewChartUpsertHandler(log, helmClient),
30+
reflect.TypeFor[*castai.ActionChartUninstall](): NewChartUninstallHandler(log, helmClient),
31+
reflect.TypeFor[*castai.ActionChartRollback](): NewChartRollbackHandler(log, helmClient, k8sVersion),
32+
reflect.TypeFor[*castai.ActionDisconnectCluster](): NewDisconnectClusterHandler(log, clientset),
33+
reflect.TypeFor[*castai.ActionCheckNodeDeleted](): NewCheckNodeDeletedHandler(log, clientset),
34+
reflect.TypeFor[*castai.ActionCheckNodeStatus](): NewCheckNodeStatusHandler(log, clientset),
35+
reflect.TypeFor[*castai.ActionEvictPod](): NewEvictPodHandler(log, clientset),
36+
reflect.TypeFor[*castai.ActionPatch](): NewPatchHandler(log, dynamicClient),
37+
reflect.TypeFor[*castai.ActionCreate](): NewCreateHandler(log, dynamicClient),
38+
reflect.TypeFor[*castai.ActionDelete](): NewDeleteHandler(log, dynamicClient),
3939
}
4040
}
4141

4242
func (h ActionHandlers) Close() error {
43-
return h[reflect.TypeOf(&castai.ActionCreateEvent{})].(*CreateEventHandler).Close()
43+
return h[reflect.TypeFor[*castai.ActionCreateEvent]()].(*CreateEventHandler).Close()
4444
}

internal/actions/check_node_deleted_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ func TestCheckNodeDeletedHandler_Handle(t *testing.T) {
192192
},
193193
}
194194
for _, tt := range tests {
195-
tt := tt
196195
t.Run(tt.name, func(t *testing.T) {
197196
t.Parallel()
198197
clientSet := fake.NewClientset(tt.args.tuneFakeObjects...)

internal/actions/check_node_status.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"errors"
66
"fmt"
77
"reflect"
8+
"slices"
89
"time"
910

1011
"github.com/samber/lo"
1112
"github.com/sirupsen/logrus"
1213
corev1 "k8s.io/api/core/v1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
"k8s.io/client-go/kubernetes"
15-
"k8s.io/client-go/kubernetes/typed/core/v1"
16+
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
1617

1718
"github.com/castai/cluster-controller/internal/castai"
1819
"github.com/castai/cluster-controller/internal/waitext"
@@ -63,7 +64,6 @@ func (h *CheckNodeStatusHandler) Handle(ctx context.Context, action *castai.Clus
6364
case castai.ActionCheckNodeStatus_DELETED:
6465
log.Info("checking node deleted")
6566
return h.checkNodeDeleted(ctx, log, req)
66-
6767
}
6868

6969
return fmt.Errorf("unknown status to check provided node=%s status=%s", req.NodeName, req.NodeStatus)
@@ -176,13 +176,7 @@ func (h *CheckNodeStatusHandler) isNodeReady(node *corev1.Node, castNodeID, prov
176176
}
177177

178178
func containsUninitializedNodeTaint(taints []corev1.Taint) bool {
179-
for _, taint := range taints {
180-
// Some providers like AKS provider adds this taint even if node contains ready condition.
181-
if taint == taintCloudProviderUninitialized {
182-
return true
183-
}
184-
}
185-
return false
179+
return slices.Contains(taints, taintCloudProviderUninitialized)
186180
}
187181

188182
var taintCloudProviderUninitialized = corev1.Taint{

internal/actions/check_node_status_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ func TestCheckNodeStatusHandler_Handle_Deleted(t *testing.T) {
185185
},
186186
}
187187
for _, tt := range tests {
188-
tt := tt
189188
t.Run(tt.name, func(t *testing.T) {
190189
t.Parallel()
191190
clientSet := fake.NewClientset(tt.fields.tuneFakeObjects...)
@@ -434,7 +433,6 @@ func TestCheckNodeStatusHandler_Handle_Ready(t *testing.T) {
434433
},
435434
}
436435
for _, tt := range tests {
437-
tt := tt
438436
t.Run(tt.name, func(t *testing.T) {
439437
t.Parallel()
440438
clientSet := fake.NewClientset()

0 commit comments

Comments
 (0)