Skip to content

Commit be24a41

Browse files
authored
golangci-lint: migration to v2 (#2875)
1 parent d1c2586 commit be24a41

File tree

19 files changed

+133
-142
lines changed

19 files changed

+133
-142
lines changed

.github/workflows/pre-main.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ jobs:
7171
uses: mfinelli/setup-shfmt@1a143389339b48c4b48ae3cdc058f3dbe336a701 # v3.0.2
7272

7373
- name: Golangci-lint
74-
uses: golangci/golangci-lint-action@4696ba8babb6127d732c3c6dde519db15edab9ea # v6.3.3
74+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
7575
with:
76-
version: v1.64
7776
args: --timeout 10m0s
7877

7978
- name: Checkmake

.golangci.yml

+86-98
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,109 @@
1-
linters-settings:
2-
dupl:
3-
threshold: 100
4-
funlen:
5-
lines: 60
6-
statements: 45
7-
goconst:
8-
min-len: 4
9-
min-occurrences: 2
10-
gocritic:
11-
enabled-tags:
12-
- diagnostic
13-
- experimental
14-
- opinionated
15-
- performance
16-
- style
17-
disabled-checks:
18-
- whyNoLint
19-
settings:
20-
tooManyResultsChecker:
21-
# Maximum number of results.
22-
# Default: 5
23-
maxResults: 10
24-
gocyclo:
25-
min-complexity: 20
26-
govet:
27-
disable:
28-
- printf
29-
gosec:
30-
excludes:
31-
- G115
32-
lll:
33-
line-length: 250
34-
nolintlint:
35-
allow-unused: false # report any unused nolint directives
36-
require-explanation: false # do not require an explanation for nolint directives
37-
require-specific: true # require nolint directives to be specific about which linter is being skipped
38-
exhaustive:
39-
default-signifies-exhaustive: true
1+
version: "2"
402
linters:
41-
# please, do not use `enable-all`: it's deprecated and will be removed soon.
42-
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
43-
disable-all: true
3+
default: none
444
enable:
455
- bodyclose
6+
- copyloopvar
467
- dogsled
478
- errcheck
489
- exhaustive
49-
- copyloopvar
5010
- funlen
5111
- goconst
5212
- gocritic
5313
- gocyclo
54-
- gofmt
55-
- goimports
56-
- mnd
5714
- goprintffuncname
5815
- gosec
59-
- gosimple
6016
- govet
6117
- ineffassign
6218
- lll
6319
- misspell
20+
- mnd
6421
- nolintlint
6522
- rowserrcheck
6623
- staticcheck
67-
- stylecheck
68-
- typecheck
6924
- unconvert
7025
- unparam
7126
- unused
7227
- whitespace
73-
# do not enable:
74-
# - asciicheck
75-
# - depguard
76-
# - dupl
77-
# - gochecknoglobals
78-
# - gochecknoinits
79-
# - gocognit
80-
# - godot
81-
# - godox
82-
# - goerr113
83-
# - maligned
84-
# - nakedret
85-
# - nestif
86-
# - noctx
87-
# - prealloc
88-
# - revive
89-
# - copyloopvar
90-
# - testpackage
91-
# - wsl
92-
issues:
93-
# Excluding configuration per-path, per-linter, per-text and per-source
94-
exclude-rules:
95-
# Ignore magic numbers, inline strings and function length in tests.
96-
- path: _test\.go
97-
linters:
98-
- mnd
99-
- goconst
100-
- funlen
101-
- path: config/config.go
102-
linters:
103-
- mnd
104-
- path: _scaling.go
105-
linters:
106-
- gocritic
107-
- path: hugepages.go
108-
linters:
109-
- mnd
110-
- path: scheduling.go
111-
linters:
112-
- mnd
113-
# Ignore line length for string assignments (do not try and wrap regex definitions)
114-
- linters:
115-
- lll
116-
source: "^(.*= (\".*\"|`.*`))$"
117-
# https://github.com/go-critic/go-critic/issues/926
118-
- linters:
119-
- gocritic
120-
text: "unnecessaryDefer:"
121-
# Ignore static strings in tests
28+
settings:
29+
dupl:
30+
threshold: 100
31+
exhaustive:
32+
default-signifies-exhaustive: true
33+
funlen:
34+
lines: 60
35+
statements: 45
36+
goconst:
37+
min-len: 4
38+
min-occurrences: 2
39+
gocritic:
40+
disabled-checks:
41+
- whyNoLint
42+
enabled-tags:
43+
- diagnostic
44+
- experimental
45+
- opinionated
46+
- performance
47+
- style
48+
settings:
49+
tooManyResultsChecker:
50+
maxResults: 10
51+
gocyclo:
52+
min-complexity: 20
53+
gosec:
54+
excludes:
55+
- G115
56+
govet:
57+
disable:
58+
- printf
59+
lll:
60+
line-length: 250
61+
nolintlint:
62+
require-explanation: false
63+
require-specific: true
64+
allow-unused: false
65+
exclusions:
66+
generated: lax
67+
presets:
68+
- comments
69+
- common-false-positives
70+
- legacy
71+
- std-error-handling
72+
rules:
73+
- linters:
74+
- funlen
75+
- goconst
76+
- mnd
77+
path: _test\.go
78+
- linters:
79+
- mnd
80+
path: config/config.go
81+
- linters:
82+
- gocritic
83+
path: _scaling.go
84+
- linters:
85+
- mnd
86+
path: hugepages.go
87+
- linters:
88+
- mnd
89+
path: scheduling.go
90+
- linters:
91+
- lll
92+
source: ^(.*= (".*"|`.*`))$
93+
- linters:
94+
- gocritic
95+
text: 'unnecessaryDefer:'
96+
paths:
97+
- third_party$
98+
- builtin$
99+
- examples$
100+
formatters:
101+
enable:
102+
- gofmt
103+
- goimports
104+
exclusions:
105+
generated: lax
106+
paths:
107+
- third_party$
108+
- builtin$
109+
- examples$

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ GIT_COMMIT=$(shell script/create-version-files.sh)
4646
GIT_RELEASE=$(shell script/get-git-release.sh)
4747
GIT_PREVIOUS_RELEASE=$(shell script/get-git-previous-release.sh)
4848
CLAIM_FORMAT_VERSION=$(shell script/get-claim-version.sh)
49-
GOLANGCI_VERSION=v1.64.3
49+
GOLANGCI_VERSION=v2.0.1
5050
LINKER_CERTSUITE_RELEASE_FLAGS=-X github.com/redhat-best-practices-for-k8s/certsuite/pkg/versions.GitCommit=${GIT_COMMIT}
5151
LINKER_CERTSUITE_RELEASE_FLAGS+= -X github.com/redhat-best-practices-for-k8s/certsuite/pkg/versions.GitRelease=${GIT_RELEASE}
5252
LINKER_CERTSUITE_RELEASE_FLAGS+= -X github.com/redhat-best-practices-for-k8s/certsuite/pkg/versions.GitPreviousRelease=${GIT_PREVIOUS_RELEASE}

cmd/certsuite/claim/show/csv/csv.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func buildCSV(claimScheme *claim.Schema, cnfType string, catalogMap map[string]c
153153
}
154154

155155
opVers := ""
156-
for i, op := range claimScheme.Claim.Configurations.TestOperators {
156+
for i, op := range claimScheme.Claim.TestOperators {
157157
if i == 0 {
158158
opVers = op.Version
159159
} else {

internal/clientsholder/clientsholder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func GetClientConfigFromRestConfig(restConfig *rest.Config) *clientcmdapi.Config
219219
Clusters: map[string]*clientcmdapi.Cluster{
220220
"default-cluster": {
221221
Server: restConfig.Host,
222-
CertificateAuthority: restConfig.TLSClientConfig.CAFile,
222+
CertificateAuthority: restConfig.CAFile,
223223
},
224224
},
225225
Contexts: map[string]*clientcmdapi.Context{

pkg/autodiscover/autodiscover_operators.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func getAllNamespaces(oc corev1client.CoreV1Interface) (allNs []string, err erro
135135
return allNs, fmt.Errorf("error getting all namespaces, err: %v", err)
136136
}
137137
for index := range nsList.Items {
138-
allNs = append(allNs, nsList.Items[index].ObjectMeta.Name)
138+
allNs = append(allNs, nsList.Items[index].Name)
139139
}
140140
return allNs, nil
141141
}

pkg/autodiscover/autodiscover_pods.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func findPodsByLabels(oc corev1client.CoreV1Interface, labels []labelObject, nam
6161
}
6262
// Filter out any pod set to be deleted
6363
for i := 0; i < len(pods.Items); i++ {
64-
if pods.Items[i].ObjectMeta.DeletionTimestamp == nil && pods.Items[i].Status.Phase == corev1.PodRunning {
64+
if pods.Items[i].DeletionTimestamp == nil && pods.Items[i].Status.Phase == corev1.PodRunning {
6565
runningPods = append(runningPods, pods.Items[i])
6666
}
6767
allPods = append(allPods, pods.Items[i])

pkg/autodiscover/autodiscover_podset.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func FindCrObjectByNameByNamespace(scalesGetter scale.ScalesGetter, ns, name str
5858
func isDeploymentsPodsMatchingAtLeastOneLabel(labels []labelObject, namespace string, deployment *appsv1.Deployment) bool {
5959
for _, aLabelObject := range labels {
6060
log.Debug("Searching pods in deployment %q found in ns %q using label %s=%s", deployment.Name, namespace, aLabelObject.LabelKey, aLabelObject.LabelValue)
61-
if deployment.Spec.Template.ObjectMeta.Labels[aLabelObject.LabelKey] == aLabelObject.LabelValue {
61+
if deployment.Spec.Template.Labels[aLabelObject.LabelKey] == aLabelObject.LabelValue {
6262
log.Info("Deployment %s found in ns=%s", deployment.Name, namespace)
6363
return true
6464
}
@@ -106,7 +106,7 @@ func findDeploymentsByLabels(
106106
func isStatefulSetsMatchingAtLeastOneLabel(labels []labelObject, namespace string, statefulSet *appsv1.StatefulSet) bool {
107107
for _, aLabelObject := range labels {
108108
log.Debug("Searching pods in statefulset %q found in ns %q using label %s=%s", statefulSet.Name, namespace, aLabelObject.LabelKey, aLabelObject.LabelValue)
109-
if statefulSet.Spec.Template.ObjectMeta.Labels[aLabelObject.LabelKey] == aLabelObject.LabelValue {
109+
if statefulSet.Spec.Template.Labels[aLabelObject.LabelKey] == aLabelObject.LabelValue {
110110
log.Info("StatefulSet %s found in ns=%s", statefulSet.Name, namespace)
111111
return true
112112
}

pkg/podhelper/podhelper_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,19 @@ func Test_followOwnerReferences(t *testing.T) {
108108
client := k8sDynamicFake.NewSimpleDynamicClient(scheme, rep1, dep1, csv1, node1, pod1)
109109

110110
// Spoof the get functions
111-
client.Fake.AddReactor("get", "ClusterServiceVersion", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
111+
client.AddReactor("get", "ClusterServiceVersion", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
112112
return true, csv1, nil
113113
})
114-
client.Fake.AddReactor("get", "Deployment", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
114+
client.AddReactor("get", "Deployment", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
115115
return true, dep1, nil
116116
})
117-
client.Fake.AddReactor("get", "ReplicaSet", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
117+
client.AddReactor("get", "ReplicaSet", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
118118
return true, rep1, nil
119119
})
120-
client.Fake.AddReactor("get", "Node", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
120+
client.AddReactor("get", "Node", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
121121
return true, node1, nil
122122
})
123-
client.Fake.AddReactor("get", "Pod", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
123+
client.AddReactor("get", "Pod", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
124124
return true, pod1, nil
125125
})
126126

@@ -225,11 +225,11 @@ func TestGetTopOwners(t *testing.T) {
225225
client := k8sDynamicFake.NewSimpleDynamicClient(k8sscheme.Scheme, testDeployment, testPod)
226226

227227
// Spoof the get functions
228-
client.Fake.AddReactor("get", "Deployment", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
228+
client.AddReactor("get", "Deployment", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
229229
return true, testDeployment, nil
230230
})
231231

232-
client.Fake.AddReactor("get", "Pod", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
232+
client.AddReactor("get", "Pod", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
233233
return true, testPod, nil
234234
})
235235

pkg/provider/containers.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ func (c *Container) IsTagEmpty() bool {
189189

190190
func (c *Container) IsReadOnlyRootFilesystem(logger *log.Logger) bool {
191191
logger.Info("Testing Container %q", c)
192-
if c.Container.SecurityContext == nil || c.Container.SecurityContext.ReadOnlyRootFilesystem == nil {
192+
if c.SecurityContext == nil || c.SecurityContext.ReadOnlyRootFilesystem == nil {
193193
return false
194194
}
195-
return *c.Container.SecurityContext.ReadOnlyRootFilesystem
195+
return *c.SecurityContext.ReadOnlyRootFilesystem
196196
}
197197

198198
func (c *Container) IsContainerRunAsNonRoot(podRunAsNonRoot *bool) (isContainerRunAsNonRoot bool, reason string) {

pkg/provider/isolation.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func LoadBalancingDisabled(p *Pod) bool {
8787
cpuLoadBalancingDisabled := false
8888
irqLoadBalancingDisabled := false
8989

90-
if v, ok := p.ObjectMeta.Annotations["cpu-load-balancing.crio.io"]; ok {
90+
if v, ok := p.Annotations["cpu-load-balancing.crio.io"]; ok {
9191
if v == disableVar {
9292
cpuLoadBalancingDisabled = true
9393
} else {
@@ -97,7 +97,7 @@ func LoadBalancingDisabled(p *Pod) bool {
9797
log.Debug("Annotation cpu-load-balancing.crio.io is missing.")
9898
}
9999

100-
if v, ok := p.ObjectMeta.Annotations["irq-load-balancing.crio.io"]; ok {
100+
if v, ok := p.Annotations["irq-load-balancing.crio.io"]; ok {
101101
if v == disableVar {
102102
irqLoadBalancingDisabled = true
103103
} else {

pkg/provider/operators.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ func createOperators(csvs []*olmv1Alpha.ClusterServiceVersion,
169169
uniqueCsvs := getUniqueCsvListByName(csvs)
170170

171171
for _, csv := range uniqueCsvs {
172-
if !(csv.Status.Phase == olmv1Alpha.CSVPhaseSucceeded || !succeededRequired) {
172+
// Skip CSVs that are not in the Succeeded phase if the flag is set.
173+
if csv.Status.Phase != olmv1Alpha.CSVPhaseSucceeded && succeededRequired {
173174
continue
174175
}
175176
op := &Operator{Name: csv.Name, Namespace: csv.Namespace}

0 commit comments

Comments
 (0)