Skip to content

Commit

Permalink
Fix tests to handle netlink returning 0.0.0.0/0 instead of nil.
Browse files Browse the repository at this point in the history
  • Loading branch information
fasaxc committed Jul 11, 2024
1 parent 036c490 commit da91dbf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions cni-plugin/tests/calico_cni_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ var _ = Describe("Kubernetes CNI tests", func() {
Expect(contRoutes).Should(SatisfyAll(
ContainElement(netlink.Route{
LinkIndex: contVeth.Attrs().Index,
Dst: netlinkDefaultCIDR(),
Gw: net.IPv4(169, 254, 1, 1).To4(),
Protocol: syscall.RTPROT_BOOT,
Table: syscall.RT_TABLE_MAIN,
Expand Down
24 changes: 16 additions & 8 deletions cni-plugin/tests/calico_cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ var _ = Describe("CalicoCni", func() {

// Assume the first IP is the IPv4 address
Expect(contAddresses[0].IP.String()).Should(Equal(ip))
Expect(contRoutes).Should(SatisfyAll(ContainElement(netlink.Route{
LinkIndex: contVeth.Attrs().Index,
Gw: net.IPv4(169, 254, 1, 1).To4(),
Protocol: syscall.RTPROT_BOOT,
Table: syscall.RT_TABLE_MAIN,
Type: syscall.RTN_UNICAST,
Family: syscall.AF_INET,
}),
Expect(contRoutes).Should(SatisfyAll(
ContainElement(netlink.Route{
LinkIndex: contVeth.Attrs().Index,
Dst: netlinkDefaultCIDR(),
Gw: net.IPv4(169, 254, 1, 1).To4(),
Protocol: syscall.RTPROT_BOOT,
Table: syscall.RT_TABLE_MAIN,
Type: syscall.RTN_UNICAST,
Family: syscall.AF_INET,
}),
ContainElement(netlink.Route{
LinkIndex: contVeth.Attrs().Index,
Scope: netlink.SCOPE_LINK,
Expand Down Expand Up @@ -931,3 +933,9 @@ var _ = Describe("CalicoCni", func() {

})
})

func netlinkDefaultCIDR() *net.IPNet {
_, defaultCIDR, _ := net.ParseCIDR("0.0.0.0/0")
defaultCIDR.IP =defaultCIDR.IP.To16() // Netlink returns a v6-formed IP.
return defaultCIDR
}

0 comments on commit da91dbf

Please sign in to comment.