-
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.
Merge pull request #19 from fedepaol/moretests
E2E: add announcement tests
- Loading branch information
Showing
10 changed files
with
459 additions
and
117 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
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,69 @@ | ||
// 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" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// 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)) | ||
} |
Oops, something went wrong.