enable staticcheck linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
d12b81dec5
commit
177e0bf2d9
@ -3,11 +3,11 @@ linters:
|
|||||||
- gci
|
- gci
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- misspell
|
- misspell
|
||||||
|
- staticcheck
|
||||||
disable:
|
disable:
|
||||||
- errcheck
|
- errcheck
|
||||||
- gosimple
|
- gosimple
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- staticcheck
|
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
gci:
|
gci:
|
||||||
|
@ -125,7 +125,7 @@ func (s *Store) FindByID(id string, ifname string) bool {
|
|||||||
// Match anything created by this id
|
// Match anything created by this id
|
||||||
if !found && err == nil {
|
if !found && err == nil {
|
||||||
match := strings.TrimSpace(id)
|
match := strings.TrimSpace(id)
|
||||||
found, err = s.FindByKey(id, ifname, match)
|
found, _ = s.FindByKey(id, ifname, match)
|
||||||
}
|
}
|
||||||
|
|
||||||
return found
|
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
|
// For backwards compatibility, look for files written by a previous version
|
||||||
if !found && err == nil {
|
if !found && err == nil {
|
||||||
match := strings.TrimSpace(id)
|
match := strings.TrimSpace(id)
|
||||||
found, err = s.ReleaseByKey(id, ifname, match)
|
_, err = s.ReleaseByKey(id, ifname, match)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -465,6 +465,9 @@ func validateCniContainerInterface(intf current.Interface, masterIndex int, mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
mode, err := modeFromString(modeExpected)
|
mode, err := modeFromString(modeExpected)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if ipv.Mode != mode {
|
if ipv.Mode != mode {
|
||||||
currString, err := modeToString(ipv.Mode)
|
currString, err := modeToString(ipv.Mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -455,7 +455,7 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
|
|
||||||
// Parse previous result.
|
// Parse previous result.
|
||||||
if n.NetConf.RawPrevResult == nil {
|
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 {
|
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
|
// The namespace must be the same as what was configured
|
||||||
if args.Netns != contMap.Sandbox {
|
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)
|
contMap.Sandbox, args.Netns)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,22 +527,25 @@ func validateCniContainerInterface(intf current.Interface, parentIndex int, mode
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
if intf.Name == "" {
|
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)
|
link, err = netlink.LinkByName(intf.Name)
|
||||||
if err != nil {
|
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 == "" {
|
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)
|
macv, isMacvlan := link.(*netlink.Macvlan)
|
||||||
if !isMacvlan {
|
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)
|
mode, err := modeFromString(modeExpected)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if macv.Mode != mode {
|
if macv.Mode != mode {
|
||||||
currString, err := modeToString(macv.Mode)
|
currString, err := modeToString(macv.Mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -552,12 +555,12 @@ func validateCniContainerInterface(intf current.Interface, parentIndex int, mode
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 != "" {
|
||||||
if intf.Mac != link.Attrs().HardwareAddr.String() {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,8 +104,6 @@ func getBandwidth(conf *PluginConf) *BandwidthEntry {
|
|||||||
|
|
||||||
func validateRateAndBurst(rate, burst uint64) error {
|
func validateRateAndBurst(rate, burst uint64) error {
|
||||||
switch {
|
switch {
|
||||||
case burst < 0 || rate < 0:
|
|
||||||
return fmt.Errorf("rate and burst must be a positive integer")
|
|
||||||
case burst == 0 && rate != 0:
|
case burst == 0 && rate != 0:
|
||||||
return fmt.Errorf("if rate is set, burst must also be set")
|
return fmt.Errorf("if rate is set, burst must also be set")
|
||||||
case rate == 0 && burst != 0:
|
case rate == 0 && burst != 0:
|
||||||
|
@ -84,8 +84,10 @@ var _ = Describe("portmapping configuration", func() {
|
|||||||
Expect(c.Name).To(Equal("test"))
|
Expect(c.Name).To(Equal("test"))
|
||||||
|
|
||||||
n, err := types.ParseCIDR("10.0.0.2/24")
|
n, err := types.ParseCIDR("10.0.0.2/24")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(c.ContIPv4).To(Equal(*n))
|
Expect(c.ContIPv4).To(Equal(*n))
|
||||||
n, err = types.ParseCIDR("2001:db8:1::2/64")
|
n, err = types.ParseCIDR("2001:db8:1::2/64")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(c.ContIPv6).To(Equal(*n))
|
Expect(c.ContIPv6).To(Equal(*n))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -199,6 +201,7 @@ var _ = Describe("portmapping configuration", func() {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
n, err := types.ParseCIDR("10.0.0.2/24")
|
n, err := types.ParseCIDR("10.0.0.2/24")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
fillDnatRules(&ch, conf, *n)
|
fillDnatRules(&ch, conf, *n)
|
||||||
|
|
||||||
Expect(ch.entryRules).To(Equal([][]string{
|
Expect(ch.entryRules).To(Equal([][]string{
|
||||||
@ -249,6 +252,7 @@ var _ = Describe("portmapping configuration", func() {
|
|||||||
ch.entryRules = nil
|
ch.entryRules = nil
|
||||||
|
|
||||||
n, err = types.ParseCIDR("2001:db8::2/64")
|
n, err = types.ParseCIDR("2001:db8::2/64")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
fillDnatRules(&ch, conf, *n)
|
fillDnatRules(&ch, conf, *n)
|
||||||
|
|
||||||
Expect(ch.rules).To(Equal([][]string{
|
Expect(ch.rules).To(Equal([][]string{
|
||||||
@ -277,6 +281,7 @@ var _ = Describe("portmapping configuration", func() {
|
|||||||
conf.SNAT = &fvar
|
conf.SNAT = &fvar
|
||||||
|
|
||||||
n, err = types.ParseCIDR("10.0.0.2/24")
|
n, err = types.ParseCIDR("10.0.0.2/24")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
fillDnatRules(&ch, conf, *n)
|
fillDnatRules(&ch, conf, *n)
|
||||||
Expect(ch.rules).To(Equal([][]string{
|
Expect(ch.rules).To(Equal([][]string{
|
||||||
{"-p", "tcp", "--dport", "8080", "-j", "DNAT", "--to-destination", "10.0.0.2:80"},
|
{"-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)
|
ch = genDnatChain(conf.Name, containerID)
|
||||||
n, err := types.ParseCIDR("10.0.0.2/24")
|
n, err := types.ParseCIDR("10.0.0.2/24")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
fillDnatRules(&ch, conf, *n)
|
fillDnatRules(&ch, conf, *n)
|
||||||
Expect(ch.rules).To(Equal([][]string{
|
Expect(ch.rules).To(Equal([][]string{
|
||||||
{"-p", "tcp", "--dport", "8080", "-s", "10.0.0.2/24", "-j", "PLZ-SET-MARK"},
|
{"-p", "tcp", "--dport", "8080", "-s", "10.0.0.2/24", "-j", "PLZ-SET-MARK"},
|
||||||
|
@ -156,6 +156,9 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
vrfInterfaces, err := assignedInterfaces(vrf)
|
vrfInterfaces, err := assignedInterfaces(vrf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
for _, intf := range vrfInterfaces {
|
for _, intf := range vrfInterfaces {
|
||||||
@ -165,10 +168,13 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
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
|
return nil
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,7 @@ var _ = Describe("vrf plugin", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = targetNS.Do(func(ns.NetNS) error {
|
err = targetNS.Do(func(ns.NetNS) error {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
@ -296,6 +297,7 @@ var _ = Describe("vrf plugin", func() {
|
|||||||
link, err := netlink.LinkByName(IF0Name)
|
link, err := netlink.LinkByName(IF0Name)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
addresses, err := netlink.AddrList(link, netlink.FAMILY_ALL)
|
addresses, err := netlink.AddrList(link, netlink.FAMILY_ALL)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(addresses)).To(Equal(1))
|
Expect(len(addresses)).To(Equal(1))
|
||||||
Expect(addresses[0].IP.Equal(addr0.IP)).To(BeTrue())
|
Expect(addresses[0].IP.Equal(addr0.IP)).To(BeTrue())
|
||||||
Expect(addresses[0].Mask).To(Equal(addr0.Mask))
|
Expect(addresses[0].Mask).To(Equal(addr0.Mask))
|
||||||
@ -313,6 +315,7 @@ var _ = Describe("vrf plugin", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
addresses, err := netlink.AddrList(link, netlink.FAMILY_ALL)
|
addresses, err := netlink.AddrList(link, netlink.FAMILY_ALL)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(addresses)).To(Equal(1))
|
Expect(len(addresses)).To(Equal(1))
|
||||||
Expect(addresses[0].IP.Equal(addr1.IP)).To(BeTrue())
|
Expect(addresses[0].IP.Equal(addr1.IP)).To(BeTrue())
|
||||||
Expect(addresses[0].Mask).To(Equal(addr1.Mask))
|
Expect(addresses[0].Mask).To(Equal(addr1.Mask))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user