Skip to content

Commit 4404f94

Browse files
Upgrade golangci-lint to v1.64.8
All above these version: github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.1 github.com/daixiang0/gci@v0.11.2 sigs.k8s.io/kustomize/kustomize/v5@v5.2.1 gosec => 2.22.2 kustomize => 5.6 https://issues.redhat.com/browse/ACM-8341 Ref: https://issues.redhat.com/browse/ACM-8341 Signed-off-by: yiraeChristineKim <yikim@redhat.com>
1 parent e62600f commit 4404f94

12 files changed

+43
-33
lines changed

Diff for: 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

Diff for: 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
- deadcode #deprecated

Diff for: test/common/common.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func LoadConfig(url, kubeconfig, context string) (*rest.Config, error) {
184184
}
185185
}
186186

187-
return nil, fmt.Errorf("could not create a valid kubeconfig")
187+
return nil, errors.New("could not create a valid kubeconfig")
188188
}
189189

190190
func oc(args ...string) (string, error) {
@@ -212,7 +212,7 @@ func oc(args ...string) (string, error) {
212212
return string(output), nil
213213
}
214214

215-
return string(output), fmt.Errorf(string(exitError.Stderr))
215+
return string(output), errors.New(string(exitError.Stderr))
216216
}
217217

218218
return string(output), err
@@ -287,8 +287,8 @@ func IsAtLeastVersion(minVersion string) bool {
287287
klog.V(5).Info("OCP Version " + version)
288288

289289
// Convert to valid semantic versions by adding the "v" prefix
290-
minSemVer := fmt.Sprintf("v%s", minVersion)
291-
ocpSemVer := semver.MajorMinor(fmt.Sprintf("v%s", version))
290+
minSemVer := "v" + minVersion
291+
ocpSemVer := semver.MajorMinor("v" + version)
292292

293293
// Compare returns: 0 if ver1 == ver2, -1 if ver1 < ver2, or +1 if ver1 > ver2
294294
return semver.Compare(ocpSemVer, minSemVer) >= 0

Diff for: test/common/metrics.go

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func GetWithToken(url, authToken string) (body, status string, err error) {
3939
if err != nil {
4040
return "", "", err
4141
}
42+
4243
defer resp.Body.Close()
4344
bodyBytes, err := io.ReadAll(resp.Body)
4445

Diff for: test/common/policy_utils.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"path/filepath"
10+
"strconv"
1011
"strings"
1112

1213
. "github.com/onsi/ginkgo/v2"
@@ -389,12 +390,12 @@ func DoHistoryUpdatedTest(policyName string, messages ...string) {
389390
g.Expect(err).ShouldNot(HaveOccurred())
390391
lenMessage := len(messages)
391392
historyMsgs := []string{}
392-
fmt.Println("Returned policy history:")
393+
GinkgoWriter.Println("Returned policy history:")
393394
for i, h := range history {
394395
historyItem, _ := h.(map[string]interface{})
395396
m, _, _ := unstructured.NestedString(historyItem, "message")
396397
historyMsgs = append(historyMsgs, m)
397-
fmt.Println(fmt.Sprint(i) + ": " + m)
398+
GinkgoWriter.Println(strconv.Itoa(i) + ": " + m)
398399
}
399400
By("Check history length is same")
400401
g.Expect(history).Should(HaveLen(lenMessage))

Diff for: test/common/user_management.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
cryptoRand "crypto/rand"
88
"encoding/hex"
9+
"errors"
910
"fmt"
1011
"math/rand"
1112
"os"
@@ -66,14 +67,14 @@ func GetKubeConfig(server, username, password string) (string, error) {
6667
// Create a temporary file for the kubeconfig that the `oc login` command will generate
6768
f, err := os.CreateTemp("", "e2e-kubeconfig")
6869
if err != nil {
69-
return "", fmt.Errorf("failed to create the temporary kubeconfig")
70+
return "", errors.New("failed to create the temporary kubeconfig")
7071
}
7172

7273
kubeconfigPath := f.Name()
7374
// Close the file immediately so that the `oc login` command can use the file
7475
err = f.Close()
7576
if err != nil {
76-
return "", fmt.Errorf("failed to close the temporary kubeconfig")
77+
return "", errors.New("failed to close the temporary kubeconfig")
7778
}
7879

7980
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)

Diff for: test/configuration_policy_prune.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func ConfigPruneBehavior(labels ...string) bool {
116116
g.Expect(err).ToNot(HaveOccurred())
117117

118118
return createdByPolicy
119-
}, DefaultTimeoutSeconds, 5).Should(Equal(true), "createdByPolicy should be true")
119+
}, DefaultTimeoutSeconds, 5).Should(BeTrue(), "createdByPolicy should be true")
120120

121121
DoCleanupPolicy(policyYaml, GvrConfigurationPolicy)
122122

@@ -425,6 +425,7 @@ func ConfigPruneBehavior(labels ...string) bool {
425425
"Test configuration policy pruning", Ordered, Label(labels...), func() {
426426
cleanConfigMap := func() {
427427
By("Removing any finalizers from the configmap")
428+
428429
_, _ = OcManaged("patch", "configmap", pruneConfigMapName, "-n", "default",
429430
"--type=json", "-p", `[{"op":"remove", "path":"/metadata/finalizers"}]`)
430431

Diff for: test/integration/policy_comp_operator_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package integration
55

66
import (
77
"context"
8-
"fmt"
98

109
. "github.com/onsi/ginkgo/v2"
1110
. "github.com/onsi/gomega"
@@ -22,6 +21,7 @@ func complianceScanTest(scanPolicyName string, scanPolicyURL string, scanName st
2221
Describe("create and enforce the stable/"+scanPolicyName+" policy", Ordered, Label("BVT"), func() {
2322
It("stable/"+scanPolicyName+" should be created on hub", func(ctx SpecContext) {
2423
By("Creating policy on hub")
24+
2525
_, err := utils.KubectlWithOutput(
2626
"apply",
2727
"-f",
@@ -136,6 +136,7 @@ func complianceScanTest(scanPolicyName string, scanPolicyURL string, scanName st
136136
})
137137
AfterAll(func() {
138138
By("Removing policy")
139+
139140
_, err := utils.KubectlWithOutput(
140141
"delete",
141142
"-f",
@@ -289,7 +290,7 @@ var _ = Describe("RHACM4K-2222 GRC: [P1][Sev1][policy-grc] "+
289290
i := 0
290291
Eventually(func(g Gomega) []corev1.Pod {
291292
if i == 60*2 || i == 60*4 {
292-
fmt.Println("compliance operator pod still not created, "+
293+
GinkgoWriter.Println("compliance operator pod still not created, "+
293294
"deleting subscription and let it recreate", i)
294295
_, err := utils.KubectlWithOutput(
295296
"get", "-n",
@@ -420,7 +421,7 @@ var _ = Describe("RHACM4K-2222 GRC: [P1][Sev1][policy-grc] "+
420421
"--ignore-not-found",
421422
)
422423
if err != nil {
423-
Expect(err).To(Equal("error: the server doesn't have a resource type \"ProfileBundle\""))
424+
Expect(err.Error()).To(Equal("error: the server doesn't have a resource type \"ProfileBundle\""))
424425
} else {
425426
Expect(err).ToNot(HaveOccurred())
426427
}

Diff for: test/integration/policy_generator_acm_hardening_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package integration
44

55
import (
66
"context"
7-
"fmt"
7+
"errors"
88

99
. "github.com/onsi/ginkgo/v2"
1010
. "github.com/onsi/gomega"
@@ -110,9 +110,9 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the ACM Hardening "+
110110
return myerr
111111
}
112112
if !found {
113-
return fmt.Errorf("failed to find the compliant field of the policy status")
113+
return errors.New("failed to find the compliant field of the policy status")
114114
} else if compliant != "Compliant" {
115-
return fmt.Errorf("The policy is not compliant")
115+
return errors.New("The policy is not compliant")
116116
}
117117
}
118118

Diff for: test/integration/policy_report_metric_test.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,13 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test policyreport_info metric", Or
289289
strings.TrimSpace(insightsToken),
290290
)
291291
if err != nil {
292-
fmt.Println("ERROR GETTING METRIC:")
293-
fmt.Println(err)
292+
GinkgoWriter.Println("ERROR GETTING METRIC:")
293+
GinkgoWriter.Println(err)
294294

295295
return err
296296
}
297-
fmt.Println("metric response received:")
298-
fmt.Println(resp)
297+
GinkgoWriter.Println("metric response received:")
298+
GinkgoWriter.Println(resp)
299299

300300
return resp
301301
}, 10*time.Minute, 1).Should(common.MatchMetricValue(insightsMetricName, policyLabel, "1"))
@@ -322,13 +322,14 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test policyreport_info metric", Or
322322
strings.TrimSpace(insightsToken),
323323
)
324324
if err != nil {
325-
fmt.Println("ERROR GETTING METRIC:")
326-
fmt.Println(err)
325+
GinkgoWriter.Println("ERROR GETTING METRIC:")
326+
GinkgoWriter.Println(err)
327327

328328
return err
329329
}
330-
fmt.Println("metric response received:")
331-
fmt.Println(resp)
330+
331+
GinkgoWriter.Println("metric response received:")
332+
GinkgoWriter.Println(resp)
332333

333334
return resp
334335
}, 10*time.Minute, 1).ShouldNot(common.MatchMetricValue(insightsMetricName, policyLabel, "1"))

Diff for: test/performance/performance.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ func query(host string, token string, query string, insecure bool) (time.Time, f
5858
}
5959

6060
trHeader := NewWithHeader(tr)
61-
trHeader.Set("Authorization", fmt.Sprintf("Bearer %s", token))
61+
trHeader.Set("Authorization", "Bearer "+token)
6262

6363
cl := &http.Client{Transport: trHeader}
6464

6565
client, err := api.NewClient(api.Config{
66-
Address: fmt.Sprintf("https://%s", host),
66+
Address: "https://" + host,
6767
Client: cl,
6868
})
6969
if err != nil {
@@ -263,7 +263,7 @@ func printTable(data []metricData) {
263263
fmt.Fprintln(table, "========\t==========\t====================\t"+
264264
"====================\t===================\t===================\t")
265265

266-
for i := 0; i < len(data); i++ {
266+
for i := range data {
267267
fmt.Fprintf(table, "%s\t%d\t%s\t%s\t%s\t%s\t\n",
268268
data[i].timestamp,
269269
data[i].numPolicies,
@@ -286,7 +286,7 @@ func printTable(data []metricData) {
286286
fmt.Fprintln(table, "========\t==========\t====================\t"+
287287
"====================\t===================\t===================\t")
288288

289-
for i := 0; i < len(data); i++ {
289+
for i := range data {
290290
fmt.Fprintf(table, "%s\t%d\t%s\t%s\t%s\t%s\t\n",
291291
data[i].timestamp,
292292
data[i].numPolicies,
@@ -330,7 +330,7 @@ func exportTable(cpuData []metricData, filename string) {
330330
for _, entry := range cpuData {
331331
line = []string{
332332
entry.timestamp,
333-
fmt.Sprintf("%d", entry.numPolicies),
333+
strconv.Itoa(entry.numPolicies),
334334
fmt.Sprintf("%.5f", entry.controllerCPUAvg),
335335
fmt.Sprintf("%.5f", entry.controllerCPUMax),
336336
fmt.Sprintf("%.5f", entry.apiServerCPUAvg),
@@ -396,7 +396,7 @@ func main() {
396396

397397
batchFails := 0
398398

399-
for batchPlcs := 0; batchPlcs < nPerBatch; batchPlcs++ {
399+
for range nPerBatch {
400400
err = genUniquePolicy(path.Join(performanceDir, plcFilename), path.Join(policyDir, "current_policy.yaml"))
401401
if err != nil {
402402
klog.Exitf("Error patching policy with unique name: %s", err)
@@ -413,12 +413,13 @@ func main() {
413413

414414
tries--
415415
if tries == 0 {
416-
os.Exit(1)
416+
klog.Fatal()
417417
}
418418
} else {
419419
break
420420
}
421421
}
422+
422423
totalPlcs++
423424
}
424425

Diff for: test/policy_ordering.go

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func PolicyOrdering(labels ...string) bool {
130130
Describe("Ordering via a dependency on a PolicySet", Ordered, func() {
131131
It("Should create policyset with noncompliant status", func() {
132132
By("Creating the initial policy set to use as a dependency")
133+
133134
_, err := OcHub("apply", "-f", testPolicySetYaml, "-n", UserNamespace)
134135
Expect(err).ToNot(HaveOccurred())
135136

@@ -167,6 +168,7 @@ func PolicyOrdering(labels ...string) bool {
167168
Expect(plcSet).NotTo(BeNil())
168169

169170
By("Checking the status of policy set - NonCompliant")
171+
170172
yamlPlc := utils.ParseYaml("../resources/policy_ordering/dep-plcset-statuscheck.yaml")
171173

172174
Eventually(func() interface{} {

0 commit comments

Comments
 (0)