Skip to content

Commit 514c5a9

Browse files
committed
Fail early if ipMode not Proxy after creation, and
Skip if Cluster has less than 2 nodes Deploy pods on different nodes for ESIPP test
1 parent 819f41b commit 514c5a9

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

test/e2e/cloud-provider-oci/load_balancer.go

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strconv"
2424
"strings"
2525
"sync"
26+
"time"
2627

2728
. "github.com/onsi/ginkgo"
2829
. "github.com/onsi/gomega"
@@ -699,11 +700,11 @@ var _ = Describe("IpMode [Slow]", func() {
699700
},
700701
}
701702
Context("[cloudprovider][ccm][lb][ipMode]", func() {
702-
It("should work from pods", func() {
703+
It("traffic should work from pods via load balancer", func() {
703704
for _, test := range esippTestsArray {
704705
By("Running test for: " + test.lbType)
705706
namespace := f.Namespace.Name
706-
serviceName := "external-local-" + test.lbType
707+
serviceName := "internal-local-" + test.lbType
707708
jig := sharedfw.NewServiceTestJig(cs, serviceName)
708709
nodes := jig.GetNodes(sharedfw.MaxNodesForEndpointsTests)
709710

@@ -714,6 +715,10 @@ var _ = Describe("IpMode [Slow]", func() {
714715
Expect(cs.CoreV1().Services(svc.Namespace).Delete(context.Background(), svc.Name, metav1.DeleteOptions{})).NotTo(HaveOccurred())
715716
}()
716717

718+
if *svc.Status.LoadBalancer.Ingress[0].IPMode != v1.LoadBalancerIPModeProxy {
719+
sharedfw.Failf("IpMode on the service is '%v', expected 'Proxy'", *svc.Status.LoadBalancer.Ingress[0].IPMode)
720+
}
721+
717722
ingressIP := sharedfw.GetIngressPoint(&svc.Status.LoadBalancer.Ingress[0])
718723
port := strconv.Itoa(int(svc.Spec.Ports[0].Port))
719724
ipPort := net.JoinHostPort(ingressIP, port)
@@ -753,8 +758,9 @@ var _ = Describe("IpMode [Slow]", func() {
753758
})
754759
})
755760

756-
// Test for ESIPP (External Source IP Preservation) via NLB
757-
var _ = Describe("ESIPP [Slow]", func() {
761+
// Test for ESIPP (External Source IP Preservation) via NLB using new ipMode="Proxy".
762+
// Source and destination pods need to be on different nodes for this test so the test will be skipped id there are less than 2 nodes.
763+
var _ = Describe("ESIPP - IpMode Proxy [Slow]", func() {
758764

759765
baseName := "esipp-internal"
760766
f := sharedfw.NewDefaultFramework(baseName)
@@ -782,15 +788,25 @@ var _ = Describe("ESIPP [Slow]", func() {
782788
},
783789
}
784790
Context("[cloudprovider][ccm][lb][esipp]", func() {
785-
It("should work from pods", func() {
791+
It("should preserve source IP of pod with ipMode Proxy", func() {
786792
for _, test := range esippTestsArray {
787793
By("Running test for: " + test.lbType)
788794
namespace := f.Namespace.Name
789-
serviceName := "external-local-" + test.lbType
795+
serviceName := "internal-local-" + test.lbType
790796
jig := sharedfw.NewServiceTestJig(cs, serviceName)
791797
nodes := jig.GetNodes(sharedfw.MaxNodesForEndpointsTests)
798+
// Can not run the test if the cluster has less than 2 nodes
799+
if len(nodes.Items) < 2 {
800+
// We can decide to scale the nodepool as well. We already do so for [node-local] test.
801+
Skip("Skipping test since cluster has less than 2 nodes")
802+
}
792803

793-
svc := jig.CreateOnlyLocalLoadBalancerService(namespace, serviceName, loadBalancerCreateTimeout, true, test.CreationAnnotations, func(s *v1.Service) {
804+
By("creating a pod to be part of the service " + serviceName)
805+
jig.RunOrFail(namespace, func(s *v1.ReplicationController) {
806+
nodeName := nodes.Items[0].Name
807+
s.Spec.Template.Spec.NodeName = nodeName
808+
})
809+
svc := jig.CreateOnlyLocalLoadBalancerService(namespace, serviceName, loadBalancerCreateTimeout, false, test.CreationAnnotations, func(s *v1.Service) {
794810
s.Spec.Ports = []v1.ServicePort{v1.ServicePort{Name: "http", Port: 80, TargetPort: intstr.FromInt(80)},
795811
v1.ServicePort{Name: "https", Port: 443, TargetPort: intstr.FromInt(80)}}
796812
})
@@ -800,11 +816,15 @@ var _ = Describe("ESIPP [Slow]", func() {
800816
Expect(cs.CoreV1().Services(svc.Namespace).Delete(context.Background(), svc.Name, metav1.DeleteOptions{})).NotTo(HaveOccurred())
801817
}()
802818

819+
if *svc.Status.LoadBalancer.Ingress[0].IPMode != v1.LoadBalancerIPModeProxy {
820+
sharedfw.Failf("IpMode on the service is '%v', expected 'Proxy'", *svc.Status.LoadBalancer.Ingress[0].IPMode)
821+
}
822+
803823
ingressIP := sharedfw.GetIngressPoint(&svc.Status.LoadBalancer.Ingress[0])
804824
port := strconv.Itoa(int(svc.Spec.Ports[0].Port))
805825
ipPort := net.JoinHostPort(ingressIP, port)
806826
path := fmt.Sprintf("%s/clientip", ipPort)
807-
nodeName := nodes.Items[0].Name
827+
nodeName := nodes.Items[1].Name
808828
podName := "execpod-sourceip"
809829

810830
By(fmt.Sprintf("Creating %v on node %v", podName, nodeName))
@@ -821,18 +841,20 @@ var _ = Describe("ESIPP [Slow]", func() {
821841
sharedfw.Logf("Waiting up to %v wget %v", sharedfw.KubeProxyLagTimeout, path)
822842
cmd := fmt.Sprintf(`wget -T 30 -qO- %v`, path)
823843

824-
var srcIP string
825-
By(fmt.Sprintf("Hitting external lb %v from pod %v on node %v", ingressIP, podName, nodeName))
826-
if pollErr := wait.PollImmediate(sharedfw.K8sResourcePoll, sharedfw.LoadBalancerCreateTimeoutDefault, func() (bool, error) {
844+
var srcIP, expectedIP string
845+
By(fmt.Sprintf("Hitting external lb %v from pod %v (%v) on node %v", ingressIP, podName, execPod.Status.PodIP, nodeName))
846+
if pollErr := wait.PollImmediate(sharedfw.K8sResourcePoll, 5*time.Minute, func() (bool, error) {
847+
expectedIP = execPod.Spec.NodeName // Node IP
848+
827849
stdout, err := sharedfw.RunHostCmd(execPod.Namespace, execPod.Name, cmd)
828850
if err != nil {
829851
sharedfw.Logf("got err: %v, retry until timeout", err)
830852
return false, nil
831853
}
832854
srcIP = strings.TrimSpace(strings.Split(stdout, ":")[0])
833-
return srcIP == execPod.Status.PodIP, nil
855+
return srcIP == expectedIP, nil
834856
}); pollErr != nil {
835-
sharedfw.Failf("Source IP not preserved from %v, expected '%v' got '%v'", podName, execPod.Status.PodIP, srcIP)
857+
sharedfw.Failf("Source IP not preserved from %v, expected '%v' got '%v'", podName, expectedIP, srcIP)
836858
}
837859
}
838860
})

0 commit comments

Comments
 (0)