From b45505d51d257317d2f3865c2d16afca6b8da16a Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Sun, 18 Feb 2024 18:48:21 +0800 Subject: [PATCH] fix ci Signed-off-by: Hang Yan --- test/e2e/packetsampling_test.go | 53 +++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/test/e2e/packetsampling_test.go b/test/e2e/packetsampling_test.go index e4fee20f14f..7d969ea5747 100644 --- a/test/e2e/packetsampling_test.go +++ b/test/e2e/packetsampling_test.go @@ -17,8 +17,10 @@ import ( ) var ( - psNamespace = "default" - psSecretName = "ps-secret" + psNamespace = "default" + psSecretName = "ps-secret" + psNginxPodName = "test-nginx" + psBusyboxPodName = "busybox" ) type psTestCase struct { @@ -90,26 +92,31 @@ func skipIfPacketSamplingDisabled(t *testing.T) { // testPacketSamplingTCP verifies if PacketSampling can capture tcp packets. func testPacketSamplingIntraNode(t *testing.T, data *TestData) { - var err error - k8sUtils, err = NewKubernetesUtils(data) - failOnError(err, t) - nodeIdx := 0 if len(clusterInfo.windowsNodes) != 0 { nodeIdx = clusterInfo.windowsNodes[0] } node1 := nodeName(nodeIdx) - node1Pods, _, node1CleanupFn := createTestAgnhostPods(t, data, 3, data.testNamespace, node1) + + node1Pods, _, node1CleanupFn := createTestAgnhostPods(t, data, 2, data.testNamespace, node1) defer node1CleanupFn() + err := data.createNginxPodOnNode(psNginxPodName, data.testNamespace, node1, false) + require.NoError(t, err) + defer deletePodWrapper(t, data, data.testNamespace, psNginxPodName) + + err = data.createBusyboxPodOnNode(psBusyboxPodName, data.testNamespace, node1, false) + require.NoError(t, err) + defer deletePodWrapper(t, data, data.testNamespace, psNginxPodName) + // Give a little time for Windows containerd Nodes to setup OVS. // Containerd configures port asynchronously, which could cause execution time of installing flow longer than docker. time.Sleep(time.Second * 1) testcases := []psTestCase{ { - name: "ICMPIPv4", + name: "intraNodePacketSamplingIPv4", ipVersion: 4, - srcPod: node1Pods[0], + srcPod: psBusyboxPodName, ps: &crdv1alpha1.PacketSampling{ ObjectMeta: metav1.ObjectMeta{ Name: randName(fmt.Sprintf("%s-%s-to-%s-%s-", data.testNamespace, node1Pods[0], data.testNamespace, node1Pods[1])), @@ -117,11 +124,11 @@ func testPacketSamplingIntraNode(t *testing.T, data *TestData) { Spec: crdv1alpha1.PacketSamplingSpec{ Source: crdv1alpha1.Source{ Namespace: data.testNamespace, - Pod: node1Pods[0], + Pod: psBusyboxPodName, }, Destination: crdv1alpha1.Destination{ Namespace: data.testNamespace, - Pod: node1Pods[1], + Pod: psNginxPodName, }, Type: crdv1alpha1.FirstNSampling, FirstNSamplingConfig: &crdv1alpha1.FirstNSamplingConfig{ @@ -139,7 +146,12 @@ func testPacketSamplingIntraNode(t *testing.T, data *TestData) { }, Packet: crdv1alpha1.Packet{ IPHeader: crdv1alpha1.IPHeader{ - Protocol: protocolICMP, + Protocol: protocolTCP, + }, + TransportHeader: crdv1alpha1.TransportHeader{ + TCP: &crdv1alpha1.TCPHeader{ + DstPort: 80, + }, }, }, }, @@ -201,9 +213,20 @@ func runPacketSamplingTest(t *testing.T, data *TestData, tc psTestCase) { // Give a little time for Nodes to install OVS flows. time.Sleep(time.Second * 2) // Send an ICMP echo packet from the source Pod to the destination. - if err := data.RunPingCommandFromTestPod(PodInfo{srcPod, osString, "", ""}, - data.testNamespace, dstPodIPs, agnhostContainerName, 10, 0, false); err != nil { - t.Logf("Ping '%s' -> '%v' failed: ERROR (%v)", srcPod, *dstPodIPs, err) + if tc.ps.Spec.Packet.IPHeader.Protocol == protocolICMP { + if err := data.RunPingCommandFromTestPod(PodInfo{srcPod, osString, "", ""}, + data.testNamespace, dstPodIPs, agnhostContainerName, 10, 0, false); err != nil { + t.Logf("Ping '%s' -> '%v' failed: ERROR (%v)", srcPod, *dstPodIPs, err) + } + } else if tc.ps.Spec.Packet.IPHeader.Protocol == protocolTCP { + server := dstPodIPs.IPv4.String() + if tc.ipVersion == 6 { + server = dstPodIPs.IPv6.String() + } + url := fmt.Sprintf("%s:%v", server, tc.ps.Spec.Packet.TransportHeader.TCP.DstPort) + if _, _, err := data.runWgetCommandOnBusyboxWithRetry(tc.srcPod, data.testNamespace, url, 3); err != nil { + t.Logf("wget '%s' -> '%v' failed: ERROR (%v)", srcPod, url, err) + } } ps, err := data.waitForPacketSampling(t, tc.ps.Name, tc.expectedPhase)