-
Notifications
You must be signed in to change notification settings - Fork 522
fix gabage u2o openflow #5757
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
Merged
Merged
fix gabage u2o openflow #5757
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -1323,6 +1323,88 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { | |
| framework.ExpectNoError(err) | ||
| } | ||
| }) | ||
|
|
||
| framework.ConformanceIt("should create and delete keepSrcMac OpenFlow rules when u2oInterconnection is enabled", func() { | ||
| f.SkipVersionPriorTo(1, 14, "keepSrcMac OpenFlow rules were introduced in v1.14") | ||
|
|
||
| ginkgo.By("Creating provider network " + providerNetworkName) | ||
| pn := makeProviderNetwork(providerNetworkName, false, linkMap) | ||
| _ = providerNetworkClient.CreateSync(pn) | ||
|
|
||
| ginkgo.By("Getting docker network " + dockerNetworkName) | ||
| network, err := docker.NetworkInspect(dockerNetworkName) | ||
| framework.ExpectNoError(err, "getting docker network "+dockerNetworkName) | ||
|
|
||
| ginkgo.By("Creating vlan " + vlanName) | ||
| vlan := framework.MakeVlan(vlanName, providerNetworkName, 0) | ||
| _ = vlanClient.Create(vlan) | ||
|
|
||
| ginkgo.By("Creating underlay subnet " + subnetName) | ||
| var cidrV4, cidrV6, gatewayV4, gatewayV6 string | ||
| for _, config := range dockerNetwork.IPAM.Config { | ||
| switch util.CheckProtocol(config.Subnet) { | ||
| case apiv1.ProtocolIPv4: | ||
| if f.HasIPv4() { | ||
| cidrV4 = config.Subnet | ||
| gatewayV4 = config.Gateway | ||
| } | ||
| case apiv1.ProtocolIPv6: | ||
| if f.HasIPv6() { | ||
| cidrV6 = config.Subnet | ||
| gatewayV6 = config.Gateway | ||
| } | ||
| } | ||
| } | ||
| underlayCidr := make([]string, 0, 2) | ||
| gateway := make([]string, 0, 2) | ||
| if f.HasIPv4() { | ||
| underlayCidr = append(underlayCidr, cidrV4) | ||
| gateway = append(gateway, gatewayV4) | ||
| } | ||
| if f.HasIPv6() { | ||
| underlayCidr = append(underlayCidr, cidrV6) | ||
| gateway = append(gateway, gatewayV6) | ||
| } | ||
|
|
||
| excludeIPs := make([]string, 0, len(network.Containers)*2) | ||
| for _, container := range network.Containers { | ||
| if container.IPv4Address != "" && f.HasIPv4() { | ||
| excludeIPs = append(excludeIPs, strings.Split(container.IPv4Address, "/")[0]) | ||
| } | ||
| if container.IPv6Address != "" && f.HasIPv6() { | ||
| excludeIPs = append(excludeIPs, strings.Split(container.IPv6Address, "/")[0]) | ||
| } | ||
| } | ||
|
|
||
| ginkgo.By("Creating underlay subnet with u2oInterconnection enabled " + subnetName) | ||
| subnet := framework.MakeSubnet(subnetName, vlanName, strings.Join(underlayCidr, ","), strings.Join(gateway, ","), "", "", excludeIPs, nil, []string{namespaceName}) | ||
| subnet.Spec.U2OInterconnection = true | ||
| _ = subnetClient.CreateSync(subnet) | ||
|
|
||
| ginkgo.By("Waiting for U2OInterconnection status to be ready") | ||
| waitSubnetU2OStatus(f, subnetName, subnetClient, true) | ||
|
|
||
| ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay) | ||
| annotations := map[string]string{ | ||
| util.LogicalSwitchAnnotation: subnetName, | ||
| } | ||
| args := []string{"netexec", "--http-port", strconv.Itoa(curlListenPort)} | ||
| underlayPod := framework.MakePod(namespaceName, u2oPodNameUnderlay, nil, annotations, framework.AgnhostImage, nil, args) | ||
| underlayPod = podClient.CreateSync(underlayPod) | ||
| waitSubnetStatusUpdate(subnetName, subnetClient, 2) | ||
|
|
||
| ginkgo.By("Verifying keepSrcMac OpenFlow rules exist after pod creation") | ||
| checkKeepSrcMacFlow(underlayPod, providerNetworkName, true) | ||
|
|
||
| ginkgo.By("Deleting underlay pod " + u2oPodNameUnderlay) | ||
| podClient.DeleteSync(u2oPodNameUnderlay) | ||
| waitSubnetStatusUpdate(subnetName, subnetClient, 1) | ||
|
|
||
| ginkgo.By("Verifying keepSrcMac OpenFlow rules are deleted after pod deletion") | ||
| // Wait a bit for the flow rules to be cleaned up | ||
| time.Sleep(2 * time.Second) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| checkKeepSrcMacFlow(underlayPod, providerNetworkName, false) | ||
| }) | ||
| }) | ||
|
|
||
| func checkU2OItems(f *framework.Framework, subnet *apiv1.Subnet, underlayPod, overlayPod *corev1.Pod, isU2OCustomVpc bool, pnName string) { | ||
|
|
@@ -1503,25 +1585,26 @@ func checkReachable(podName, podNamespace, sourceIP, targetIP, targetPort string | |
| func checkKeepSrcMacFlow(pod *corev1.Pod, providerNetworkName string, expectRules bool) { | ||
| ginkgo.GinkgoHelper() | ||
|
|
||
| cmd := fmt.Sprintf("kubectl exec -n %s %s -- ip -o link show eth0 | awk '{print $16}'", pod.Namespace, pod.Name) | ||
| output, err := exec.Command("bash", "-c", cmd).CombinedOutput() | ||
| if err != nil { | ||
| framework.Logf("Error getting MAC address: %v, %s", err, string(output)) | ||
| return | ||
| } | ||
| podMac := strings.TrimSpace(string(output)) | ||
|
|
||
| podNodeName := pod.Spec.NodeName | ||
| ginkgo.By(fmt.Sprintf("Checking keepSrcMac OpenFlow rule on node %s for Pod %s with MAC %s (expect rules: %v)", | ||
| podNodeName, pod.Name, podMac, expectRules)) | ||
| framework.Logf("Checking keepSrcMac OpenFlow rule on node %s for Pod %s", podNodeName, pod.Name) | ||
|
|
||
| podMac := pod.Annotations[util.MacAddressAnnotation] | ||
| if podMac == "" { | ||
| if !expectRules { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| var ruleFound bool | ||
| framework.WaitUntil(1*time.Second, 5*time.Second, func(_ context.Context) (bool, error) { | ||
| nodeCmd := fmt.Sprintf("kubectl ko ofctl %s dump-flows br-%s | grep actions=mod_dl_src:%s | wc -l", | ||
| podNodeName, providerNetworkName, podMac) | ||
| output, _ := exec.Command("bash", "-c", nodeCmd).CombinedOutput() | ||
| outputStr := string(output) | ||
| output, err := exec.Command("bash", "-c", nodeCmd).CombinedOutput() | ||
| if err != nil { | ||
| return false, nil | ||
| } | ||
|
|
||
| outputStr := string(output) | ||
| lines := strings.Split(outputStr, "\n") | ||
| var countStr string | ||
| for i := len(lines) - 1; i >= 0; i-- { | ||
|
|
@@ -1538,18 +1621,12 @@ func checkKeepSrcMacFlow(pod *corev1.Pod, providerNetworkName string, expectRule | |
| countNum, _ = strconv.Atoi(matches[0]) | ||
| } | ||
|
|
||
| framework.Logf("Raw output: '%s', extracted count: %d", outputStr, countNum) | ||
| ruleFound = countNum > 0 | ||
|
|
||
| if (expectRules && ruleFound) || (!expectRules && !ruleFound) { | ||
| return true, nil | ||
| } | ||
|
|
||
| if expectRules { | ||
| framework.Logf("keepSrcMac flow rule not found but expected, retrying...") | ||
| } else { | ||
| framework.Logf("keepSrcMac flow rule found but not expected, retrying...") | ||
| } | ||
| return false, nil | ||
| }, "") | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error returned by
action.MarshalText()is being ignored. While errors might be rare for standard OpenFlow actions, it's safer to handle them to prevent unexpected behavior. Please consider checking the error and logging it if it's not nil.