Skip to content

Commit

Permalink
E2ETests: set the password of the BGP sessions
Browse files Browse the repository at this point in the history
Creating the secrets and configuring the neighbors so the session uses
the password. The EBGP-multihop session is left without password so we
validate it keeps working.

Signed-off-by: Federico Paolinelli <[email protected]>
  • Loading branch information
fedepaol committed Aug 28, 2023
1 parent 1affe21 commit 62324a1
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 86 deletions.
24 changes: 23 additions & 1 deletion e2etests/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"context"

frrk8sv1beta1 "github.com/metallb/frrk8s/api/v1beta1"
"github.com/metallb/frrk8stests/pkg/k8s"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
Expand All @@ -22,6 +24,9 @@ func NewUpdater(r *rest.Config) (*Updater, error) {
if err := frrk8sv1beta1.AddToScheme(myScheme); err != nil {
return nil, err
}
if err := v1.AddToScheme(myScheme); err != nil {
return nil, err
}

cl, err := client.New(r, client.Options{
Scheme: myScheme,
Expand All @@ -34,7 +39,7 @@ func NewUpdater(r *rest.Config) (*Updater, error) {
}, nil
}

func (u *Updater) Update(configs ...frrk8sv1beta1.FRRConfiguration) error {
func (u *Updater) Update(secrets []v1.Secret, configs ...frrk8sv1beta1.FRRConfiguration) error {
for i, config := range configs {
_, err := controllerutil.CreateOrUpdate(context.Background(), u.client, &config, func() error {
old := &configs[i].Spec
Expand All @@ -46,6 +51,18 @@ func (u *Updater) Update(configs ...frrk8sv1beta1.FRRConfiguration) error {
return err
}
}
for i, s := range secrets {
_, err := controllerutil.CreateOrUpdate(context.Background(), u.client, &s, func() error {
s.Data = secrets[i].Data
s.StringData = secrets[i].StringData
s.Type = secrets[i].Type
return nil
})

if err != nil {
return err
}
}

return nil
}
Expand All @@ -55,5 +72,10 @@ func (u *Updater) Clean() error {
if err != nil && !errors.IsNotFound(err) {
return err
}
err = u.client.DeleteAllOf(context.Background(), &v1.Secret{}, client.InNamespace(k8s.FRRK8sNamespace))
if err != nil && !errors.IsNotFound(err) {
return err
}

return nil
}
45 changes: 38 additions & 7 deletions e2etests/pkg/config/from_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"net"

frrk8sv1beta1 "github.com/metallb/frrk8s/api/v1beta1"
"go.universe.tf/e2etest/pkg/frr"
"github.com/metallb/frrk8stests/pkg/k8s"
frrcontainer "go.universe.tf/e2etest/pkg/frr/container"
"go.universe.tf/e2etest/pkg/ipfamily"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type Peer struct {
Expand All @@ -17,10 +20,20 @@ type Peer struct {
FRR frrcontainer.FRR
}

type PeersConfig struct {
PeersV4 []Peer
PeersV6 []Peer
Secrets []corev1.Secret
}

// PeersForContainers returns two lists of Peers, one for v4 addresses and one for v6 addresses.
func PeersForContainers(frrs []*frrcontainer.FRR, ipFam ipfamily.Family, modify ...func(frr.Neighbor)) ([]Peer, []Peer) {
resV4 := make([]Peer, 0)
resV6 := make([]Peer, 0)
func PeersForContainers(frrs []*frrcontainer.FRR, ipFam ipfamily.Family) PeersConfig {
res := PeersConfig{
PeersV4: make([]Peer, 0),
PeersV6: make([]Peer, 0),
Secrets: make([]corev1.Secret, 0),
}

for _, f := range frrs {
addresses := f.AddressesForFamily(ipFam)
ebgpMultihop := false
Expand All @@ -40,14 +53,32 @@ func PeersForContainers(frrs []*frrcontainer.FRR, ipFam ipfamily.Family, modify
FRR: *f,
}

if f.RouterConfig.Password != "" {
s := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: f.Name,
Namespace: k8s.FRRK8sNamespace,
},
Type: corev1.SecretTypeBasicAuth,
Data: map[string][]byte{
"password": []byte(f.RouterConfig.Password),
},
}
peer.Neigh.PasswordSecret = v1.SecretReference{
Name: f.Name,
Namespace: k8s.FRRK8sNamespace,
}
res.Secrets = append(res.Secrets, s)
}

if ipfamily.ForAddress(net.ParseIP(address)) == ipfamily.IPv4 {
resV4 = append(resV4, peer)
res.PeersV4 = append(res.PeersV4, peer)
continue
}
resV6 = append(resV6, peer)
res.PeersV6 = append(res.PeersV6, peer)
}
}
return resV4, resV6
return res
}

func NeighborsFromPeers(peers []Peer, peers1 []Peer) []frrk8sv1beta1.Neighbor {
Expand Down
72 changes: 35 additions & 37 deletions e2etests/pkg/infra/infra_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,14 @@ func frrContainersConfigs(image string) map[string]frrcontainer.Config {
Name: "ibgp-single-hop",
Image: image,
Neighbor: frrconfig.NeighborConfig{
ASN: FRRK8sASN,
// Password: "ibgp-test",
ASN: FRRK8sASN,
Password: "ibgp-test",
MultiHop: false,
},
Router: frrconfig.RouterConfig{
ASN: FRRK8sASN,
BGPPort: 179,
// Password: "ibgp-test",
ASN: FRRK8sASN,
BGPPort: 179,
Password: "ibgp-test",
},
Network: kindNetwork,
}
Expand All @@ -385,14 +385,14 @@ func frrContainersConfigs(image string) map[string]frrcontainer.Config {
Name: "ibgp-multi-hop",
Image: image,
Neighbor: frrconfig.NeighborConfig{
ASN: FRRK8sASN,
// Password: "ibgp-test",
ASN: FRRK8sASN,
Password: "ibgp-test",
MultiHop: true,
},
Router: frrconfig.RouterConfig{
ASN: FRRK8sASN,
BGPPort: 180,
// Password: "ibgp-test",
ASN: FRRK8sASN,
BGPPort: 180,
Password: "ibgp-test",
},
Network: defaultNextHopSettings.multiHopNetwork,
HostIPv4: hostIPv4,
Expand All @@ -402,14 +402,14 @@ func frrContainersConfigs(image string) map[string]frrcontainer.Config {
Name: "ebgp-multi-hop",
Image: image,
Neighbor: frrconfig.NeighborConfig{
ASN: FRRK8sASN,
// Password: "ebgp-test",
ASN: FRRK8sASN,
Password: "ebgp-test",
MultiHop: true,
},
Router: frrconfig.RouterConfig{
ASN: externalASN,
BGPPort: 180,
//Password: "ebgp-test",
ASN: externalASN,
BGPPort: 180,
Password: "ebgp-test",
},
Network: defaultNextHopSettings.multiHopNetwork,
HostIPv4: hostIPv4,
Expand Down Expand Up @@ -438,62 +438,60 @@ func vrfContainersConfig(image string) map[string]frrcontainer.Config {
Image: image,
Network: vrfNetwork,
Neighbor: frrconfig.NeighborConfig{
ASN: FRRK8sASNVRF,
// Password: "vrf-test",
ASN: FRRK8sASNVRF,
Password: "vrf-test",
MultiHop: false,
},
Router: frrconfig.RouterConfig{
ASN: externalASN,
// Password: "vrf-test",
BGPPort: 179,
VRF: VRFName,
ASN: externalASN,
Password: "vrf-test",
BGPPort: 179,
VRF: VRFName,
},
}
res["ibgp-vrf-single-hop"] = frrcontainer.Config{
Name: "ibgp-vrf-single-hop",
Image: image,
Network: vrfNetwork,
Neighbor: frrconfig.NeighborConfig{
ASN: FRRK8sASNVRF,
// Password: "vrf-test",
ASN: FRRK8sASNVRF,
Password: "vrf-test",
MultiHop: false,
},
Router: frrconfig.RouterConfig{
ASN: FRRK8sASNVRF,
BGPPort: 179,
// Password: "vrf-test",
VRF: VRFName,
ASN: FRRK8sASNVRF,
BGPPort: 179,
Password: "vrf-test",
VRF: VRFName,
},
}
res["ibgp-vrf-multi-hop"] = frrcontainer.Config{
Name: "ibgp-vrf-multi-hop",
Image: image,
Neighbor: frrconfig.NeighborConfig{
ASN: FRRK8sASNVRF,
// Password: "ibgp-test",
ASN: FRRK8sASNVRF,
Password: "ibgp-test",
MultiHop: true,
},
Router: frrconfig.RouterConfig{
ASN: FRRK8sASNVRF,
BGPPort: 180,
// Password: "ibgp-test",
VRF: VRFName,
ASN: FRRK8sASNVRF,
BGPPort: 180,
Password: "ibgp-test",
VRF: VRFName,
},
Network: vrfNextHopSettings.multiHopNetwork,
}
res["ebgp-vrf-multi-hop"] = frrcontainer.Config{
Name: "ebgp-vrf-multi-hop",
Image: image,
Neighbor: frrconfig.NeighborConfig{
ASN: FRRK8sASNVRF,
//Password: "ebgp-test",
ASN: FRRK8sASNVRF,
MultiHop: true,
},
Router: frrconfig.RouterConfig{
ASN: externalASN,
BGPPort: 180,
// Password: "ebgp-test",
VRF: VRFName,
VRF: VRFName,
},
Network: vrfNextHopSettings.multiHopNetwork,
}
Expand Down
14 changes: 7 additions & 7 deletions e2etests/tests/advertise_and_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ var _ = ginkgo.Describe("Advertising and Receiving routes", func() {

ginkgo.DescribeTable("Works with external frrs", func(p params) {
frrs := config.ContainersForVRF(infra.FRRContainers, p.vrf)
peersV4, peersV6 := config.PeersForContainers(frrs, p.ipFamily)
p.modifyPeers(peersV4, peersV6)
neighbors := config.NeighborsFromPeers(peersV4, peersV6)
peersConfig := config.PeersForContainers(frrs, p.ipFamily)
p.modifyPeers(peersConfig.PeersV4, peersConfig.PeersV6)
neighbors := config.NeighborsFromPeers(peersConfig.PeersV4, peersConfig.PeersV6)

config := frrk8sv1beta1.FRRConfiguration{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -101,7 +101,7 @@ var _ = ginkgo.Describe("Advertising and Receiving routes", func() {
})
framework.ExpectNoError(err)
}
err := updater.Update(config)
err := updater.Update(peersConfig.Secrets, config)
framework.ExpectNoError(err)

nodes, err := k8s.Nodes(cs)
Expand All @@ -115,7 +115,7 @@ var _ = ginkgo.Describe("Advertising and Receiving routes", func() {
framework.ExpectNoError(err)

ginkgo.By("validating")
p.validate(peersV4, peersV6, pods, nodes)
p.validate(peersConfig.PeersV4, peersConfig.PeersV6, pods, nodes)

if p.splitCfg == nil {
return
Expand All @@ -132,15 +132,15 @@ var _ = ginkgo.Describe("Advertising and Receiving routes", func() {
cfgs, err := p.splitCfg(config)
framework.ExpectNoError(err)

err = updater.Update(cfgs...)
err = updater.Update(peersConfig.Secrets, cfgs...)
framework.ExpectNoError(err)

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

ginkgo.By("validating with splitted config")
p.validate(peersV4, peersV6, pods, nodes)
p.validate(peersConfig.PeersV4, peersConfig.PeersV6, pods, nodes)
},
ginkgo.Entry("IPV4 - One config for advertising, the other for receiving", params{
ipFamily: ipfamily.IPv4,
Expand Down
14 changes: 7 additions & 7 deletions e2etests/tests/advertisement.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ var _ = ginkgo.Describe("Advertisement", func() {

ginkgo.DescribeTable("Works with external frrs", func(p params) {
frrs := config.ContainersForVRF(infra.FRRContainers, p.vrf)
peersV4, peersV6 := config.PeersForContainers(frrs, p.ipFamily)
p.modifyPeers(peersV4, peersV6)
neighbors := config.NeighborsFromPeers(peersV4, peersV6)
peersConfig := config.PeersForContainers(frrs, p.ipFamily)
p.modifyPeers(peersConfig.PeersV4, peersConfig.PeersV6)
neighbors := config.NeighborsFromPeers(peersConfig.PeersV4, peersConfig.PeersV6)

config := frrk8sv1beta1.FRRConfiguration{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -97,7 +97,7 @@ var _ = ginkgo.Describe("Advertisement", func() {
framework.ExpectNoError(err)
}

err := updater.Update(config)
err := updater.Update(peersConfig.Secrets, config)
framework.ExpectNoError(err)

nodes, err := k8s.Nodes(cs)
Expand All @@ -108,7 +108,7 @@ var _ = ginkgo.Describe("Advertisement", func() {
}

ginkgo.By("validating")
p.validate(peersV4, peersV6, nodes)
p.validate(peersConfig.PeersV4, peersConfig.PeersV6, nodes)

if p.splitCfg == nil {
return
Expand All @@ -125,15 +125,15 @@ var _ = ginkgo.Describe("Advertisement", func() {
cfgs, err := p.splitCfg(config)
framework.ExpectNoError(err)

err = updater.Update(cfgs...)
err = updater.Update(peersConfig.Secrets, cfgs...)
framework.ExpectNoError(err)

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

ginkgo.By("validating with splitted config")
p.validate(peersV4, peersV6, nodes)
p.validate(peersConfig.PeersV4, peersConfig.PeersV6, nodes)
},
ginkgo.Entry("IPV4 - Advertise with mode allowall", params{
ipFamily: ipfamily.IPv4,
Expand Down
Loading

0 comments on commit 62324a1

Please sign in to comment.