run gofmt on the code (#772)

Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
This commit is contained in:
Miguel Duarte Barroso 2022-01-04 17:33:58 +01:00 committed by GitHub
parent ed18a1f175
commit 12df5bda72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 50 deletions

View File

@ -687,10 +687,10 @@ func CmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (c
// Remove namespace from delegate.Name for Add/Del CNI cache // Remove namespace from delegate.Name for Add/Del CNI cache
nameSlice := strings.Split(delegate.Name, "/") nameSlice := strings.Split(delegate.Name, "/")
netName = nameSlice[len(nameSlice) - 1] netName = nameSlice[len(nameSlice)-1]
// Remove gateway if `default-route` network selection is specified // Remove gateway if `default-route` network selection is specified
if deleteV4gateway || deleteV6gateway { if deleteV4gateway || deleteV6gateway {
err = netutils.DeleteDefaultGW(args, ifName) err = netutils.DeleteDefaultGW(args, ifName)
if err != nil { if err != nil {
return nil, cmdErr(k8sArgs, "error deleting default gateway: %v", err) return nil, cmdErr(k8sArgs, "error deleting default gateway: %v", err)

View File

@ -182,7 +182,7 @@ func deleteDefaultGWResult(result map[string]interface{}, ipv4, ipv6 bool) (map[
} }
_, ok = result["routes"] _, ok = result["routes"]
if !ok { if !ok {
// No route in result, hence we do nothing // No route in result, hence we do nothing
return result, nil return result, nil
} }
@ -335,7 +335,7 @@ func addDefaultGWResult(result map[string]interface{}, gw []net.IP) (map[string]
routes := []interface{}{} routes := []interface{}{}
_, ok = result["routes"] _, ok = result["routes"]
if ok { if ok {
routes, ok = result["routes"].([]interface{}) routes, ok = result["routes"].([]interface{})
if !ok { if !ok {
return nil, fmt.Errorf("wrong routes format: %v", result["routes"]) return nil, fmt.Errorf("wrong routes format: %v", result["routes"])
@ -349,7 +349,7 @@ func addDefaultGWResult(result map[string]interface{}, gw []net.IP) (map[string]
} }
routes = append(routes, map[string]string{ routes = append(routes, map[string]string{
"dst": dst, "dst": dst,
"gw": g.String(), "gw": g.String(),
}) })
} }
result["routes"] = routes result["routes"] = routes
@ -376,7 +376,7 @@ func addDefaultGWResult020(result map[string]interface{}, gw []net.IP) (map[stri
} }
ip4["routes"] = append(routes, map[string]string{ ip4["routes"] = append(routes, map[string]string{
"dst": "0.0.0.0/0", "dst": "0.0.0.0/0",
"gw": g.String(), "gw": g.String(),
}) })
} }
} else { } else {
@ -396,7 +396,7 @@ func addDefaultGWResult020(result map[string]interface{}, gw []net.IP) (map[stri
} }
ip6["routes"] = append(routes, map[string]string{ ip6["routes"] = append(routes, map[string]string{
"dst": "::/0", "dst": "::/0",
"gw": g.String(), "gw": g.String(),
}) })
} }
} }

View File

@ -33,22 +33,22 @@ import (
) )
func TestNetutils(t *testing.T) { func TestNetutils(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "netutils") RunSpecs(t, "netutils")
} }
// helper function // helper function
func testAddRoute(link netlink.Link, ip net.IP, mask net.IPMask, gw net.IP) error { func testAddRoute(link netlink.Link, ip net.IP, mask net.IPMask, gw net.IP) error {
dst := &net.IPNet{ dst := &net.IPNet{
IP: ip, IP: ip,
Mask: mask, Mask: mask,
} }
route := netlink.Route{LinkIndex: link.Attrs().Index, Dst: dst, Gw: gw} route := netlink.Route{LinkIndex: link.Attrs().Index, Dst: dst, Gw: gw}
return netlink.RouteAdd(&route) return netlink.RouteAdd(&route)
} }
func testAddAddr(link netlink.Link, ip net.IP, mask net.IPMask) error { func testAddAddr(link netlink.Link, ip net.IP, mask net.IPMask) error {
return netlink.AddrAdd(link, &netlink.Addr{IPNet: &net.IPNet{IP: ip, Mask: mask}}) return netlink.AddrAdd(link, &netlink.Addr{IPNet: &net.IPNet{IP: ip, Mask: mask}})
} }
func testGetResultFromCache(data []byte) []byte { func testGetResultFromCache(data []byte) []byte {
@ -148,9 +148,9 @@ var _ = Describe("netutil netlink function testing", func() {
Expect(netlink.LinkAdd(&netlink.Dummy{ Expect(netlink.LinkAdd(&netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{ LinkAttrs: netlink.LinkAttrs{
Name: IFNAME, Name: IFNAME,
HardwareAddr: IFMAC, HardwareAddr: IFMAC,
Index: 10, Index: 10,
}, },
})).Should(Succeed()) })).Should(Succeed())
@ -291,17 +291,17 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 010/020 Result // Simplified CNI Cache with 010/020 Result
type CNICacheResult020 struct { type CNICacheResult020 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
IP4 struct { IP4 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
} `json:"routes"` } `json:"routes"`
} `json:"ip4"` } `json:"ip4"`
IP6 struct { IP6 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
@ -364,17 +364,17 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 010/020 Result // Simplified CNI Cache with 010/020 Result
type CNICacheResult020 struct { type CNICacheResult020 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
IP4 struct { IP4 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
} `json:"routes"` } `json:"routes"`
} `json:"ip4"` } `json:"ip4"`
IP6 struct { IP6 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
@ -449,7 +449,7 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result // Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result
type CNICacheResult030_040 struct { type CNICacheResult030_040 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
@ -523,7 +523,7 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result // Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result
type CNICacheResult030_040 struct { type CNICacheResult030_040 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
@ -563,7 +563,7 @@ var _ = Describe("netutil cnicache function testing", func() {
} }
} }
}`) }`)
newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{ net.ParseIP("10.1.1.1") }) newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{net.ParseIP("10.1.1.1")})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(test020ResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue()) Expect(test020ResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue())
@ -571,17 +571,17 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 010/020 Result // Simplified CNI Cache with 010/020 Result
type CNICacheResult020 struct { type CNICacheResult020 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
IP4 struct { IP4 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
} `json:"routes"` } `json:"routes"`
} `json:"ip4"` } `json:"ip4"`
IP6 struct { IP6 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
@ -631,7 +631,7 @@ var _ = Describe("netutil cnicache function testing", func() {
} }
} }
}`) }`)
newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{ net.ParseIP("10.1.1.1") }) newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{net.ParseIP("10.1.1.1")})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(test020ResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue()) Expect(test020ResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue())
@ -639,17 +639,17 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 010/020 Result // Simplified CNI Cache with 010/020 Result
type CNICacheResult020 struct { type CNICacheResult020 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
IP4 struct { IP4 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
} `json:"routes"` } `json:"routes"`
} `json:"ip4"` } `json:"ip4"`
IP6 struct { IP6 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
@ -689,7 +689,7 @@ var _ = Describe("netutil cnicache function testing", func() {
} }
} }
}`) }`)
newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{ net.ParseIP("10::1:1:1") }) newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{net.ParseIP("10::1:1:1")})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(test020ResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue()) Expect(test020ResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue())
@ -697,17 +697,17 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 010/020 Result // Simplified CNI Cache with 010/020 Result
type CNICacheResult020 struct { type CNICacheResult020 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
IP4 struct { IP4 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
} `json:"routes"` } `json:"routes"`
} `json:"ip4"` } `json:"ip4"`
IP6 struct { IP6 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
@ -757,7 +757,7 @@ var _ = Describe("netutil cnicache function testing", func() {
} }
} }
}`) }`)
newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{ net.ParseIP("10::1:1:1") }) newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{net.ParseIP("10::1:1:1")})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(test020ResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue()) Expect(test020ResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue())
@ -765,17 +765,17 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 010/020 Result // Simplified CNI Cache with 010/020 Result
type CNICacheResult020 struct { type CNICacheResult020 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
IP4 struct { IP4 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
} `json:"routes"` } `json:"routes"`
} `json:"ip4"` } `json:"ip4"`
IP6 struct { IP6 struct {
IP string `json:"ip"` IP string `json:"ip"`
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
Gw string `json:"gw"` Gw string `json:"gw"`
@ -815,7 +815,7 @@ var _ = Describe("netutil cnicache function testing", func() {
] ]
} }
}`) }`)
newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{ net.ParseIP("10.1.1.1") }) newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{net.ParseIP("10.1.1.1")})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(testResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue()) Expect(testResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue())
@ -823,7 +823,7 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result // Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result
type CNICacheResult030_040 struct { type CNICacheResult030_040 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
@ -881,7 +881,7 @@ var _ = Describe("netutil cnicache function testing", func() {
] ]
} }
}`) }`)
newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{ net.ParseIP("10.1.1.1") }) newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{net.ParseIP("10.1.1.1")})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(testResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue()) Expect(testResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue())
@ -889,7 +889,7 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result // Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result
type CNICacheResult030_040 struct { type CNICacheResult030_040 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
@ -929,7 +929,7 @@ var _ = Describe("netutil cnicache function testing", func() {
] ]
} }
}`) }`)
newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{ net.ParseIP("10::1:1:1") }) newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{net.ParseIP("10::1:1:1")})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(testResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeFalse()) Expect(testResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeFalse())
@ -937,7 +937,7 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result // Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result
type CNICacheResult030_040 struct { type CNICacheResult030_040 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`
@ -999,7 +999,7 @@ var _ = Describe("netutil cnicache function testing", func() {
] ]
} }
}`) }`)
newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{ net.ParseIP("10::1:1:1") }) newResult, err := addDefaultGWCacheBytes(origResult, []net.IP{net.ParseIP("10::1:1:1")})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(testResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue()) Expect(testResultHasIPv4DefaultRoute(testGetResultFromCache(newResult))).To(BeTrue())
@ -1007,7 +1007,7 @@ var _ = Describe("netutil cnicache function testing", func() {
// Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result // Simplified CNI Cache with 0.3.0/0.3.1/0.4.0 Result
type CNICacheResult030_040 struct { type CNICacheResult030_040 struct {
Kind string `json:"kind"` Kind string `json:"kind"`
Result struct { Result struct {
Routes []struct { Routes []struct {
Dst string `json:"dst"` Dst string `json:"dst"`