Skip to content

Commit a97a95f

Browse files
authored
Merge pull request #813 from anshuman-agarwala/lint-enhacement
Enhanced Linting
2 parents 387b1bc + 18694e1 commit a97a95f

Some content is hidden

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

51 files changed

+464
-265
lines changed

.golangci.yml

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- asasalint
5+
- asciicheck
6+
- bodyclose
7+
- containedctx
8+
- copyloopvar
9+
- decorder
10+
- dogsled
11+
- errcheck
12+
- errchkjson
13+
- execinquery
14+
# - gci
15+
- goconst
16+
# - gocritic
17+
- gocyclo
18+
- godot
19+
- gofmt
20+
- goimports
21+
- goprintffuncname
22+
# - gosec
23+
- gosimple
24+
- govet
25+
# - importas
26+
- ineffassign
27+
- misspell
28+
- nakedret
29+
- nilerr
30+
- noctx
31+
- nolintlint
32+
- nosprintfhostport
33+
- prealloc
34+
- predeclared
35+
- reassign
36+
# - revive
37+
- rowserrcheck
38+
- staticcheck
39+
# - stylecheck
40+
# - thelper
41+
- typecheck
42+
- unconvert
43+
- unparam
44+
- unused
45+
- usestdlibvars
46+
- whitespace
47+
48+
linters-settings:
49+
gocyclo:
50+
min-complexity: 20
51+
godot:
52+
# declarations - for top level declaration comments (default);
53+
# toplevel - for top level comments;
54+
# all - for all comments.
55+
scope: toplevel
56+
exclude:
57+
- '^ \+.*'
58+
- '^ ANCHOR.*'
59+
gci:
60+
sections:
61+
- standard
62+
- default
63+
- prefix(github.com/IBM)
64+
- prefix(k8s.io)
65+
- prefix(sigs.k8s.io)
66+
- blank
67+
- dot
68+
importas:
69+
no-unaliased: true
70+
alias:
71+
# Kubernetes
72+
- pkg: k8s.io/api/core/v1
73+
alias: corev1
74+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
75+
alias: apiextensionsv1
76+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
77+
alias: metav1
78+
- pkg: k8s.io/apimachinery/pkg/api/errors
79+
alias: apierrors
80+
- pkg: k8s.io/apimachinery/pkg/util/errors
81+
alias: kerrors
82+
# Controller Runtime
83+
- pkg: sigs.k8s.io/controller-runtime
84+
alias: ctrl
85+
nolintlint:
86+
allow-unused: false
87+
# allow-leading-space: false
88+
require-specific: true
89+
gosec:
90+
excludes:
91+
- G307 # Deferring unsafe method "Close" on type "\*os.File"
92+
- G108 # Profiling endpoint is automatically exposed on /debug/pprof
93+
gocritic:
94+
enabled-tags:
95+
- experimental
96+
disabled-checks:
97+
- appendAssign
98+
- dupImport # https://github.com/go-critic/go-critic/issues/845
99+
- evalOrder
100+
- ifElseChain
101+
- octalLiteral
102+
- regexpSimplify
103+
- sloppyReassign
104+
- truncateCmp
105+
- typeDefFirst
106+
- unnamedResult
107+
- unnecessaryDefer
108+
- whyNoLint
109+
- wrapperFunc
110+
unused:
111+
go: "1.23"
112+
issues:
113+
exclude-files:
114+
- "zz_generated.*\\.go$"
115+
max-same-issues: 0
116+
max-issues-per-linter: 0
117+
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
118+
# changes in PRs and avoid nitpicking.
119+
exclude-use-default: false
120+
exclude-rules:
121+
- linters:
122+
- gci
123+
path: _test\.go
124+
- linters:
125+
- revive
126+
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
127+
- linters:
128+
- errcheck
129+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
130+
# Exclude some packages or code to require comments, for example test code, or fake clients.
131+
- linters:
132+
- revive
133+
text: exported (method|function|type|const) (.+) should have comment or be unexported
134+
source: (func|type).*Fake.*
135+
- linters:
136+
- revive
137+
text: exported (method|function|type|const) (.+) should have comment or be unexported
138+
path: fake_\.go
139+
- linters:
140+
- revive
141+
text: exported (method|function|type|const) (.+) should have comment or be unexported
142+
path: "(framework|e2e)/.*.go"
143+
# Disable unparam "always receives" which might not be really
144+
# useful when building libraries.
145+
- linters:
146+
- unparam
147+
text: always receives
148+
# Dot imports for gomega or ginkgo are allowed
149+
# within test files.
150+
- path: _test\.go
151+
text: should not use dot imports
152+
- path: (framework|e2e)/.*.go
153+
text: should not use dot imports
154+
- path: _test\.go
155+
text: cyclomatic complexity
156+
# Append should be able to assign to a different var/slice.
157+
- linters:
158+
- gocritic
159+
text: "appendAssign: append result not assigned to the same slice"
160+
# Disable linters for conversion
161+
- linters:
162+
- staticcheck
163+
text: "SA1019: in.(.+) is deprecated"
164+
path: .*(api|types)\/.*\/.*conversion.*\.go$
165+
- linters:
166+
- revive
167+
text: exported (method|function|type|const) (.+) should have comment or be unexported
168+
path: .*(api|types)\/.*\/.*conversion.*\.go$
169+
- linters:
170+
- revive
171+
text: "var-naming: don't use underscores in Go names;"
172+
path: .*(api|types)\/.*\/.*conversion.*\.go$
173+
- linters:
174+
- revive
175+
text: "receiver-naming: receiver name"
176+
path: .*(api|types)\/.*\/.*conversion.*\.go$
177+
- linters:
178+
- stylecheck
179+
text: "ST1003: should not use underscores in Go names;"
180+
path: .*(api|types)\/.*\/.*conversion.*\.go$
181+
- linters:
182+
- stylecheck
183+
text: "ST1016: methods on the same type should have the same receiver name"
184+
path: .*(api|types)\/.*\/.*conversion.*\.go$
185+
# hack/tools
186+
- linters:
187+
- typecheck
188+
text: import (".+") is a program, not an importable package
189+
path: ^tools\.go$
190+
# We don't care about defer in for loops in test files.
191+
- linters:
192+
- gocritic
193+
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
194+
path: _test\.go
195+
196+
run:
197+
timeout: 10m
198+
build-tags:
199+
- tools
200+
- e2e
201+
allow-parallel-runners: true
202+
go: "1.23"

adhoc-controllers/controllers/nodeupdate_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ import (
2424
apierrors "k8s.io/apimachinery/pkg/api/errors"
2525
"k8s.io/apimachinery/pkg/runtime"
2626
"k8s.io/klog/v2"
27+
2728
ctrl "sigs.k8s.io/controller-runtime"
2829
"sigs.k8s.io/controller-runtime/pkg/client"
2930
"sigs.k8s.io/ibm-powervs-block-csi-driver/pkg/cloud"
3031
)
3132

32-
// NodeUpdateReconciler reconciles a NodeUpdate object
33+
// NodeUpdateReconciler reconciles a NodeUpdate object.
3334
type NodeUpdateReconciler struct {
3435
Client client.Client
3536
Scheme *runtime.Scheme
@@ -41,7 +42,6 @@ type NodeUpdateReconciler struct {
4142
// For more details, check Reconcile and its Result here:
4243
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
4344
func (r *NodeUpdateReconciler) Reconcile(_ context.Context, req ctrl.Request) (ctrl.Result, error) {
44-
4545
// Fetch the Node instance
4646
node := corev1.Node{}
4747
err := r.Client.Get(context.Background(), req.NamespacedName, &node)

adhoc-controllers/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,22 @@ import (
2020
"flag"
2121
"os"
2222

23-
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
24-
// to ensure that exec-entrypoint and run can make use of them.
25-
_ "k8s.io/client-go/plugin/pkg/client/auth"
26-
2723
"k8s.io/apimachinery/pkg/runtime"
2824
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2925
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
26+
3027
ctrl "sigs.k8s.io/controller-runtime"
3128
"sigs.k8s.io/controller-runtime/pkg/healthz"
3229
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3330
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
3431
"sigs.k8s.io/controller-runtime/pkg/webhook"
35-
3632
"sigs.k8s.io/ibm-powervs-block-csi-driver/adhoc-controllers/controllers"
33+
3734
//+kubebuilder:scaffold:imports
35+
36+
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
37+
// to ensure that exec-entrypoint and run can make use of them.
38+
_ "k8s.io/client-go/plugin/pkg/client/auth"
3839
)
3940

4041
var (

cmd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ limitations under the License.
1616

1717
package main
1818

19-
//DONE
19+
// DONE.
2020

2121
import (
2222
"flag"
2323

24-
"sigs.k8s.io/ibm-powervs-block-csi-driver/pkg/driver"
25-
2624
"k8s.io/klog/v2"
25+
26+
"sigs.k8s.io/ibm-powervs-block-csi-driver/pkg/driver"
2727
)
2828

2929
func main() {

cmd/options.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ limitations under the License.
1616

1717
package main
1818

19-
//DONE
19+
// DONE.
2020

2121
import (
2222
"flag"
2323
"os"
2424
"strings"
2525

26+
"k8s.io/klog/v2"
27+
2628
"sigs.k8s.io/ibm-powervs-block-csi-driver/cmd/options"
2729
"sigs.k8s.io/ibm-powervs-block-csi-driver/pkg/driver"
28-
29-
"k8s.io/klog/v2"
3030
)
3131

3232
// Options is the combined set of options for all operating modes.
@@ -38,7 +38,7 @@ type Options struct {
3838
*options.NodeOptions
3939
}
4040

41-
// used for testing
41+
// used for testing.
4242
var osExit = os.Exit
4343

4444
// GetOptions parses the command line options and returns a struct that contains
@@ -63,7 +63,7 @@ func GetOptions(fs *flag.FlagSet) *Options {
6363

6464
switch {
6565
case cmd == string(driver.ControllerMode):
66-
//controllerOptions.AddFlags(fs)
66+
// controllerOptions.AddFlags(fs)
6767
args = os.Args[2:]
6868
mode = driver.ControllerMode
6969

@@ -73,12 +73,12 @@ func GetOptions(fs *flag.FlagSet) *Options {
7373
mode = driver.NodeMode
7474

7575
case cmd == string(driver.AllMode):
76-
//controllerOptions.AddFlags(fs)
76+
// controllerOptions.AddFlags(fs)
7777
nodeOptions.AddFlags(fs)
7878
args = os.Args[2:]
7979

8080
case strings.HasPrefix(cmd, "-"):
81-
//controllerOptions.AddFlags(fs)
81+
// controllerOptions.AddFlags(fs)
8282
nodeOptions.AddFlags(fs)
8383
args = os.Args[1:]
8484

@@ -95,7 +95,7 @@ func GetOptions(fs *flag.FlagSet) *Options {
9595
if *version {
9696
info, err := driver.GetVersionJSON()
9797
if err != nil {
98-
klog.Fatalf("error while retriving the CSI driver version. err: %v", err)
98+
klog.Fatalf("error while retrieving the CSI driver version. err: %v", err)
9999
}
100100
klog.Info(info)
101101
osExit(0)

cmd/options/controller_options.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ limitations under the License.
1616

1717
package options
1818

19-
//DONE
20-
21-
//// ControllerOptions contains options and configuration settings for the controller service.
22-
//type ControllerOptions struct {
23-
// // ExtraTags is a map of tags that will be attached to each dynamically provisioned
24-
// // resource.
25-
// ExtraTags map[string]string
26-
// //// ExtraVolumeTags is a map of tags that will be attached to each dynamically provisioned
27-
// //// volume.
28-
// //// DEPRECATED: Use ExtraTags instead.
29-
// //ExtraVolumeTags map[string]string
30-
// // ID of the kubernetes cluster.
31-
// KubernetesClusterID string
32-
//}
19+
/*
20+
// ControllerOptions contains options and configuration settings for the controller service.
21+
type ControllerOptions struct {
22+
// ExtraTags is a map of tags that will be attached to each dynamically provisioned
23+
// resource.
24+
ExtraTags map[string]string
25+
//// ExtraVolumeTags is a map of tags that will be attached to each dynamically provisioned
26+
//// volume.
27+
//// DEPRECATED: Use ExtraTags instead.
28+
//ExtraVolumeTags map[string]string
29+
// ID of the kubernetes cluster.
30+
KubernetesClusterID string
31+
}
3332
34-
//func (s *ControllerOptions) AddFlags(fs *flag.FlagSet) {
35-
// //fs.Var(cliflag.NewMapStringString(&s.ExtraTags), "extra-tags", "Extra tags to attach to each dynamically provisioned resource. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'")
36-
// //fs.Var(cliflag.NewMapStringString(&s.ExtraVolumeTags), "extra-volume-tags", "DEPRECATED: Please use --extra-tags instead. Extra volume tags to attach to each dynamically provisioned volume. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'")
37-
// //fs.StringVar(&s.KubernetesClusterID, "k8s-tag-cluster-id", "", "ID of the Kubernetes cluster used for tagging provisioned EBS volumes (optional).")
38-
//}
33+
func (s *ControllerOptions) AddFlags(fs *flag.FlagSet) {
34+
fs.Var(cliflag.NewMapStringString(&s.ExtraTags), "extra-tags", "Extra tags to attach to each dynamically provisioned resource. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'")
35+
fs.Var(cliflag.NewMapStringString(&s.ExtraVolumeTags), "extra-volume-tags", "DEPRECATED: Please use --extra-tags instead. Extra volume tags to attach to each dynamically provisioned volume. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'")
36+
fs.StringVar(&s.KubernetesClusterID, "k8s-tag-cluster-id", "", "ID of the Kubernetes cluster used for tagging provisioned EBS volumes (optional).")
37+
}.
38+
*/

cmd/options/node_options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
package options
1818

19-
//DONE
19+
// DONE.
2020

2121
import (
2222
"flag"

cmd/options/server_options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
package options
1818

19-
//DONE
19+
// DONE.
2020

2121
import (
2222
"flag"

0 commit comments

Comments
 (0)