enable staticcheck linter

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL 2023-03-02 11:06:22 +01:00 committed by GitHub
parent d12b81dec5
commit 177e0bf2d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 14 deletions

View File

@ -3,11 +3,11 @@ linters:
- gci
- gofumpt
- misspell
- staticcheck
disable:
- errcheck
- gosimple
- ineffassign
- staticcheck
linters-settings:
gci:

View File

@ -125,7 +125,7 @@ func (s *Store) FindByID(id string, ifname string) bool {
// Match anything created by this id
if !found && err == nil {
match := strings.TrimSpace(id)
found, err = s.FindByKey(id, ifname, match)
found, _ = s.FindByKey(id, ifname, match)
}
return found
@ -162,7 +162,7 @@ func (s *Store) ReleaseByID(id string, ifname string) error {
// For backwards compatibility, look for files written by a previous version
if !found && err == nil {
match := strings.TrimSpace(id)
found, err = s.ReleaseByKey(id, ifname, match)
_, err = s.ReleaseByKey(id, ifname, match)
}
return err
}

View File

@ -465,6 +465,9 @@ func validateCniContainerInterface(intf current.Interface, masterIndex int, mode
}
mode, err := modeFromString(modeExpected)
if err != nil {
return err
}
if ipv.Mode != mode {
currString, err := modeToString(ipv.Mode)
if err != nil {

View File

@ -455,7 +455,7 @@ func cmdCheck(args *skel.CmdArgs) error {
// Parse previous result.
if n.NetConf.RawPrevResult == nil {
return fmt.Errorf("Required prevResult missing")
return fmt.Errorf("required prevResult missing")
}
if err := version.ParsePrevResult(&n.NetConf); err != nil {
@ -480,7 +480,7 @@ func cmdCheck(args *skel.CmdArgs) error {
// The namespace must be the same as what was configured
if args.Netns != contMap.Sandbox {
return fmt.Errorf("Sandbox in prevResult %s doesn't match configured netns: %s",
return fmt.Errorf("sandbox in prevResult %s doesn't match configured netns: %s",
contMap.Sandbox, args.Netns)
}
@ -527,22 +527,25 @@ func validateCniContainerInterface(intf current.Interface, parentIndex int, mode
var err error
if intf.Name == "" {
return fmt.Errorf("Container interface name missing in prevResult: %v", intf.Name)
return fmt.Errorf("container interface name missing in prevResult: %v", intf.Name)
}
link, err = netlink.LinkByName(intf.Name)
if err != nil {
return fmt.Errorf("Container Interface name in prevResult: %s not found", intf.Name)
return fmt.Errorf("container Interface name in prevResult: %s not found", intf.Name)
}
if intf.Sandbox == "" {
return fmt.Errorf("Error: Container interface %s should not be in host namespace", link.Attrs().Name)
return fmt.Errorf("error: Container interface %s should not be in host namespace", link.Attrs().Name)
}
macv, isMacvlan := link.(*netlink.Macvlan)
if !isMacvlan {
return fmt.Errorf("Error: Container interface %s not of type macvlan", link.Attrs().Name)
return fmt.Errorf("error: Container interface %s not of type macvlan", link.Attrs().Name)
}
mode, err := modeFromString(modeExpected)
if err != nil {
return err
}
if macv.Mode != mode {
currString, err := modeToString(macv.Mode)
if err != nil {
@ -552,12 +555,12 @@ func validateCniContainerInterface(intf current.Interface, parentIndex int, mode
if err != nil {
return err
}
return fmt.Errorf("Container macvlan mode %s does not match expected value: %s", currString, confString)
return fmt.Errorf("container macvlan mode %s does not match expected value: %s", currString, confString)
}
if intf.Mac != "" {
if intf.Mac != link.Attrs().HardwareAddr.String() {
return fmt.Errorf("Interface %s Mac %s doesn't match container Mac: %s", intf.Name, intf.Mac, link.Attrs().HardwareAddr)
return fmt.Errorf("interface %s Mac %s doesn't match container Mac: %s", intf.Name, intf.Mac, link.Attrs().HardwareAddr)
}
}

View File

@ -104,8 +104,6 @@ func getBandwidth(conf *PluginConf) *BandwidthEntry {
func validateRateAndBurst(rate, burst uint64) error {
switch {
case burst < 0 || rate < 0:
return fmt.Errorf("rate and burst must be a positive integer")
case burst == 0 && rate != 0:
return fmt.Errorf("if rate is set, burst must also be set")
case rate == 0 && burst != 0:

View File

@ -84,8 +84,10 @@ var _ = Describe("portmapping configuration", func() {
Expect(c.Name).To(Equal("test"))
n, err := types.ParseCIDR("10.0.0.2/24")
Expect(err).NotTo(HaveOccurred())
Expect(c.ContIPv4).To(Equal(*n))
n, err = types.ParseCIDR("2001:db8:1::2/64")
Expect(err).NotTo(HaveOccurred())
Expect(c.ContIPv6).To(Equal(*n))
})
@ -199,6 +201,7 @@ var _ = Describe("portmapping configuration", func() {
}))
n, err := types.ParseCIDR("10.0.0.2/24")
Expect(err).NotTo(HaveOccurred())
fillDnatRules(&ch, conf, *n)
Expect(ch.entryRules).To(Equal([][]string{
@ -249,6 +252,7 @@ var _ = Describe("portmapping configuration", func() {
ch.entryRules = nil
n, err = types.ParseCIDR("2001:db8::2/64")
Expect(err).NotTo(HaveOccurred())
fillDnatRules(&ch, conf, *n)
Expect(ch.rules).To(Equal([][]string{
@ -277,6 +281,7 @@ var _ = Describe("portmapping configuration", func() {
conf.SNAT = &fvar
n, err = types.ParseCIDR("10.0.0.2/24")
Expect(err).NotTo(HaveOccurred())
fillDnatRules(&ch, conf, *n)
Expect(ch.rules).To(Equal([][]string{
{"-p", "tcp", "--dport", "8080", "-j", "DNAT", "--to-destination", "10.0.0.2:80"},
@ -316,6 +321,7 @@ var _ = Describe("portmapping configuration", func() {
ch = genDnatChain(conf.Name, containerID)
n, err := types.ParseCIDR("10.0.0.2/24")
Expect(err).NotTo(HaveOccurred())
fillDnatRules(&ch, conf, *n)
Expect(ch.rules).To(Equal([][]string{
{"-p", "tcp", "--dport", "8080", "-s", "10.0.0.2/24", "-j", "PLZ-SET-MARK"},

View File

@ -156,6 +156,9 @@ func cmdCheck(args *skel.CmdArgs) error {
return err
}
vrfInterfaces, err := assignedInterfaces(vrf)
if err != nil {
return err
}
found := false
for _, intf := range vrfInterfaces {
@ -165,10 +168,13 @@ func cmdCheck(args *skel.CmdArgs) error {
}
}
if !found {
return fmt.Errorf("Failed to find %s associated to vrf %s", args.IfName, conf.VRFName)
return fmt.Errorf("failed to find %s associated to vrf %s", args.IfName, conf.VRFName)
}
return nil
})
if err != nil {
return err
}
return nil
}

View File

@ -167,6 +167,7 @@ var _ = Describe("vrf plugin", func() {
Expect(err).NotTo(HaveOccurred())
return nil
})
Expect(err).NotTo(HaveOccurred())
err = targetNS.Do(func(ns.NetNS) error {
defer GinkgoRecover()
@ -296,6 +297,7 @@ var _ = Describe("vrf plugin", func() {
link, err := netlink.LinkByName(IF0Name)
Expect(err).NotTo(HaveOccurred())
addresses, err := netlink.AddrList(link, netlink.FAMILY_ALL)
Expect(err).NotTo(HaveOccurred())
Expect(len(addresses)).To(Equal(1))
Expect(addresses[0].IP.Equal(addr0.IP)).To(BeTrue())
Expect(addresses[0].Mask).To(Equal(addr0.Mask))
@ -313,6 +315,7 @@ var _ = Describe("vrf plugin", func() {
Expect(err).NotTo(HaveOccurred())
addresses, err := netlink.AddrList(link, netlink.FAMILY_ALL)
Expect(err).NotTo(HaveOccurred())
Expect(len(addresses)).To(Equal(1))
Expect(addresses[0].IP.Equal(addr1.IP)).To(BeTrue())
Expect(addresses[0].Mask).To(Equal(addr1.Mask))