-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We add basic announcement tests where all the nodes announce the same ips to all / some neighbors. Signed-off-by: Federico Paolinelli <[email protected]>
- Loading branch information
Showing
8 changed files
with
488 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier:Apache-2.0 | ||
|
||
package k8s | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
clientset "k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// Nodes returns all nodes in the cluster. | ||
func Nodes(cs clientset.Interface) ([]corev1.Node, error) { | ||
nodes, err := cs.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Failed to fetch frrk8s pods") | ||
} | ||
return nodes.Items, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// SPDX-License-Identifier:Apache-2.0 | ||
|
||
package routes | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"net" | ||
|
||
"go.universe.tf/e2etest/pkg/frr" | ||
frrcontainer "go.universe.tf/e2etest/pkg/frr/container" | ||
"go.universe.tf/e2etest/pkg/ipfamily" | ||
"go.universe.tf/metallb/e2etest/pkg/executor" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/kubernetes/test/e2e/framework" | ||
) | ||
|
||
// CheckNeighborHasPrefix tells if the given frr container has a route toward the given prefix | ||
// via the set of node passed to this function. | ||
func CheckNeighborHasPrefix(neighbor frrcontainer.FRR, prefix string, nodes []v1.Node) (bool, error) { | ||
routesV4, routesV6, err := frr.Routes(neighbor) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
_, cidr, err := net.ParseCIDR(prefix) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
route, err := routeForCIDR(cidr, routesV4, routesV6) | ||
var notFound RouteNotFoundError | ||
if errors.As(err, ¬Found) { | ||
return false, nil | ||
} | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
cidrFamily := ipfamily.ForCIDR(cidr) | ||
err = frr.RoutesMatchNodes(nodes, route, cidrFamily, neighbor.RouterConfig.VRF) | ||
if err != nil { | ||
return false, nil | ||
} | ||
return true, nil | ||
} | ||
|
||
func cidrsAreEqual(a, b *net.IPNet) bool { | ||
return a.IP.Equal(b.IP) && bytes.Equal(a.Mask, b.Mask) | ||
} | ||
|
||
type RouteNotFoundError string | ||
|
||
func (e RouteNotFoundError) Error() string { | ||
return string(e) | ||
} | ||
|
||
func routeForCIDR(cidr *net.IPNet, routesV4 map[string]frr.Route, routesV6 map[string]frr.Route) (frr.Route, error) { | ||
for _, route := range routesV4 { | ||
if cidrsAreEqual(route.Destination, cidr) { | ||
return route, nil | ||
} | ||
} | ||
for _, route := range routesV6 { | ||
if cidrsAreEqual(route.Destination, cidr) { | ||
return route, nil | ||
} | ||
} | ||
return frr.Route{}, RouteNotFoundError(fmt.Sprintf("route %s not found", cidr)) | ||
} | ||
|
||
func havePrefix(pod *v1.Pod, pairingFamily ipfamily.Family, prefix *net.IPNet, nextHop, vrf string) bool { | ||
found := false | ||
podExec := executor.ForPod(pod.Namespace, pod.Name, "frr") | ||
routes, frrRoutesV6, err := frr.RoutesForVRF(vrf, podExec) | ||
framework.ExpectNoError(err) | ||
|
||
if pairingFamily == ipfamily.IPv6 { | ||
routes = frrRoutesV6 | ||
} | ||
|
||
out: | ||
for _, route := range routes { | ||
if !cidrsAreEqual(route.Destination, prefix) { | ||
continue | ||
} | ||
for _, nh := range route.NextHops { | ||
if nh.String() == nextHop { | ||
found = true | ||
break out | ||
} | ||
} | ||
} | ||
if !found { | ||
return false | ||
} | ||
return true | ||
} |
Oops, something went wrong.