Skip to content

Commit 2d1b99e

Browse files
committed
lint: enable gocritic and govet linters
1 parent 8daa296 commit 2d1b99e

File tree

6 files changed

+38
-60
lines changed

6 files changed

+38
-60
lines changed

.golangci.yml

+13-34
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
linters-settings:
2-
depguard:
3-
list-type: blacklist
4-
packages:
5-
# logging is allowed only by logutils.Log, logrus
6-
# is allowed to use only in logutils package
7-
- github.com/sirupsen/logrus
8-
packages-with-error-message:
9-
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
102
dupl:
113
threshold: 100
124
funlen:
@@ -28,6 +20,7 @@ linters-settings:
2820
- octalLiteral
2921
- whyNoLint
3022
- wrapperFunc
23+
- unnamedResult
3124
gocyclo:
3225
min-complexity: 15
3326
goimports:
@@ -64,34 +57,34 @@ linters:
6457
- deadcode
6558
- depguard
6659
- dogsled
67-
#- dupl
60+
#- dupl - todo: check if use it
6861
- errcheck
69-
#- funlen
62+
#- funlen - need to fix errors
7063
- gochecknoinits
71-
#- goconst
72-
#- gocritic
73-
#- gocyclo
64+
#- goconst - need to fix errors
65+
- gocritic
66+
#- gocyclo - need to fix errors
7467
- gofmt
7568
- goimports
76-
#- golint
77-
#- gomnd
69+
#- golint - need to fix errors
70+
#- gomnd - need to fix errors
7871
- goprintffuncname
79-
#- gosec
72+
#- gosec - need to fix it errors
8073
- gosimple
81-
#- govet
74+
- govet
8275
- ineffassign
8376
- interfacer
84-
#- lll
77+
#- lll - need to fix errors
8578
- misspell
8679
- nakedret
8780
- rowserrcheck
8881
- scopelint
8982
- staticcheck
9083
- structcheck
91-
#- stylecheck
84+
#- stylecheck - need to fix errors
9285
- typecheck
9386
- unconvert
94-
#- unparam
87+
#- unparam - todo: need to check if use ittodo
9588
- unused
9689
- varcheck
9790
- whitespace
@@ -109,17 +102,3 @@ issues:
109102
- path: _test\.go
110103
linters:
111104
- gomnd
112-
113-
run:
114-
skip-dirs:
115-
- test/testdata_etc
116-
- internal/cache
117-
- internal/renameio
118-
- internal/robustio
119-
120-
# golangci.com configuration
121-
# https://github.com/golangci/golangci/wiki/Configuration
122-
service:
123-
golangci-lint-version: 1.23.x # use the fixed version to not introduce new linters unexpectedly
124-
prepare:
125-
- echo "here I can run custom commands, but no preparation needed for this repo"

pkg/daemon/daemon.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func NewDaemon() (Daemon, error) {
7474
return nil, err
7575
}
7676

77-
if err = smClient.Validate(); err != nil {
77+
if err := smClient.Validate(); err != nil {
7878
return nil, err
7979
}
8080

@@ -297,30 +297,30 @@ func (d *daemon) DeletePeriodicUpdate() {
297297
var guidList []net.HardwareAddr
298298
for _, pod := range pods {
299299
glog.Infof("DeletePeriodicUpdate(): pod namespace %s name %s", pod.Namespace, pod.Name)
300-
ibAnnotation, err := utils.ParseInfiniBandAnnotation(pod)
301-
if err == nil {
300+
ibAnnotation, netErr := utils.ParseInfiniBandAnnotation(pod)
301+
if netErr == nil {
302302
if !utils.IsPodNetworkConfiguredWithInfiniBand(ibAnnotation, networkName) {
303303
continue
304304
}
305305
}
306-
networks, err := netAttUtils.ParsePodNetworkAnnotation(pod)
306+
networks, netErr := netAttUtils.ParsePodNetworkAnnotation(pod)
307307
if err != nil {
308308
glog.Errorf("DeletePeriodicUpdate(): failed to read pod networkName annotations pod namespace %s name %s, with error: %v",
309-
pod.Namespace, pod.Name, err)
309+
pod.Namespace, pod.Name, netErr)
310310
continue
311311
}
312312

313-
network, err := utils.GetPodNetwork(networks, networkName)
314-
if err != nil {
313+
network, netErr := utils.GetPodNetwork(networks, networkName)
314+
if netErr != nil {
315315
glog.Errorf("DeletePeriodicUpdate(): failed to get pod networkName spec %s with error: %v",
316-
networkName, err)
316+
networkName, netErr)
317317
// skip failed pod
318318
continue
319319
}
320320

321-
allocatedGuid, err := utils.GetPodNetworkGuid(network)
321+
allocatedGuid, netErr := utils.GetPodNetworkGuid(network)
322322
if err != nil {
323-
glog.Errorf("DeletePeriodicUpdate(): %v", err)
323+
glog.Errorf("DeletePeriodicUpdate(): %v", netErr)
324324
continue
325325
}
326326

@@ -329,15 +329,15 @@ func (d *daemon) DeletePeriodicUpdate() {
329329
}
330330

331331
if ibCniSpec.PKey != "" && len(guidList) != 0 {
332-
pKey, err := utils.ParsePKey(ibCniSpec.PKey)
332+
pKey, pkeyErr := utils.ParsePKey(ibCniSpec.PKey)
333333
if err != nil {
334-
glog.Errorf("DeletePeriodicUpdate(): failed to parse PKey %s with error: %v", ibCniSpec.PKey, err)
334+
glog.Errorf("DeletePeriodicUpdate(): failed to parse PKey %s with error: %v", ibCniSpec.PKey, pkeyErr)
335335
continue
336336
}
337337

338-
if err = d.smClient.RemoveGuidsFromPKey(pKey, guidList); err != nil {
338+
if pkeyErr = d.smClient.RemoveGuidsFromPKey(pKey, guidList); err != nil {
339339
glog.Errorf("DeletePeriodicUpdate(): failed to config pKey with subnet manager %s with error: %v",
340-
d.smClient.Name(), err)
340+
d.smClient.Name(), pkeyErr)
341341
continue
342342
}
343343
}

pkg/guid/guid_pool.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func (p *guidPool) InitPool() error {
8585
return err
8686
}
8787

88-
for _, pod := range pods.Items {
89-
glog.V(3).Infof("InitPool(): checking pod for network annotations %v", pod)
90-
pod := pod // pin!
88+
for index := range pods.Items {
89+
glog.V(3).Infof("InitPool(): checking pod for network annotations %v", pods.Items[index])
90+
pod := pods.Items[index]
9191
networks, err := netAttUtils.ParsePodNetworkAnnotation(&pod)
9292
if err != nil {
9393
continue
@@ -119,7 +119,7 @@ func (p *guidPool) InitPool() error {
119119
return nil
120120
}
121121

122-
/// GenerateGUID generates a guid from the range
122+
// GenerateGUID generates a guid from the range
123123
func (p *guidPool) GenerateGUID(podNetworkId string) (string, error) {
124124
glog.Infof("GenerateGUID(): podNetworkId %s", podNetworkId)
125125

@@ -172,7 +172,7 @@ func (p *guidPool) ReleaseGUID(guid string) error {
172172
return nil
173173
}
174174

175-
/// AllocateGUID allocate guid for the pod
175+
// AllocateGUID allocate guid for the pod
176176
func (p *guidPool) AllocateGUID(podNetworkId, guid string) error {
177177
glog.Infof("AllocateGUID(): podNetworkId, %s guid %s", podNetworkId, guid)
178178

@@ -184,9 +184,8 @@ func (p *guidPool) AllocateGUID(podNetworkId, guid string) error {
184184
if podNetworkId != p.guidPodNetworkMap[guid] {
185185
return fmt.Errorf("failed to allocate requested guid %s, already allocated for %s",
186186
guid, p.guidPodNetworkMap[guid])
187-
} else {
188-
return nil
189187
}
188+
return nil
190189
}
191190

192191
p.guidPoolMap[guid] = true
@@ -196,7 +195,7 @@ func (p *guidPool) AllocateGUID(podNetworkId, guid string) error {
196195

197196
func (p *guidPool) getNextGUID(currentGUID net.HardwareAddr) net.HardwareAddr {
198197
for idx := 7; idx >= 0; idx-- {
199-
currentGUID[idx] += 1
198+
currentGUID[idx]++
200199
if currentGUID[idx] != 0 {
201200
break
202201
}
@@ -206,7 +205,7 @@ func (p *guidPool) getNextGUID(currentGUID net.HardwareAddr) net.HardwareAddr {
206205
}
207206

208207
func isAllowedGUID(guid string) bool {
209-
return guid != "00:00:00:00:00:00:00:00" && strings.ToLower(guid) != "ff:ff:ff:ff:ff:ff:ff:ff"
208+
return guid != "00:00:00:00:00:00:00:00" && !strings.EqualFold(guid, "ff:ff:ff:ff:ff:ff:ff:ff")
210209
}
211210

212211
func checkGuidRange(startGUID, endGUID net.HardwareAddr) error {

pkg/sm/plugins/ufm/ufm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func newUfmPlugin(conf []byte) (*ufmPlugin, error) {
5454
}
5555
}
5656

57-
isSecure := strings.ToLower(ufmConf.HttpSchema) == "https"
57+
isSecure := strings.EqualFold(ufmConf.HttpSchema, "https")
5858
client := httpDriver.NewClient(isSecure, httpDriver.AuthBasic, ufmConf.Certificate)
5959
auth := &httpDriver.BasicAuth{Username: ufmConf.Username, Password: ufmConf.Password}
6060
client.SetBasicAuth(auth)

pkg/utils/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func IsIbSriovCniInNetwork(networkSpec map[string]interface{}) (*IbSriovCniSpec,
124124
}
125125

126126
var plugins []*IbSriovCniSpec
127-
if err = json.Unmarshal(pluginsData, &plugins); err != nil {
127+
if err := json.Unmarshal(pluginsData, &plugins); err != nil {
128128
return nil, err
129129
}
130130

pkg/watcher/resource-event-handler/pod.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (p *podEventHandler) OnDelete(obj interface{}) {
132132
continue
133133
}
134134

135-
//check if pod network has guid
135+
// check if pod network has guid
136136
if !utils.PodNetworkHasGuid(network) {
137137
glog.Errorf("OnDelete(): pod %s has network %s marked as configured with InfiniBand without having guid",
138138
pod.Name, network.Name)

0 commit comments

Comments
 (0)