Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏃 Update golangci-lint to 1.45.2 #1868

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.40.1
version: v1.45.2
working-directory: ${{matrix.working-directory}}
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ issues:
- linters:
- gocritic
text: "singleCaseSwitch: should rewrite switch statement to if statement"
# It considers all file access to a filename that comes from a variable problematic,
# which is naiv at best.
- linters:
- gosec
text: "G304: Potential file inclusion via variable"

run:
timeout: 10m
Expand Down
2 changes: 1 addition & 1 deletion pkg/certwatcher/certwatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func writeCerts(certPath, keyPath, ip string) error {
return err
}

keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) //nolint:gosec
keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ var _ = Describe("Client", func() {
By("initially creating two Deployments")

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

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

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

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

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

dep, err = clientset.AppsV1().Deployments(ns).Create(ctx, dep, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())
Expand Down
8 changes: 2 additions & 6 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ func (c *fakeClient) Watch(ctx context.Context, list client.ObjectList, opts ...
return nil, err
}

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

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

originalKind := gvk.Kind

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

if _, isUnstructuredList := obj.(*unstructured.UnstructuredList); isUnstructuredList && !c.scheme.Recognizes(gvk) {
// We need to register the ListKind with UnstructuredList:
Expand Down
4 changes: 1 addition & 3 deletions pkg/client/metadata_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ func (mc *metadataClient) List(ctx context.Context, obj ObjectList, opts ...List
}

gvk := metadata.GroupVersionKind()
if strings.HasSuffix(gvk.Kind, "List") {
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
}
gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")

listOpts := ListOptions{}
listOpts.ApplyOptions(opts)
Expand Down
16 changes: 5 additions & 11 deletions pkg/client/unstructured_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ func (uc *unstructuredClient) Update(ctx context.Context, obj Object, opts ...Up

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

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

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

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

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

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

gvk := u.GroupVersionKind()
if strings.HasSuffix(gvk.Kind, "List") {
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
}
gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")

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

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

Expand Down
8 changes: 2 additions & 6 deletions pkg/client/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ func (w *watchingClient) listOpts(opts ...ListOption) ListOptions {

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

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

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

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

r, err := w.client.unstructuredClient.cache.getResource(obj)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/envtest/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func readCRDs(basePath string, files []os.FileInfo) ([]*apiextensionsv1.CustomRe

// readDocuments reads documents from file.
func readDocuments(fp string) ([][]byte, error) {
b, err := ioutil.ReadFile(fp) //nolint:gosec
b, err := ioutil.ReadFile(fp)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/internal/flock/flock_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux || darwin || freebsd || openbsd || netbsd || dragonfly
// +build linux darwin freebsd openbsd netbsd dragonfly

/*
Expand Down
1 change: 1 addition & 0 deletions pkg/manager/signals/signal_posix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

/*
Expand Down
2 changes: 1 addition & 1 deletion tools/setup-envtest/workflows/workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ var _ = Describe("Workflows", func() {
})

It("should remove matching versions from the store & keep non-matching ones", func() {
entries, err := env.FS.ReadDir(filepath.Join(".teststore/k8s"))
entries, err := env.FS.ReadDir(".teststore/k8s")
Expect(err).NotTo(HaveOccurred(), "should be able to read the store")
Expect(entries).To(ConsistOf(
WithTransform(fs.FileInfo.Name, Equal("1.16.2-ifonlysingularitywasstillathing-amd64")),
Expand Down