From a128dac423d11a4cface5898acd3b77c74b133d9 Mon Sep 17 00:00:00 2001 From: Casey Callendrello Date: Tue, 17 Sep 2024 11:44:17 +0200 Subject: [PATCH] minor: fix lint errors Bumping golangci-lint to v1.61 introduced some new reasonable checks; fix the errors they found. Signed-off-by: Casey Callendrello --- pkg/errors/errors_test.go | 2 +- pkg/link/spoofcheck_test.go | 7 ++++--- plugins/ipam/host-local/main.go | 11 ++++++----- plugins/main/host-device/host-device.go | 1 - plugins/meta/bandwidth/bandwidth_config_test.go | 16 ++++++++-------- plugins/meta/bandwidth/bandwidth_linux_test.go | 12 ++++++------ plugins/meta/tuning/tuning.go | 2 +- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/pkg/errors/errors_test.go b/pkg/errors/errors_test.go index cd39044ca..44b0c3d3d 100644 --- a/pkg/errors/errors_test.go +++ b/pkg/errors/errors_test.go @@ -43,7 +43,7 @@ func TestAnnotate(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - if !reflect.DeepEqual(Annotatef(test.existingErr, test.contextMessage), test.expectedErr) { + if !reflect.DeepEqual(Annotate(test.existingErr, test.contextMessage), test.expectedErr) { t.Errorf("test case %s fails", test.name) return } diff --git a/pkg/link/spoofcheck_test.go b/pkg/link/spoofcheck_test.go index 50899b694..8e1828b1a 100644 --- a/pkg/link/spoofcheck_test.go +++ b/pkg/link/spoofcheck_test.go @@ -15,6 +15,7 @@ package link_test import ( + "errors" "fmt" "github.com/networkplumbing/go-nft/nft" @@ -301,10 +302,10 @@ type configurerStub struct { func (a *configurerStub) Apply(c *nft.Config) (*nft.Config, error) { a.applyCounter++ if a.failFirstApplyConfig && a.applyCounter == 1 { - return nil, fmt.Errorf(errorFirstApplyText) + return nil, errors.New(errorFirstApplyText) } if a.failSecondApplyConfig && a.applyCounter == 2 { - return nil, fmt.Errorf(errorSecondApplyText) + return nil, errors.New(errorSecondApplyText) } a.applyConfig = append(a.applyConfig, c) if a.applyReturnNil { @@ -316,7 +317,7 @@ func (a *configurerStub) Apply(c *nft.Config) (*nft.Config, error) { func (a *configurerStub) Read(_ ...string) (*nft.Config, error) { a.readCalled = true if a.failReadConfig { - return nil, fmt.Errorf(errorReadText) + return nil, errors.New(errorReadText) } return a.readConfig, nil } diff --git a/plugins/ipam/host-local/main.go b/plugins/ipam/host-local/main.go index 284d3877f..8f1c94090 100644 --- a/plugins/ipam/host-local/main.go +++ b/plugins/ipam/host-local/main.go @@ -15,6 +15,7 @@ package main import ( + "errors" "fmt" "net" "strings" @@ -130,7 +131,7 @@ func cmdAdd(args *skel.CmdArgs) error { for _, ip := range requestedIPs { errstr = errstr + " " + ip.String() } - return fmt.Errorf(errstr) + return errors.New(errstr) } result.Routes = ipamConf.Routes @@ -151,18 +152,18 @@ func cmdDel(args *skel.CmdArgs) error { defer store.Close() // Loop through all ranges, releasing all IPs, even if an error occurs - var errors []string + var errs []string for idx, rangeset := range ipamConf.Ranges { ipAllocator := allocator.NewIPAllocator(&rangeset, store, idx) err := ipAllocator.Release(args.ContainerID, args.IfName) if err != nil { - errors = append(errors, err.Error()) + errs = append(errs, err.Error()) } } - if errors != nil { - return fmt.Errorf(strings.Join(errors, ";")) + if errs != nil { + return errors.New(strings.Join(errs, ";")) } return nil } diff --git a/plugins/main/host-device/host-device.go b/plugins/main/host-device/host-device.go index 404be4290..25e301406 100644 --- a/plugins/main/host-device/host-device.go +++ b/plugins/main/host-device/host-device.go @@ -393,7 +393,6 @@ func moveLinkOut(containerNs ns.NetNS, ifName string) error { } return nil }) - if err != nil { return err } diff --git a/plugins/meta/bandwidth/bandwidth_config_test.go b/plugins/meta/bandwidth/bandwidth_config_test.go index 5a9c1dd3d..14f7edfed 100644 --- a/plugins/meta/bandwidth/bandwidth_config_test.go +++ b/plugins/meta/bandwidth/bandwidth_config_test.go @@ -117,7 +117,7 @@ var _ = Describe("bandwidth config test", func() { StdinData: []byte(conf), } - Expect(hostNs.Do(func(netNS ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) @@ -166,7 +166,7 @@ var _ = Describe("bandwidth config test", func() { StdinData: []byte(conf), } - Expect(hostNs.Do(func(netNS ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) @@ -216,7 +216,7 @@ var _ = Describe("bandwidth config test", func() { StdinData: []byte(conf), } - Expect(hostNs.Do(func(netNS ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) @@ -264,7 +264,7 @@ var _ = Describe("bandwidth config test", func() { StdinData: []byte(conf), } - Expect(hostNs.Do(func(netNS ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) @@ -312,7 +312,7 @@ var _ = Describe("bandwidth config test", func() { StdinData: []byte(conf), } - Expect(hostNs.Do(func(netNS ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) @@ -371,7 +371,7 @@ var _ = Describe("bandwidth config test", func() { StdinData: []byte(conf), } - Expect(hostNs.Do(func(netNS ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() r, out, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) Expect(err).NotTo(HaveOccurred(), string(out)) @@ -454,7 +454,7 @@ var _ = Describe("bandwidth config test", func() { })).To(Succeed()) // Container ingress (host egress) - Expect(hostNs.Do(func(n ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() vethLink, err := netlink.LinkByName(hostIfname) @@ -520,7 +520,7 @@ var _ = Describe("bandwidth config test", func() { StdinData: []byte(conf), } - Expect(hostNs.Do(func(netNS ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() _, _, err := testutils.CmdAdd(containerNs.Path(), args.ContainerID, "", []byte(conf), func() error { return cmdAdd(args) }) diff --git a/plugins/meta/bandwidth/bandwidth_linux_test.go b/plugins/meta/bandwidth/bandwidth_linux_test.go index e6dc2796a..8e03488e6 100644 --- a/plugins/meta/bandwidth/bandwidth_linux_test.go +++ b/plugins/meta/bandwidth/bandwidth_linux_test.go @@ -179,7 +179,7 @@ var _ = Describe("bandwidth test", func() { })).To(Succeed()) // Container ingress (host egress) - Expect(hostNs.Do(func(n ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() vethLink, err := netlink.LinkByName(hostIfname) @@ -381,7 +381,7 @@ var _ = Describe("bandwidth test", func() { })).To(Succeed()) // Container ingress (host egress) - Expect(hostNs.Do(func(n ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() vethLink, err := netlink.LinkByName(hostIfname) @@ -638,7 +638,7 @@ var _ = Describe("bandwidth test", func() { })).To(Succeed()) // Container ingress (host egress) - Expect(hostNs.Do(func(n ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() vethLink, err := netlink.LinkByName(hostIfname) @@ -888,7 +888,7 @@ var _ = Describe("bandwidth test", func() { // check container ingress side / host egress side, we should not have any htb qdisc/classes/filters defined for the host veth // only the qdisc ingress + a noqueue qdisc - Expect(hostNs.Do(func(n ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() containerIfLink, err := netlink.LinkByName(hostIfname) @@ -957,7 +957,7 @@ var _ = Describe("bandwidth test", func() { return nil })).To(Succeed()) - Expect(hostNs.Do(func(n ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() containerIfLink, err := netlink.LinkByName(hostIfname) @@ -1133,7 +1133,7 @@ var _ = Describe("bandwidth test", func() { })).To(Succeed()) // Container ingress (host egress) - Expect(hostNs.Do(func(n ns.NetNS) error { + Expect(hostNs.Do(func(_ ns.NetNS) error { defer GinkgoRecover() vethLink, err := netlink.LinkByName(hostIfname) diff --git a/plugins/meta/tuning/tuning.go b/plugins/meta/tuning/tuning.go index eb72837ea..84e8d97bb 100644 --- a/plugins/meta/tuning/tuning.go +++ b/plugins/meta/tuning/tuning.go @@ -319,7 +319,7 @@ func restoreBackup(ifName, containerID, backupPath string) error { } if len(errStr) > 0 { - return fmt.Errorf(strings.Join(errStr, "; ")) + return errors.New(strings.Join(errStr, "; ")) } if err = os.Remove(filePath); err != nil {