Skip to content

Commit 4698370

Browse files
sivcharisbueringer
andauthored
🐛 upgrade golangci-lint to v1.61.0 (kubernetes-sigs#2950)
* upgrade golangci-lint to v1.61.0 Signed-off-by: sivchari <[email protected]> * apply nolintlint Signed-off-by: sivchari <[email protected]> * disable gosec G115 Signed-off-by: sivchari <[email protected]> * revert configuration Signed-off-by: sivchari <[email protected]> * clean up comments Signed-off-by: sivchari <[email protected]> * add nolint:gosec about G115 rule Signed-off-by: sivchari <[email protected]> * fix: gofmt Signed-off-by: sivchari <[email protected]> * fix review findings --------- Signed-off-by: sivchari <[email protected]> Co-authored-by: Stefan Bueringer <[email protected]>
1 parent 4cae9df commit 4698370

File tree

10 files changed

+9
-15
lines changed

10 files changed

+9
-15
lines changed

.github/workflows/golangci-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ jobs:
3434
- name: golangci-lint
3535
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # tag=v6.1.0
3636
with:
37-
version: v1.57.2
37+
version: v1.61.0
3838
args: --out-format=colored-line-number
3939
working-directory: ${{matrix.working-directory}}

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ linters:
55
- asciicheck
66
- bidichk
77
- bodyclose
8+
- copyloopvar
89
- dogsled
910
- dupl
1011
- errcheck
1112
- errchkjson
1213
- errorlint
1314
- exhaustive
14-
- exportloopref
1515
- ginkgolinter
1616
- goconst
1717
- gocritic

pkg/cache/cache_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
15441544
return obtainedPodNames
15451545
}, ConsistOf(tc.expectedPods)))
15461546
for _, pod := range obtainedStructuredPodList.Items {
1547-
Expect(informer.Get(context.Background(), client.ObjectKeyFromObject(&pod), &pod)).To(Succeed()) //nolint:gosec // We don't retain the pointer
1547+
Expect(informer.Get(context.Background(), client.ObjectKeyFromObject(&pod), &pod)).To(Succeed())
15481548
}
15491549

15501550
By("Checking with unstructured")
@@ -1564,7 +1564,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
15641564
return obtainedPodNames
15651565
}, ConsistOf(tc.expectedPods)))
15661566
for _, pod := range obtainedUnstructuredPodList.Items {
1567-
Expect(informer.Get(context.Background(), client.ObjectKeyFromObject(&pod), &pod)).To(Succeed()) //nolint:gosec // We don't retain the pointer
1567+
Expect(informer.Get(context.Background(), client.ObjectKeyFromObject(&pod), &pod)).To(Succeed())
15681568
}
15691569

15701570
By("Checking with metadata")
@@ -1584,7 +1584,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
15841584
return obtainedPodNames
15851585
}, ConsistOf(tc.expectedPods)))
15861586
for _, pod := range obtainedMetadataPodList.Items {
1587-
Expect(informer.Get(context.Background(), client.ObjectKeyFromObject(&pod), &pod)).To(Succeed()) //nolint:gosec // We don't retain the pointer
1587+
Expect(informer.Get(context.Background(), client.ObjectKeyFromObject(&pod), &pod)).To(Succeed())
15881588
}
15891589
},
15901590
Entry("when selectors are empty it has to inform about all the pods", selectorsTestCase{

pkg/client/client_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,6 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
19791979
// Test this with an integrated type and a CRD to make sure it covers both proto
19801980
// and json deserialization.
19811981
for idx, object := range []client.Object{&corev1.ConfigMap{}, &pkg.ChaosPod{}} {
1982-
idx, object := idx, object
19831982
It(fmt.Sprintf("should not retain any data in the obj variable that is not on the server for %T", object), func() {
19841983
cl, err := client.New(cfg, client.Options{})
19851984
Expect(err).NotTo(HaveOccurred())

pkg/envtest/crd.go

-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ func UninstallCRDs(config *rest.Config, options CRDInstallOptions) error {
229229

230230
// Uninstall each CRD
231231
for _, crd := range options.CRDs {
232-
crd := crd
233232
log.V(1).Info("uninstalling CRD", "crd", crd.GetName())
234233
if err := cs.Delete(context.TODO(), crd); err != nil {
235234
// If CRD is not found, we can consider success
@@ -251,7 +250,6 @@ func CreateCRDs(config *rest.Config, crds []*apiextensionsv1.CustomResourceDefin
251250

252251
// Create each CRD
253252
for _, crd := range crds {
254-
crd := crd
255253
log.V(1).Info("installing CRD", "crd", crd.GetName())
256254
existingCrd := crd.DeepCopy()
257255
err := cs.Get(context.TODO(), client.ObjectKey{Name: crd.GetName()}, existingCrd)

pkg/envtest/envtest_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ var _ = Describe("Test", func() {
5757
// Cleanup CRDs
5858
AfterEach(func() {
5959
for _, crd := range crds {
60-
crd := crd
6160
// Delete only if CRD exists.
6261
crdObjectKey := client.ObjectKey{
6362
Name: crd.GetName(),

pkg/envtest/webhook.go

-2
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,12 @@ func createWebhooks(config *rest.Config, mutHooks []*admissionv1.MutatingWebhook
313313

314314
// Create each webhook
315315
for _, hook := range mutHooks {
316-
hook := hook
317316
log.V(1).Info("installing mutating webhook", "webhook", hook.GetName())
318317
if err := ensureCreated(cs, hook); err != nil {
319318
return err
320319
}
321320
}
322321
for _, hook := range valHooks {
323-
hook := hook
324322
log.V(1).Info("installing validating webhook", "webhook", hook.GetName())
325323
if err := ensureCreated(cs, hook); err != nil {
326324
return err

pkg/log/zap/flags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (ev *levelFlag) Set(flagValue string) error {
8585
}
8686
if logLevel > 0 {
8787
intLevel := -1 * logLevel
88-
ev.setFunc(zap.NewAtomicLevelAt(zapcore.Level(int8(intLevel))))
88+
ev.setFunc(zap.NewAtomicLevelAt(zapcore.Level(int8(intLevel)))) //nolint:gosec // We are not worried about integer overflows (G115) here.
8989
} else {
9090
return fmt.Errorf("invalid log level \"%s\"", flagValue)
9191
}

pkg/webhook/admission/response.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func ValidationResponse(allowed bool, message string) Response {
7171
AdmissionResponse: admissionv1.AdmissionResponse{
7272
Allowed: allowed,
7373
Result: &metav1.Status{
74-
Code: int32(code),
74+
Code: int32(code), //nolint:gosec // Integer overflows (G115) cannot occur here.
7575
Reason: reason,
7676
},
7777
},

tools/setup-envtest/store/store.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func (s *Store) Add(ctx context.Context, item Item, contents io.Reader) (resErr
167167
// preferfing our own scheme.
168168
targetPath := filepath.Base(header.Name)
169169
log.V(1).Info("writing archive file to disk", "archive file", header.Name, "on-disk file", targetPath)
170-
perms := 0555 & header.Mode // make sure we're at most r+x
171-
binOut, err := itemPath.OpenFile(targetPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.FileMode(perms))
170+
perms := 0555 & header.Mode // make sure we're at most r+x
171+
binOut, err := itemPath.OpenFile(targetPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.FileMode(perms)) //nolint:gosec // Integer overflows (G115) seem unlikely here.
172172
if err != nil {
173173
return fmt.Errorf("unable to create file %s from archive to disk for version-platform pair %s", targetPath, itemName)
174174
}

0 commit comments

Comments
 (0)