Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-metallb-nodeselector-tc #347

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gkopels
Copy link
Collaborator

@gkopels gkopels commented Dec 28, 2024

moving test cases from cnf-gotest to eco-gotest

@gkopels gkopels force-pushed the add-nodeselector-testcase branch 5 times, most recently from c92959e to 1019bfe Compare December 29, 2024 06:25

// ValidateLocalPref verifies local pref from FRR is equal to configured Local Pref.
func ValidateLocalPref(frrPod *pod.Builder, localPref uint32, ipFamily string) error {
var (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

err error
)

res, err = frrPod.ExecCommand(append(netparam.VtySh,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use getBGPStatus func

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

return fmt.Errorf("failed to parse route local preference %w", err)
}

for _, locPref := range toParse.Routes {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for _, locPref := range toParse.Routes {
for _, route := range toParse.Routes {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

for _, locPref := range toParse.Routes {
if locPref[0].LocalPref != localPref {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we expect to validate only first route?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only has one route

}
}

return err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return nil

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Expect(err).ToNot(HaveOccurred(), "Fail to validate local preference")

By("Validate BGP Community exists with the node selector")
output, err := frr.GetBGPCommunityStatus(frrPod0, noAdvertise, strings.ToLower(netparam.IPV4Family))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
output, err := frr.GetBGPCommunityStatus(frrPod0, noAdvertise, strings.ToLower(netparam.IPV4Family))
bgpStatus, err := frr.GetBGPCommunityStatus(frrPod0, noAdvertise, strings.ToLower(netparam.IPV4Family))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Expect(len(output.Routes)).To(Equal(1))

By("Validate BGP Community does not exist without the node selector")
output, err = frr.GetBGPCommunityStatus(frrPod1, customCommunity, strings.ToLower(netparam.IPV4Family))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
output, err = frr.GetBGPCommunityStatus(frrPod1, customCommunity, strings.ToLower(netparam.IPV4Family))
bgpStatus, err = frr.GetBGPCommunityStatus(frrPod1, customCommunity, strings.ToLower(netparam.IPV4Family))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

_, err := metallb.NewBPGPeerBuilder(APIClient, name, NetConfig.MlbOperatorNamespace,
peerIP, tsparams.LocalBGPASN, tsparams.LocalBGPASN).WithPassword(tsparams.BGPPassword).Create()

return err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate error here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validating

return ipAddressPool
}

func createBGPPeer(name, peerIP string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't use createBGPPeerAndVerifyIfItsReady?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using

Comment on lines +255 to +209
setupMetalLbService("service-1", netparam.IPV4Family, ipAddressPool1, "Cluster")
setupMetalLbService("service-2", netparam.IPV4Family, ipAddressPool2, "Cluster")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that expected that you create 2 the same services with different name in case single IP addressPool?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two different ipaddresspools

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about line 112
frrPod0, frrPod1 := setupTestCase(ipAddressPool, ipAddressPool, frrk8sPods)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes there is two services on a single IPaddressPool in the original test case but lets talk to make sure I understand your question.

@gkopels gkopels force-pushed the add-nodeselector-testcase branch 5 times, most recently from c225bdf to 876bc6e Compare January 30, 2025 15:26
Comment on lines 507 to 519
toParse, err := getBgpStatus(frrPod, fmt.Sprintf("show ip bgp %s json", ipFamily))

if err != nil {
return fmt.Errorf("failed to parse route local preference %w", err)
}

for _, route := range toParse.Routes {
if route[0].LocalPref != localPref {
return fmt.Errorf("incorrect localPref: %d", localPref)
}
}

return nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
toParse, err := getBgpStatus(frrPod, fmt.Sprintf("show ip bgp %s json", ipFamily))
if err != nil {
return fmt.Errorf("failed to parse route local preference %w", err)
}
for _, route := range toParse.Routes {
if route[0].LocalPref != localPref {
return fmt.Errorf("incorrect localPref: %d", localPref)
}
}
return nil
bgpStatus, err := getBgpStatus(frrPod, fmt.Sprintf("show ip bgp %s json", ipFamily))
if err != nil {
return fmt.Errorf("failed to get BGP status %w", err)
}
for _, route := range bgpStatus.Routes {
if route[0].LocalPref != localPref {
return fmt.Errorf("incorrect localPref: %d", localPref)
}
}
return nil

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


for _, route := range toParse.Routes {
if route[0].LocalPref != localPref {
return fmt.Errorf("incorrect localPref: %d", localPref)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add what local pref we expected

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

frrk8sPods, err = pod.List(APIClient, NetConfig.MlbOperatorNamespace, metav1.ListOptions{
LabelSelector: frrNodeLabel,
})
Expect(err).ToNot(HaveOccurred(), "Failed to list speaker pods")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Expect(err).ToNot(HaveOccurred(), "Failed to list speaker pods")
Expect(err).ToNot(HaveOccurred(), "Failed to list frrk8s pods")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Context("Single IPAddressPool", func() {

var (
err error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

err = metallbenv.CreateNewMetalLbDaemonSetAndWaitUntilItsRunning(tsparams.DefaultTimeout, workerLabelMap)
Expect(err).ToNot(HaveOccurred(), "Failed to recreate metalLb daemonset")

waitForWebHookRunning()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
waitForWebHookRunning()
waitForFRRK8SWebHookRunning()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I moved to general afterall no longer needed as a separate func. Removed

Expect(len(output.Routes)).To(Equal(1))

By("Validate BGP Community does not exist without the node selector")
output, err = frr.GetBGPCommunityStatus(frrPod1, tsparams.CustomCommunity, strings.ToLower(netparam.IPV4Family))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bgpStatus

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Expect(err).ToNot(HaveOccurred(), "Failed to collect bgp community status")
Expect(len(output.Routes)).To(Equal(1))

By("Validate BGP Community does not exist without the node selector")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we check that the comunity doesn't exist?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the description. We can add a negitive check as well. But not sure it is needed. We are just validating the the correct community has been added to the route.

Comment on lines +255 to +209
setupMetalLbService("service-1", netparam.IPV4Family, ipAddressPool1, "Cluster")
setupMetalLbService("service-2", netparam.IPV4Family, ipAddressPool2, "Cluster")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about line 112
frrPod0, frrPod1 := setupTestCase(ipAddressPool, ipAddressPool, frrk8sPods)

// BGPTestPeer is the bgppeer name.
BGPTestPeer = "testpeer"
// FrrK8WebHookServer is the web hook server running in namespace metallb-system.
FrrK8WebHookServer = "frr-k8s-webhook-server"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you created the variable, please replace it everywhere it is used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced

Comment on lines 94 to 98
By("Creating a new instance of MetalLB Speakers on workers")
err = metallbenv.CreateNewMetalLbDaemonSetAndWaitUntilItsRunning(tsparams.DefaultTimeout, workerLabelMap)
Expect(err).ToNot(HaveOccurred(), "Failed to recreate metalLb daemonset")

waitForWebHookRunning()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to wait specifically for the frrk8s webhook? If so, it should be a part of metallbenv.CreateNewMetalLbDaemonSetAndWaitUntilItsRunning()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember from the frrk8 test cases that the webhook was the took longer to come up. For those test cases I didnt add it to CreateNewMetalLbDaemonSetAndWaitUntilItsRunning but can.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The webhook is the last to come up. I added it to the CreateNewMetalLbDaemonSetAndWaitUntilItsRunning. Without the check it fails

@gkopels gkopels force-pushed the add-nodeselector-testcase branch 4 times, most recently from 90eb7ab to 87b31d6 Compare February 1, 2025 19:32
nodeAddrList []string
addressPool []string
frrk8sPods []*pod.Builder
frrNodeLabel = "app=frr-k8s"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to const.

Comment on lines 139 to 141
_, err = frr.GetBGPCommunityStatus(frrPod1, tsparams.CustomCommunity,
strings.ToLower(netparam.IPV4Family))
Expect(err).ToNot(HaveOccurred(), "Failed to collect bgp community status")
Expect(len(bgpStatus.Routes)).To(Equal(2))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, err = frr.GetBGPCommunityStatus(frrPod1, tsparams.CustomCommunity,
strings.ToLower(netparam.IPV4Family))
Expect(err).ToNot(HaveOccurred(), "Failed to collect bgp community status")
Expect(len(bgpStatus.Routes)).To(Equal(2))
bgpStatus, err = frr.GetBGPCommunityStatus(frrPod1, tsparams.CustomCommunity,
strings.ToLower(netparam.IPV4Family))
Expect(err).ToNot(HaveOccurred(), "Failed to collect bgp community status")
Expect(len(bgpStatus.Routes)).To(Equal(2))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to change

ipAddressPool1 := createIPAddressPool(ipaddressPoolName1, addressPool)
ipAddressPool2 := createIPAddressPool(ipaddressPoolName2, addressPool2)

frrPod0, frrPod1 := setupTestCase(ipAddressPool1, ipAddressPool2, frrk8sPods)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add By()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

By("Create a single IPAddressPool")
ipAddressPool := createIPAddressPool(ipaddressPoolName1, addressPool)

frrPod0, frrPod1 := setupTestCase(ipAddressPool, ipAddressPool, frrk8sPods)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add By()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Comment on lines +255 to +209
setupMetalLbService("service-1", netparam.IPV4Family, ipAddressPool1, "Cluster")
setupMetalLbService("service-2", netparam.IPV4Family, ipAddressPool2, "Cluster")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@gkopels gkopels force-pushed the add-nodeselector-testcase branch from 87b31d6 to c0bee71 Compare February 4, 2025 11:14
@gkopels gkopels force-pushed the add-nodeselector-testcase branch from c0bee71 to b7c20ae Compare February 4, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants