Skip to content

Commit 27dbc90

Browse files
Upgrade golangci-lint to 1.64.8
All above these version: github.com/golangci/golangci-lint/cmd/[email protected] github.com/daixiang0/[email protected] sigs.k8s.io/kustomize/kustomize/[email protected] gosec => 2.22.2 kustomize => 5.6. ref: https://issues.redhat.com/browse/ACM-8341 Signed-off-by: yiraeChristineKim <[email protected]>
1 parent a522425 commit 27dbc90

16 files changed

+179
-170
lines changed

build/common/Makefile.common.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
# https://github.com/kubernetes-sigs/controller-tools/releases/latest
66
CONTROLLER_GEN_VERSION := v0.16.3
77
# https://github.com/kubernetes-sigs/kustomize/releases/latest
8-
KUSTOMIZE_VERSION := v5.4.3
8+
KUSTOMIZE_VERSION := v5.6.0
99
# https://github.com/golangci/golangci-lint/releases/latest
10-
GOLANGCI_VERSION := v1.52.2
10+
GOLANGCI_VERSION := v1.64.8
1111
# https://github.com/mvdan/gofumpt/releases/latest
1212
GOFUMPT_VERSION := v0.7.0
1313
# https://github.com/daixiang0/gci/releases/latest
1414
GCI_VERSION := v0.13.5
1515
# https://github.com/securego/gosec/releases/latest
16-
GOSEC_VERSION := v2.21.3
16+
GOSEC_VERSION := v2.22.2
1717
# https://github.com/kubernetes-sigs/kubebuilder/releases/latest
1818
KBVERSION := 3.15.1
1919
# https://github.com/kubernetes/kubernetes/releases/latest

build/common/config/.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ run:
2424
linters:
2525
enable-all: true
2626
disable:
27+
- mnd # Disabled as tech debt: Magic number detection
2728
- bodyclose
2829
- cyclop
2930
- depguard

internal/expanders/expanders_utils_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ func assertEqual(t *testing.T, a interface{}, b interface{}) {
1111
t.Helper()
1212

1313
if a != b {
14-
t.Fatalf(cmp.Diff(a, b))
14+
t.Fatal(cmp.Diff(a, b))
1515
}
1616
}
1717

1818
func assertReflectEqual(t *testing.T, a interface{}, b interface{}) {
1919
t.Helper()
2020

2121
if !reflect.DeepEqual(a, b) {
22-
t.Fatalf(cmp.Diff(a, b))
22+
t.Fatal(cmp.Diff(a, b))
2323
}
2424
}

internal/expanders/gatekeeper.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
package expanders
33

44
import (
5-
"fmt"
6-
75
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
86

97
"open-cluster-management.io/policy-generator-plugin/internal/types"
@@ -54,7 +52,7 @@ func (g GatekeeperPolicyExpander) Expand(
5452
constraintName, _, _ := unstructured.NestedString(manifest, "metadata", "name")
5553
constraintKind, _, _ := unstructured.NestedString(manifest, "kind")
5654

57-
auditConfigPolicyName := fmt.Sprintf("inform-gatekeeper-audit-%s", constraintName)
55+
auditConfigPolicyName := "inform-gatekeeper-audit-" + constraintName
5856
auditConfigurationPolicy := map[string]interface{}{
5957
"objectDefinition": map[string]interface{}{
6058
"apiVersion": configPolicyAPIVersion,
@@ -87,7 +85,7 @@ func (g GatekeeperPolicyExpander) Expand(
8785
}
8886
// Further improvements here could be made by having the user specify the Gatekeeper namespace and
8987
// targeting the events for the constraint kind to just that namespace.
90-
admissionConfigPolicyName := fmt.Sprintf("inform-gatekeeper-admission-%s", constraintName)
88+
admissionConfigPolicyName := "inform-gatekeeper-admission-" + constraintName
9189
admissionConfigurationPolicy := map[string]interface{}{
9290
"objectDefinition": map[string]interface{}{
9391
"apiVersion": configPolicyAPIVersion,

internal/expanders/gatekeeper_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ func TestGatekeeperCanHandle(t *testing.T) {
1717
}
1818

1919
for _, test := range tests {
20-
test := test
2120
t.Run(
22-
fmt.Sprintf("kind=%s", test.kind),
21+
"kind="+test.kind,
2322
func(t *testing.T) {
2423
t.Parallel()
24+
2525
manifest := map[string]interface{}{
2626
"apiVersion": gatekeeperConstraintAPIVersion,
2727
"kind": test.kind,
@@ -46,11 +46,11 @@ func TestGatekeeperCanHandleInvalid(t *testing.T) {
4646
}
4747

4848
for _, test := range tests {
49-
test := test
5049
t.Run(
5150
fmt.Sprintf("apiVersion=%s,kind=%s,name=%s", test.apiVersion, test.kind, test.name),
5251
func(t *testing.T) {
5352
t.Parallel()
53+
5454
manifest := map[string]interface{}{
5555
"apiVersion": test.apiVersion,
5656
"kind": test.kind,

internal/expanders/kyverno.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
package expanders
33

44
import (
5-
"fmt"
6-
75
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
86

97
"open-cluster-management.io/policy-generator-plugin/internal/types"
@@ -50,7 +48,7 @@ func (k KyvernoPolicyExpander) Expand(
5048
// This was previously validated in the CanHandle method.
5149
policyName, _, _ := unstructured.NestedString(manifest, "metadata", "name")
5250

53-
configPolicyName := fmt.Sprintf("inform-kyverno-%s", policyName)
51+
configPolicyName := "inform-kyverno-" + policyName
5452
configurationPolicy := map[string]interface{}{
5553
"objectDefinition": map[string]interface{}{
5654
"apiVersion": configPolicyAPIVersion,

internal/expanders/kyverno_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ func TestKyvernoCanHandle(t *testing.T) {
1818
}
1919

2020
for _, test := range tests {
21-
test := test
2221
t.Run(
23-
fmt.Sprintf("kind=%s", test.kind),
22+
"kind="+test.kind,
2423
func(t *testing.T) {
2524
t.Parallel()
25+
2626
manifest := map[string]interface{}{
2727
"apiVersion": kyvernoAPIVersion,
2828
"kind": test.kind,
@@ -49,11 +49,11 @@ func TestKyvernoCanHandleInvalid(t *testing.T) {
4949
}
5050

5151
for _, test := range tests {
52-
test := test
5352
t.Run(
5453
fmt.Sprintf("apiVersion=%s,kind=%s,name=%s", test.apiVersion, test.kind, test.name),
5554
func(t *testing.T) {
5655
t.Parallel()
56+
5757
manifest := map[string]interface{}{
5858
"apiVersion": test.apiVersion,
5959
"kind": test.kind,

internal/patches.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818

1919
type kustomizeFile struct {
2020
OpenAPI types.Filepath `json:"openapi,omitempty" yaml:"openapi,omitempty"`
21-
Patches []types.Filepath `json:"patches" yaml:"patches"`
22-
Resources []string `json:"resources" yaml:"resources"`
21+
Patches []types.Filepath `json:"patches" yaml:"patches"`
22+
Resources []string `json:"resources" yaml:"resources"`
2323
}
2424

2525
type manifestPatcher struct {

internal/patches_test.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,20 @@ func TestValidateManifestMissingData(t *testing.T) {
9999
}
100100

101101
for _, test := range tests {
102-
test := test
103-
name := fmt.Sprintf("manifest missing %s", strings.Join(test.missingFields, "."))
102+
name := "manifest missing " + strings.Join(test.missingFields, ".")
104103

105104
t.Run(
106105
name,
107106
func(t *testing.T) {
108107
t.Parallel()
108+
109109
configmap := *createExConfigMap("configmap1")
110+
110111
err := unstructured.SetNestedField(configmap, "", test.missingFields...)
111112
if err != nil {
112113
t.Fatal(err.Error())
113114
}
115+
114116
manifests := []map[string]interface{}{configmap}
115117

116118
patcher := manifestPatcher{manifests: manifests, patches: []map[string]interface{}{}}
@@ -136,8 +138,7 @@ func TestValidatePatchMissingData(t *testing.T) {
136138
}
137139

138140
for _, test := range tests {
139-
test := test
140-
name := fmt.Sprintf("patch missing %s", strings.Join(test.missingFields, "."))
141+
name := "patch missing " + strings.Join(test.missingFields, ".")
141142

142143
t.Run(
143144
name,
@@ -159,10 +160,12 @@ func TestValidatePatchMissingData(t *testing.T) {
159160
},
160161
},
161162
}
163+
162164
err := unstructured.SetNestedField(patch, "", test.missingFields...)
163165
if err != nil {
164166
t.Fatal(err.Error())
165167
}
168+
166169
patches := []map[string]interface{}{patch}
167170

168171
patcher := manifestPatcher{manifests: manifests, patches: patches}
@@ -187,8 +190,7 @@ func TestValidatePatchInvalidSingleManifest(t *testing.T) {
187190
}
188191

189192
for _, test := range tests {
190-
test := test
191-
name := fmt.Sprintf("patch invalid %s", strings.Join(test.invalidFields, "."))
193+
name := "patch invalid " + strings.Join(test.invalidFields, ".")
192194

193195
t.Run(
194196
name,
@@ -207,10 +209,12 @@ func TestValidatePatchInvalidSingleManifest(t *testing.T) {
207209
},
208210
},
209211
}
212+
210213
err := unstructured.SetNestedField(patch, true, test.invalidFields...)
211214
if err != nil {
212215
t.Fatal(err.Error())
213216
}
217+
214218
patches := []map[string]interface{}{patch}
215219

216220
patcher := manifestPatcher{manifests: manifests, patches: patches}

0 commit comments

Comments
 (0)