Skip to content

Commit 0b6a64d

Browse files
committed
sync linter settings with cluster-api repo and fix findings
1 parent 347f7c4 commit 0b6a64d

File tree

18 files changed

+417
-125
lines changed

18 files changed

+417
-125
lines changed

.golangci.yml

Lines changed: 101 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,87 @@
11
linters:
2-
enable-all: true
3-
disable:
4-
- dupl
5-
- errorlint
6-
- exhaustivestruct
7-
- funlen
8-
- gochecknoglobals
9-
- gochecknoinits
10-
- gocognit
11-
- godox
12-
- goerr113
13-
- gomnd
14-
- interfacer
15-
- lll
16-
- maligned
17-
- nlreturn
18-
- whitespace
19-
- wrapcheck
20-
- wsl
21-
# Run with --fast=false for more extensive checks
22-
fast: true
2+
disable-all: true
3+
enable:
4+
- asciicheck
5+
- bodyclose
6+
- cyclop
7+
- deadcode
8+
- depguard
9+
- dogsled
10+
- durationcheck
11+
- errcheck
12+
- exportloopref
13+
- forbidigo
14+
- gci
15+
- goconst
16+
- gocritic
17+
- gocyclo
18+
- godot
19+
- gofmt
20+
- gofumpt
21+
- goheader
22+
- goimports
23+
- gomodguard
24+
- goprintffuncname
25+
- gosec
26+
- gosimple
27+
- govet
28+
- ifshort
29+
- importas
30+
- ineffassign
31+
- makezero
32+
- misspell
33+
- nakedret
34+
- nestif
35+
- nilerr
36+
- noctx
37+
- nolintlint
38+
- prealloc
39+
- predeclared
40+
- revive
41+
- rowserrcheck
42+
- sqlclosecheck
43+
- staticcheck
44+
- structcheck
45+
- stylecheck
46+
- thelper
47+
- typecheck
48+
- unconvert
49+
- unparam
50+
- unused
51+
- varcheck
52+
- wastedassign
53+
- whitespace
54+
2355
linters-settings:
2456
cyclop:
2557
# TODO(sbuerin) fix remaining findings and set to 20 afterwards
2658
max-complexity: 30
59+
ifshort:
60+
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
61+
max-decl-chars: 50
2762
goimports:
2863
local-prefixes: sigs.k8s.io/cluster-api-provider-openstack
64+
importas:
65+
no-unaliased: true
66+
alias:
67+
# Kubernetes
68+
- pkg: k8s.io/api/core/v1
69+
alias: corev1
70+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
71+
alias: apiextensionsv1
72+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
73+
alias: metav1
74+
- pkg: k8s.io/apimachinery/pkg/api/errors
75+
alias: apierrors
76+
- pkg: k8s.io/apimachinery/pkg/util/errors
77+
alias: kerrors
78+
# Controller Runtime
79+
- pkg: sigs.k8s.io/controller-runtime
80+
alias: ctrl
81+
staticcheck:
82+
go: "1.16"
83+
stylecheck:
84+
go: "1.16"
2985
nestif:
3086
# minimal complexity of if statements to report, 5 by default
3187
# TODO(sbuerin) fix remaining findings and set to 5 after:
@@ -34,16 +90,34 @@ linters-settings:
3490

3591
issues:
3692
max-same-issues: 0
37-
max-per-linter: 0
93+
max-issues-per-linter: 0
3894
# List of regexps of issue texts to exclude, empty list by default.
39-
exclude:
40-
- Using the variable on range scope `(tc)|(rt)|(tt)|(test)|(testcase)|(testCase)` in function literal
41-
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
95+
exclude-rules:
96+
- linters:
97+
- gosec
98+
text: "G108: Profiling endpoint is automatically exposed on /debug/pprof"
99+
- linters:
100+
- gosec
101+
text: "G108: Profiling endpoint is automatically exposed on /debug/pprof"
102+
# This directive allows the embed package to be imported with an underscore everywhere.
103+
- linters:
104+
- revive
105+
source: _ "embed"
106+
- linters:
107+
- revive
108+
- stylecheck
109+
path: (test)/.*.go
110+
text: should not use dot imports
111+
- linters:
112+
- revive
113+
path: test/e2e/shared/defaults.go
114+
text: "exported: exported const .* should have comment \\(or a comment on this block\\) or be unexported"
42115
run:
43-
timeout: 6m
116+
timeout: 10m
44117
build-tags:
45118
- e2e
46119

47120
skip-files:
48121
- "zz_generated.*\\.go$"
49-
- ".*_mock\\.go"
122+
- ".*conversion.*\\.go$"
123+
allow-parallel-runners: true

api/v1alpha3/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,19 @@ func (r SecurityGroupRule) Equal(x SecurityGroupRule) bool {
227227
type InstanceState string
228228

229229
var (
230+
// InstanceStateBuilding is the string representing an instance in a building state.
230231
InstanceStateBuilding = InstanceState("BUILDING")
231232

233+
// InstanceStateActive is the string representing an instance in an active state.
232234
InstanceStateActive = InstanceState("ACTIVE")
233235

236+
// InstanceStateError is the string representing an instance in an error state.
234237
InstanceStateError = InstanceState("ERROR")
235238

239+
// InstanceStateStopped is the string representing an instance in a stopped state.
236240
InstanceStateStopped = InstanceState("STOPPED")
237241

242+
// InstanceStateShutoff is the string representing an instance in a shutoff state.
238243
InstanceStateShutoff = InstanceState("SHUTOFF")
239244
)
240245

api/v1alpha4/openstackmachinetemplate_webhook.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ var _ webhook.Validator = &OpenStackMachineTemplate{}
4242
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
4343
func (r *OpenStackMachineTemplate) ValidateCreate() error {
4444
var allErrs field.ErrorList
45-
spec := r.Spec.Template.Spec
4645

47-
if spec.ProviderID != nil {
46+
if r.Spec.Template.Spec.ProviderID != nil {
4847
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "template", "spec", "providerID"), "cannot be set in templates"))
4948
}
5049

api/v1alpha4/openstackmachinetemplate_webhook_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/gomega"
23-
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
)
2525

2626
func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
@@ -67,7 +67,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
6767
},
6868
},
6969
},
70-
ObjectMeta: v1.ObjectMeta{
70+
ObjectMeta: metav1.ObjectMeta{
7171
Name: "foo",
7272
},
7373
},
@@ -80,7 +80,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
8080
},
8181
},
8282
},
83-
ObjectMeta: v1.ObjectMeta{
83+
ObjectMeta: metav1.ObjectMeta{
8484
Name: "bar",
8585
},
8686
},

api/v1alpha4/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,19 @@ func (r SecurityGroupRule) Equal(x SecurityGroupRule) bool {
260260
type InstanceState string
261261

262262
var (
263+
// InstanceStateBuilding is the string representing an instance in a building state.
263264
InstanceStateBuilding = InstanceState("BUILDING")
264265

266+
// InstanceStateActive is the string representing an instance in an active state.
265267
InstanceStateActive = InstanceState("ACTIVE")
266268

269+
// InstanceStateError is the string representing an instance in an error state.
267270
InstanceStateError = InstanceState("ERROR")
268271

272+
// InstanceStateStopped is the string representing an instance in a stopped state.
269273
InstanceStateStopped = InstanceState("STOPPED")
270274

275+
// InstanceStateShutoff is the string representing an instance in a shutoff state.
271276
InstanceStateShutoff = InstanceState("SHUTOFF")
272277
)
273278

controllers/openstackmachine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func (r *OpenStackMachineReconciler) reconcileLoadBalancerMember(logger logr.Log
399399
return loadbalancerService.ReconcileLoadBalancerMember(openStackCluster, machine, openStackMachine, clusterName, ip)
400400
}
401401

402-
// OpenStackClusterToOpenStackMachine is a handler.ToRequestsFunc to be used to enqeue requests for reconciliation
402+
// OpenStackClusterToOpenStackMachines is a handler.ToRequestsFunc to be used to enqeue requests for reconciliation
403403
// of OpenStackMachines.
404404
func (r *OpenStackMachineReconciler) OpenStackClusterToOpenStackMachines(ctx context.Context) handler.MapFunc {
405405
log := ctrl.LoggerFrom(ctx)

hack/tools/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.16
55
require (
66
github.com/a8m/envsubst v1.2.0
77
github.com/golang/mock v1.4.4
8-
github.com/golangci/golangci-lint v1.38.0
8+
github.com/golangci/golangci-lint v1.40.1
99
github.com/itchyny/gojq v0.12.2
1010
github.com/onsi/ginkgo v1.16.4
1111
k8s.io/code-generator v0.21.1

0 commit comments

Comments
 (0)