Skip to content

Commit

Permalink
E2E: add integration test for Graceful Restart (wip)
Browse files Browse the repository at this point in the history
Signed-off-by: karampok <[email protected]>
  • Loading branch information
karampok committed Jul 11, 2024
1 parent c65752c commit 223bcb4
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 1 deletion.
5 changes: 4 additions & 1 deletion e2etests/pkg/k8s/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
clientset "k8s.io/client-go/kubernetes"
)

const labelSelector = "app=frr-k8s"
const (
FRRK8sLabelSelector = "control-plane=frr-k8s"
labelSelector = "app=frr-k8s"
)

// FRRK8sPods returns the set of pods related to FRR-K8s.
func FRRK8sPods(cs clientset.Interface) ([]*corev1.Pod, error) {
Expand Down
142 changes: 142 additions & 0 deletions e2etests/tests/gracefulrestart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// SPDX-License-Identifier:Apache-2.0

package tests

import (
"context"
"time"

"github.com/onsi/ginkgo/v2"
"go.universe.tf/e2etest/pkg/frr/container"
frrcontainer "go.universe.tf/e2etest/pkg/frr/container"

frrk8sv1beta1 "github.com/metallb/frr-k8s/api/v1beta1"
"github.com/metallb/frrk8stests/pkg/config"
"github.com/metallb/frrk8stests/pkg/dump"
"github.com/metallb/frrk8stests/pkg/infra"
"github.com/metallb/frrk8stests/pkg/k8s"
"github.com/metallb/frrk8stests/pkg/k8sclient"
"github.com/metallb/frrk8stests/pkg/routes"
. "github.com/onsi/gomega"
frrconfig "go.universe.tf/e2etest/pkg/frr/config"
"go.universe.tf/e2etest/pkg/ipfamily"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

clientset "k8s.io/client-go/kubernetes"
)

var _ = ginkgo.Describe("When establish BGP session", func() {
var cs clientset.Interface

defer ginkgo.GinkgoRecover()

updater, err := config.NewUpdater()
Expect(err).NotTo(HaveOccurred())
reporter := dump.NewK8sReporter(k8s.FRRK8sNamespace)

ginkgo.AfterEach(func() {
if ginkgo.CurrentSpecReport().Failed() {
testName := ginkgo.CurrentSpecReport().LeafNodeText
dump.K8sInfo(testName, reporter)
dump.BGPInfo(testName, infra.FRRContainers, cs)
}
})

ginkgo.BeforeEach(func() {
ginkgo.By("Clearing any previous configuration")
for _, c := range infra.FRRContainers {
err := c.UpdateBGPConfigFile(frrconfig.Empty)
Expect(err).NotTo(HaveOccurred())
}
err := updater.Clean()
Expect(err).NotTo(HaveOccurred())

cs = k8sclient.New()
})

ginkgo.Context("with EnableGracefulRestart", func() {
type params struct {
ipFamily ipfamily.Family
prefixes []string
}

ginkgo.DescribeTable("external BGP peer maintains", func(p params) {
frrs := config.ContainersForVRF(infra.FRRContainers, "")
peersConfig := config.PeersForContainers(frrs, p.ipFamily)
modifyPeers := func(ppV4 []config.Peer, ppV6 []config.Peer) {
for i := range append(ppV4, ppV6...) {
ppV4[i].Neigh.ToAdvertise.Allowed.Mode = frrk8sv1beta1.AllowAll
//p.Neigh.ToAdvertise.Allowed.Mode = frrk8sv1beta1.AllowAll
ppV4[i].Neigh.EnableGracefulRestart = true
}
}

modifyPeers(peersConfig.PeersV4, peersConfig.PeersV6)
neighbors := config.NeighborsFromPeers(peersConfig.PeersV4, peersConfig.PeersV6)

frrConfigCR := frrk8sv1beta1.FRRConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "graceful-restart-test",
Namespace: k8s.FRRK8sNamespace,
},
Spec: frrk8sv1beta1.FRRConfigurationSpec{
BGP: frrk8sv1beta1.BGPConfig{
Routers: []frrk8sv1beta1.Router{
{
ASN: infra.FRRK8sASN,
Neighbors: neighbors,
Prefixes: p.prefixes,
},
},
},
},
}

for _, c := range frrs {
err := container.PairWithNodes(cs, c, p.ipFamily)
Expect(err).NotTo(HaveOccurred(), "frr config in infra containers failed")
}

err := updater.Update(peersConfig.Secrets, frrConfigCR)
Expect(err).NotTo(HaveOccurred(), "apply the CR in api failed")

nodes, err := k8s.Nodes(cs)
Expect(err).NotTo(HaveOccurred())

for _, c := range frrs {
ValidateFRRPeeredWithNodes(nodes, c, p.ipFamily)
}

validate := func(ppV4 []config.Peer, ppV6 []config.Peer, nodes []v1.Node) {
for _, p := range ppV4 {
ValidatePrefixesForNeighbor(p.FRR, nodes, "192.168.2.0/24")
}
}

validate(peersConfig.PeersV4, peersConfig.PeersV6, nodes)

go func() {
defer ginkgo.GinkgoRecover()
err := cs.CoreV1().Pods(k8s.FRRK8sNamespace).DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: k8s.FRRK8sLabelSelector,
})
Expect(err).NotTo(HaveOccurred())
}()

f := func(neigh frrcontainer.FRR, nodes []v1.Node, prefix string) {
Consistently(func() bool {
found, err := routes.CheckNeighborHasPrefix(neigh, prefix, nodes)
Expect(err).NotTo(HaveOccurred())
return found
}, 1*time.Minute, time.Second).Should(BeTrue())
}
f(peersConfig.PeersV4[0].FRR, nodes, "192.168.2.0/24")
},
ginkgo.Entry("IPV4", params{
ipFamily: ipfamily.IPv4,
prefixes: []string{"192.168.2.0/24"},
}),
)
})
})

0 comments on commit 223bcb4

Please sign in to comment.