Skip to content

Commit 7bab887

Browse files
committed
🏃 Update golangci-lint to 1.45.2
The current version fails on files that are unchanged.
1 parent 0a4d154 commit 7bab887

File tree

11 files changed

+23
-32
lines changed

11 files changed

+23
-32
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ jobs:
1919
- name: golangci-lint
2020
uses: golangci/golangci-lint-action@v2
2121
with:
22-
version: v1.40.1
22+
version: v1.45.2
2323
working-directory: ${{matrix.working-directory}}

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ issues:
121121
- linters:
122122
- gocritic
123123
text: "singleCaseSwitch: should rewrite switch statement to if statement"
124+
# It considers all file access to a filename that comes from a variable problematic,
125+
# which is naiv at best.
126+
- linters:
127+
- gosec
128+
text: "G304: Potential file inclusion via variable"
124129

125130
run:
126131
timeout: 10m

pkg/certwatcher/certwatcher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func writeCerts(certPath, keyPath, ip string) error {
167167
return err
168168
}
169169

170-
keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) //nolint:gosec
170+
keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
171171
if err != nil {
172172
return err
173173
}

pkg/client/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ var _ = Describe("Client", func() {
11101110
By("initially creating two Deployments")
11111111

11121112
dep2 := dep.DeepCopy()
1113-
dep2.Name = dep2.Name + "-2"
1113+
dep2.Name += "-2"
11141114

11151115
dep, err = clientset.AppsV1().Deployments(ns).Create(ctx, dep, metav1.CreateOptions{})
11161116
Expect(err).NotTo(HaveOccurred())
@@ -1209,7 +1209,7 @@ var _ = Describe("Client", func() {
12091209
By("initially creating two Deployments")
12101210

12111211
dep2 := dep.DeepCopy()
1212-
dep2.Name = dep2.Name + "-2"
1212+
dep2.Name += "-2"
12131213

12141214
dep, err = clientset.AppsV1().Deployments(ns).Create(ctx, dep, metav1.CreateOptions{})
12151215
Expect(err).NotTo(HaveOccurred())
@@ -1295,7 +1295,7 @@ var _ = Describe("Client", func() {
12951295
By("initially creating two Deployments")
12961296

12971297
dep2 := dep.DeepCopy()
1298-
dep2.Name = dep2.Name + "-2"
1298+
dep2.Name += "-2"
12991299

13001300
dep, err = clientset.AppsV1().Deployments(ns).Create(ctx, dep, metav1.CreateOptions{})
13011301
Expect(err).NotTo(HaveOccurred())

pkg/client/fake/client.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,7 @@ func (c *fakeClient) Watch(ctx context.Context, list client.ObjectList, opts ...
352352
return nil, err
353353
}
354354

355-
if strings.HasSuffix(gvk.Kind, "List") {
356-
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
357-
}
355+
gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")
358356

359357
listOpts := client.ListOptions{}
360358
listOpts.ApplyOptions(opts)
@@ -371,9 +369,7 @@ func (c *fakeClient) List(ctx context.Context, obj client.ObjectList, opts ...cl
371369

372370
originalKind := gvk.Kind
373371

374-
if strings.HasSuffix(gvk.Kind, "List") {
375-
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
376-
}
372+
gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")
377373

378374
if _, isUnstructuredList := obj.(*unstructured.UnstructuredList); isUnstructuredList && !c.scheme.Recognizes(gvk) {
379375
// We need to register the ListKind with UnstructuredList:

pkg/client/metadata_client.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ func (mc *metadataClient) List(ctx context.Context, obj ObjectList, opts ...List
146146
}
147147

148148
gvk := metadata.GroupVersionKind()
149-
if strings.HasSuffix(gvk.Kind, "List") {
150-
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
151-
}
149+
gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")
152150

153151
listOpts := ListOptions{}
154152
listOpts.ApplyOptions(opts)

pkg/client/unstructured_client.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ func (uc *unstructuredClient) Update(ctx context.Context, obj Object, opts ...Up
9595

9696
// Delete implements client.Client.
9797
func (uc *unstructuredClient) Delete(ctx context.Context, obj Object, opts ...DeleteOption) error {
98-
_, ok := obj.(*unstructured.Unstructured)
99-
if !ok {
98+
if _, ok := obj.(*unstructured.Unstructured); ok {
10099
return fmt.Errorf("unstructured client did not understand object: %T", obj)
101100
}
102101

@@ -118,8 +117,7 @@ func (uc *unstructuredClient) Delete(ctx context.Context, obj Object, opts ...De
118117

119118
// DeleteAllOf implements client.Client.
120119
func (uc *unstructuredClient) DeleteAllOf(ctx context.Context, obj Object, opts ...DeleteAllOfOption) error {
121-
_, ok := obj.(*unstructured.Unstructured)
122-
if !ok {
120+
if _, ok := obj.(*unstructured.Unstructured); ok {
123121
return fmt.Errorf("unstructured client did not understand object: %T", obj)
124122
}
125123

@@ -141,8 +139,7 @@ func (uc *unstructuredClient) DeleteAllOf(ctx context.Context, obj Object, opts
141139

142140
// Patch implements client.Client.
143141
func (uc *unstructuredClient) Patch(ctx context.Context, obj Object, patch Patch, opts ...PatchOption) error {
144-
_, ok := obj.(*unstructured.Unstructured)
145-
if !ok {
142+
if _, ok := obj.(*unstructured.Unstructured); ok {
146143
return fmt.Errorf("unstructured client did not understand object: %T", obj)
147144
}
148145

@@ -201,9 +198,7 @@ func (uc *unstructuredClient) List(ctx context.Context, obj ObjectList, opts ...
201198
}
202199

203200
gvk := u.GroupVersionKind()
204-
if strings.HasSuffix(gvk.Kind, "List") {
205-
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
206-
}
201+
gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")
207202

208203
listOpts := ListOptions{}
209204
listOpts.ApplyOptions(opts)
@@ -222,8 +217,7 @@ func (uc *unstructuredClient) List(ctx context.Context, obj ObjectList, opts ...
222217
}
223218

224219
func (uc *unstructuredClient) UpdateStatus(ctx context.Context, obj Object, opts ...UpdateOption) error {
225-
_, ok := obj.(*unstructured.Unstructured)
226-
if !ok {
220+
if _, ok := obj.(*unstructured.Unstructured); ok {
227221
return fmt.Errorf("unstructured client did not understand object: %T", obj)
228222
}
229223

pkg/client/watch.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ func (w *watchingClient) listOpts(opts ...ListOption) ListOptions {
6969

7070
func (w *watchingClient) metadataWatch(ctx context.Context, obj *metav1.PartialObjectMetadataList, opts ...ListOption) (watch.Interface, error) {
7171
gvk := obj.GroupVersionKind()
72-
if strings.HasSuffix(gvk.Kind, "List") {
73-
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
74-
}
72+
gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")
7573

7674
listOpts := w.listOpts(opts...)
7775

@@ -85,9 +83,7 @@ func (w *watchingClient) metadataWatch(ctx context.Context, obj *metav1.PartialO
8583

8684
func (w *watchingClient) unstructuredWatch(ctx context.Context, obj *unstructured.UnstructuredList, opts ...ListOption) (watch.Interface, error) {
8785
gvk := obj.GroupVersionKind()
88-
if strings.HasSuffix(gvk.Kind, "List") {
89-
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
90-
}
86+
gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")
9187

9288
r, err := w.client.unstructuredClient.cache.getResource(obj)
9389
if err != nil {

pkg/envtest/crd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func readCRDs(basePath string, files []os.FileInfo) ([]*apiextensionsv1.CustomRe
426426

427427
// readDocuments reads documents from file.
428428
func readDocuments(fp string) ([][]byte, error) {
429-
b, err := ioutil.ReadFile(fp) //nolint:gosec
429+
b, err := ioutil.ReadFile(fp)
430430
if err != nil {
431431
return nil, err
432432
}

pkg/internal/flock/flock_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build linux || darwin || freebsd || openbsd || netbsd || dragonfly
12
// +build linux darwin freebsd openbsd netbsd dragonfly
23

34
/*

pkg/manager/signals/signal_posix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
/*

0 commit comments

Comments
 (0)