@@ -23,7 +23,6 @@ import (
23
23
"context"
24
24
"fmt"
25
25
"io"
26
- "math/big"
27
26
"net"
28
27
"net/http"
29
28
"strconv"
@@ -32,8 +31,6 @@ import (
32
31
"sync/atomic"
33
32
"time"
34
33
35
- compute "google.golang.org/api/compute/v1"
36
-
37
34
appsv1 "k8s.io/api/apps/v1"
38
35
v1 "k8s.io/api/core/v1"
39
36
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -52,7 +49,6 @@ import (
52
49
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
53
50
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
54
51
e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
55
- "k8s.io/kubernetes/test/e2e/framework/providers/gce"
56
52
e2erc "k8s.io/kubernetes/test/e2e/framework/rc"
57
53
e2eservice "k8s.io/kubernetes/test/e2e/framework/service"
58
54
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
@@ -125,13 +121,9 @@ var _ = common.SIGDescribe("LoadBalancers", func() {
125
121
f .NamespacePodSecurityLevel = admissionapi .LevelPrivileged
126
122
127
123
var cs clientset.Interface
128
- var subnetPrefix * net.IPNet
129
- var err error
130
124
131
125
ginkgo .BeforeEach (func (ctx context.Context ) {
132
126
cs = f .ClientSet
133
- subnetPrefix , err = getSubnetPrefix (ctx , cs )
134
- framework .ExpectNoError (err )
135
127
})
136
128
137
129
ginkgo .AfterEach (func (ctx context.Context ) {
@@ -187,37 +179,8 @@ var _ = common.SIGDescribe("LoadBalancers", func() {
187
179
framework .ExpectNoError (err )
188
180
189
181
// Change the services to LoadBalancer.
190
-
191
- // Here we test that LoadBalancers can receive static IP addresses. This isn't
192
- // necessary, but is an additional feature this monolithic test checks.
193
- requestedIP := ""
194
- staticIPName := ""
195
- if framework .ProviderIs ("gce" , "gke" ) {
196
- ginkgo .By ("creating a static load balancer IP" )
197
- staticIPName = fmt .Sprintf ("e2e-external-lb-test-%s" , framework .RunID )
198
- gceCloud , err := gce .GetGCECloud ()
199
- framework .ExpectNoError (err , "failed to get GCE cloud provider" )
200
-
201
- err = gceCloud .ReserveRegionAddress (& compute.Address {Name : staticIPName }, gceCloud .Region ())
202
- defer func () {
203
- if staticIPName != "" {
204
- // Release GCE static IP - this is not kube-managed and will not be automatically released.
205
- if err := gceCloud .DeleteRegionAddress (staticIPName , gceCloud .Region ()); err != nil {
206
- framework .Logf ("failed to release static IP %s: %v" , staticIPName , err )
207
- }
208
- }
209
- }()
210
- framework .ExpectNoError (err , "failed to create region address: %s" , staticIPName )
211
- reservedAddr , err := gceCloud .GetRegionAddress (staticIPName , gceCloud .Region ())
212
- framework .ExpectNoError (err , "failed to get region address: %s" , staticIPName )
213
-
214
- requestedIP = reservedAddr .Address
215
- framework .Logf ("Allocated static load balancer IP: %s" , requestedIP )
216
- }
217
-
218
182
ginkgo .By ("changing the TCP service to type=LoadBalancer" )
219
183
_ , err = tcpJig .UpdateService (ctx , func (s * v1.Service ) {
220
- s .Spec .LoadBalancerIP = requestedIP // will be "" if not applicable
221
184
s .Spec .Type = v1 .ServiceTypeLoadBalancer
222
185
})
223
186
framework .ExpectNoError (err )
@@ -229,30 +192,9 @@ var _ = common.SIGDescribe("LoadBalancers", func() {
229
192
if int (tcpService .Spec .Ports [0 ].NodePort ) != tcpNodePort {
230
193
framework .Failf ("TCP Spec.Ports[0].NodePort changed (%d -> %d) when not expected" , tcpNodePort , tcpService .Spec .Ports [0 ].NodePort )
231
194
}
232
- if requestedIP != "" && e2eservice .GetIngressPoint (& tcpService .Status .LoadBalancer .Ingress [0 ]) != requestedIP {
233
- framework .Failf ("unexpected TCP Status.LoadBalancer.Ingress (expected %s, got %s)" , requestedIP , e2eservice .GetIngressPoint (& tcpService .Status .LoadBalancer .Ingress [0 ]))
234
- }
235
195
tcpIngressIP := e2eservice .GetIngressPoint (& tcpService .Status .LoadBalancer .Ingress [0 ])
236
196
framework .Logf ("TCP load balancer: %s" , tcpIngressIP )
237
197
238
- if framework .ProviderIs ("gce" , "gke" ) {
239
- // Do this as early as possible, which overrides the `defer` above.
240
- // This is mostly out of fear of leaking the IP in a timeout case
241
- // (as of this writing we're not 100% sure where the leaks are
242
- // coming from, so this is first-aid rather than surgery).
243
- ginkgo .By ("demoting the static IP to ephemeral" )
244
- if staticIPName != "" {
245
- gceCloud , err := gce .GetGCECloud ()
246
- framework .ExpectNoError (err , "failed to get GCE cloud provider" )
247
- // Deleting it after it is attached "demotes" it to an
248
- // ephemeral IP, which can be auto-released.
249
- if err := gceCloud .DeleteRegionAddress (staticIPName , gceCloud .Region ()); err != nil {
250
- framework .Failf ("failed to release static IP %s: %v" , staticIPName , err )
251
- }
252
- staticIPName = ""
253
- }
254
- }
255
-
256
198
err = tcpJig .CheckServiceReachability (ctx , tcpService , execPod )
257
199
framework .ExpectNoError (err )
258
200
@@ -377,54 +319,12 @@ var _ = common.SIGDescribe("LoadBalancers", func() {
377
319
framework .ExpectNoError (err )
378
320
379
321
// Change the services to LoadBalancer.
380
-
381
- // Here we test that LoadBalancers can receive static IP addresses. This isn't
382
- // necessary, but is an additional feature this monolithic test checks.
383
- requestedIP := ""
384
- staticIPName := ""
385
- ginkgo .By ("creating a static load balancer IP" )
386
- staticIPName = fmt .Sprintf ("e2e-external-lb-test-%s" , framework .RunID )
387
- gceCloud , err := gce .GetGCECloud ()
388
- framework .ExpectNoError (err , "failed to get GCE cloud provider" )
389
-
390
- err = gceCloud .ReserveRegionAddress (& compute.Address {Name : staticIPName }, gceCloud .Region ())
391
- defer func () {
392
- if staticIPName != "" {
393
- // Release GCE static IP - this is not kube-managed and will not be automatically released.
394
- if err := gceCloud .DeleteRegionAddress (staticIPName , gceCloud .Region ()); err != nil {
395
- framework .Logf ("failed to release static IP %s: %v" , staticIPName , err )
396
- }
397
- }
398
- }()
399
- framework .ExpectNoError (err , "failed to create region address: %s" , staticIPName )
400
- reservedAddr , err := gceCloud .GetRegionAddress (staticIPName , gceCloud .Region ())
401
- framework .ExpectNoError (err , "failed to get region address: %s" , staticIPName )
402
-
403
- requestedIP = reservedAddr .Address
404
- framework .Logf ("Allocated static load balancer IP: %s" , requestedIP )
405
-
406
322
ginkgo .By ("changing the UDP service to type=LoadBalancer" )
407
323
_ , err = udpJig .UpdateService (ctx , func (s * v1.Service ) {
408
324
s .Spec .Type = v1 .ServiceTypeLoadBalancer
409
325
})
410
326
framework .ExpectNoError (err )
411
327
412
- // Do this as early as possible, which overrides the `defer` above.
413
- // This is mostly out of fear of leaking the IP in a timeout case
414
- // (as of this writing we're not 100% sure where the leaks are
415
- // coming from, so this is first-aid rather than surgery).
416
- ginkgo .By ("demoting the static IP to ephemeral" )
417
- if staticIPName != "" {
418
- gceCloud , err := gce .GetGCECloud ()
419
- framework .ExpectNoError (err , "failed to get GCE cloud provider" )
420
- // Deleting it after it is attached "demotes" it to an
421
- // ephemeral IP, which can be auto-released.
422
- if err := gceCloud .DeleteRegionAddress (staticIPName , gceCloud .Region ()); err != nil {
423
- framework .Failf ("failed to release static IP %s: %v" , staticIPName , err )
424
- }
425
- staticIPName = ""
426
- }
427
-
428
328
var udpIngressIP string
429
329
ginkgo .By ("waiting for the UDP service to have a load balancer" )
430
330
// 2nd one should be faster since they ran in parallel.
@@ -611,135 +511,6 @@ var _ = common.SIGDescribe("LoadBalancers", func() {
611
511
checkReachabilityFromPod (true , loadBalancerCreateTimeout , namespace , dropPod .Name , svcIP )
612
512
})
613
513
614
- f .It ("should be able to create an internal type load balancer" , f .WithSlow (), func (ctx context.Context ) {
615
- e2eskipper .SkipUnlessProviderIs ("gke" , "gce" )
616
-
617
- createTimeout := e2eservice .GetServiceLoadBalancerCreationTimeout (ctx , cs )
618
- pollInterval := framework .Poll * 10
619
-
620
- namespace := f .Namespace .Name
621
- serviceName := "lb-internal"
622
- jig := e2eservice .NewTestJig (cs , namespace , serviceName )
623
-
624
- ginkgo .By ("creating pod to be part of service " + serviceName )
625
- _ , err := jig .Run (ctx , nil )
626
- framework .ExpectNoError (err )
627
-
628
- enableILB , disableILB := enableAndDisableInternalLB ()
629
-
630
- isInternalEndpoint := func (lbIngress * v1.LoadBalancerIngress ) bool {
631
- ingressEndpoint := e2eservice .GetIngressPoint (lbIngress )
632
- ingressIP := netutils .ParseIPSloppy (ingressEndpoint )
633
- if ingressIP == nil {
634
- framework .Failf ("invalid ingressEndpoint IP address format: %s" , ingressEndpoint )
635
- }
636
- // Needs update for providers using hostname as endpoint.
637
- return subnetPrefix .Contains (ingressIP )
638
- }
639
-
640
- ginkgo .By ("creating a service with type LoadBalancer and cloud specific Internal-LB annotation enabled" )
641
- svc , err := jig .CreateTCPService (ctx , func (svc * v1.Service ) {
642
- svc .Spec .Type = v1 .ServiceTypeLoadBalancer
643
- enableILB (svc )
644
- })
645
- framework .ExpectNoError (err )
646
-
647
- ginkgo .DeferCleanup (func (ctx context.Context ) {
648
- ginkgo .By ("Clean up loadbalancer service" )
649
- e2eservice .WaitForServiceDeletedWithFinalizer (ctx , cs , svc .Namespace , svc .Name )
650
- })
651
-
652
- svc , err = jig .WaitForLoadBalancer (ctx , createTimeout )
653
- framework .ExpectNoError (err )
654
- lbIngress := & svc .Status .LoadBalancer .Ingress [0 ]
655
- svcPort := int (svc .Spec .Ports [0 ].Port )
656
- // should have an internal IP.
657
- if ! isInternalEndpoint (lbIngress ) {
658
- framework .Failf ("lbIngress %v doesn't have an internal IP" , lbIngress )
659
- }
660
-
661
- // ILBs are not accessible from the test orchestrator, so it's necessary to use
662
- // a pod to test the service.
663
- ginkgo .By ("hitting the internal load balancer from pod" )
664
- framework .Logf ("creating pod with host network" )
665
- hostExec := launchHostExecPod (ctx , f .ClientSet , f .Namespace .Name , "ilb-host-exec" )
666
-
667
- framework .Logf ("Waiting up to %v for service %q's internal LB to respond to requests" , createTimeout , serviceName )
668
- tcpIngressIP := e2eservice .GetIngressPoint (lbIngress )
669
- if pollErr := wait .PollImmediate (pollInterval , createTimeout , func () (bool , error ) {
670
- cmd := fmt .Sprintf (`curl -m 5 'http://%v:%v/echo?msg=hello'` , tcpIngressIP , svcPort )
671
- stdout , err := e2eoutput .RunHostCmd (hostExec .Namespace , hostExec .Name , cmd )
672
- if err != nil {
673
- framework .Logf ("error curling; stdout: %v. err: %v" , stdout , err )
674
- return false , nil
675
- }
676
-
677
- if ! strings .Contains (stdout , "hello" ) {
678
- framework .Logf ("Expected output to contain 'hello', got %q; retrying..." , stdout )
679
- return false , nil
680
- }
681
-
682
- framework .Logf ("Successful curl; stdout: %v" , stdout )
683
- return true , nil
684
- }); pollErr != nil {
685
- framework .Failf ("ginkgo.Failed to hit ILB IP, err: %v" , pollErr )
686
- }
687
-
688
- ginkgo .By ("switching to external type LoadBalancer" )
689
- svc , err = jig .UpdateService (ctx , func (svc * v1.Service ) {
690
- disableILB (svc )
691
- })
692
- framework .ExpectNoError (err )
693
- framework .Logf ("Waiting up to %v for service %q to have an external LoadBalancer" , createTimeout , serviceName )
694
- if pollErr := wait .PollImmediate (pollInterval , createTimeout , func () (bool , error ) {
695
- svc , err := cs .CoreV1 ().Services (namespace ).Get (ctx , serviceName , metav1.GetOptions {})
696
- if err != nil {
697
- return false , err
698
- }
699
- lbIngress = & svc .Status .LoadBalancer .Ingress [0 ]
700
- return ! isInternalEndpoint (lbIngress ), nil
701
- }); pollErr != nil {
702
- framework .Failf ("Loadbalancer IP not changed to external." )
703
- }
704
- // should have an external IP.
705
- gomega .Expect (isInternalEndpoint (lbIngress )).To (gomega .BeFalse ())
706
-
707
- ginkgo .By ("hitting the external load balancer" )
708
- framework .Logf ("Waiting up to %v for service %q's external LB to respond to requests" , createTimeout , serviceName )
709
- tcpIngressIP = e2eservice .GetIngressPoint (lbIngress )
710
- e2eservice .TestReachableHTTP (ctx , tcpIngressIP , svcPort , e2eservice .LoadBalancerLagTimeoutDefault )
711
-
712
- // GCE cannot test a specific IP because the test may not own it. This cloud specific condition
713
- // will be removed when GCP supports similar functionality.
714
- if framework .ProviderIs ("azure" ) {
715
- ginkgo .By ("switching back to interal type LoadBalancer, with static IP specified." )
716
- // For a cluster created with CAPZ, node-subnet may not be "10.240.0.0/16", e.g. "10.1.0.0/16".
717
- base := netutils .BigForIP (subnetPrefix .IP )
718
- offset := big .NewInt (0 ).SetBytes (netutils .ParseIPSloppy ("0.0.11.11" ).To4 ()).Int64 ()
719
-
720
- internalStaticIP := netutils .AddIPOffset (base , int (offset )).String ()
721
-
722
- svc , err = jig .UpdateService (ctx , func (svc * v1.Service ) {
723
- svc .Spec .LoadBalancerIP = internalStaticIP
724
- enableILB (svc )
725
- })
726
- framework .ExpectNoError (err )
727
- framework .Logf ("Waiting up to %v for service %q to have an internal LoadBalancer" , createTimeout , serviceName )
728
- if pollErr := wait .PollImmediate (pollInterval , createTimeout , func () (bool , error ) {
729
- svc , err := cs .CoreV1 ().Services (namespace ).Get (ctx , serviceName , metav1.GetOptions {})
730
- if err != nil {
731
- return false , err
732
- }
733
- lbIngress = & svc .Status .LoadBalancer .Ingress [0 ]
734
- return isInternalEndpoint (lbIngress ), nil
735
- }); pollErr != nil {
736
- framework .Failf ("Loadbalancer IP not changed to internal." )
737
- }
738
- // should have the given static internal IP.
739
- gomega .Expect (e2eservice .GetIngressPoint (lbIngress )).To (gomega .Equal (internalStaticIP ))
740
- }
741
- })
742
-
743
514
// [LinuxOnly]: Windows does not support session affinity.
744
515
f .It ("should have session affinity work for LoadBalancer service with ESIPP on" , f .WithSlow (), "[LinuxOnly]" , func (ctx context.Context ) {
745
516
// L4 load balancer affinity `ClientIP` is not supported on AWS ELB.
@@ -852,37 +623,8 @@ var _ = common.SIGDescribe("LoadBalancers", func() {
852
623
framework .ExpectNoError (err )
853
624
854
625
// Change the services to LoadBalancer.
855
-
856
- // Here we test that LoadBalancers can receive static IP addresses. This isn't
857
- // necessary, but is an additional feature this monolithic test checks.
858
- requestedIP := ""
859
- staticIPName := ""
860
- if framework .ProviderIs ("gce" , "gke" ) {
861
- ginkgo .By ("creating a static load balancer IP" )
862
- staticIPName = fmt .Sprintf ("e2e-external-lb-test-%s" , framework .RunID )
863
- gceCloud , err := gce .GetGCECloud ()
864
- framework .ExpectNoError (err , "failed to get GCE cloud provider" )
865
-
866
- err = gceCloud .ReserveRegionAddress (& compute.Address {Name : staticIPName }, gceCloud .Region ())
867
- ginkgo .DeferCleanup (func (ctx context.Context ) {
868
- if staticIPName != "" {
869
- // Release GCE static IP - this is not kube-managed and will not be automatically released.
870
- if err := gceCloud .DeleteRegionAddress (staticIPName , gceCloud .Region ()); err != nil {
871
- framework .Logf ("failed to release static IP %s: %v" , staticIPName , err )
872
- }
873
- }
874
- })
875
- framework .ExpectNoError (err , "failed to create region address: %s" , staticIPName )
876
- reservedAddr , err := gceCloud .GetRegionAddress (staticIPName , gceCloud .Region ())
877
- framework .ExpectNoError (err , "failed to get region address: %s" , staticIPName )
878
-
879
- requestedIP = reservedAddr .Address
880
- framework .Logf ("Allocated static load balancer IP: %s" , requestedIP )
881
- }
882
-
883
626
ginkgo .By ("changing the TCP service to type=LoadBalancer" )
884
627
_ , err = tcpJig .UpdateService (ctx , func (s * v1.Service ) {
885
- s .Spec .LoadBalancerIP = requestedIP // will be "" if not applicable
886
628
s .Spec .Type = v1 .ServiceTypeLoadBalancer
887
629
s .Spec .AllocateLoadBalancerNodePorts = utilpointer .BoolPtr (false )
888
630
})
@@ -895,30 +637,9 @@ var _ = common.SIGDescribe("LoadBalancers", func() {
895
637
if int (tcpService .Spec .Ports [0 ].NodePort ) != 0 {
896
638
framework .Failf ("TCP Spec.Ports[0].NodePort allocated %d when not expected" , tcpService .Spec .Ports [0 ].NodePort )
897
639
}
898
- if requestedIP != "" && e2eservice .GetIngressPoint (& tcpService .Status .LoadBalancer .Ingress [0 ]) != requestedIP {
899
- framework .Failf ("unexpected TCP Status.LoadBalancer.Ingress (expected %s, got %s)" , requestedIP , e2eservice .GetIngressPoint (& tcpService .Status .LoadBalancer .Ingress [0 ]))
900
- }
901
640
tcpIngressIP := e2eservice .GetIngressPoint (& tcpService .Status .LoadBalancer .Ingress [0 ])
902
641
framework .Logf ("TCP load balancer: %s" , tcpIngressIP )
903
642
904
- if framework .ProviderIs ("gce" , "gke" ) {
905
- // Do this as early as possible, which overrides the `defer` above.
906
- // This is mostly out of fear of leaking the IP in a timeout case
907
- // (as of this writing we're not 100% sure where the leaks are
908
- // coming from, so this is first-aid rather than surgery).
909
- ginkgo .By ("demoting the static IP to ephemeral" )
910
- if staticIPName != "" {
911
- gceCloud , err := gce .GetGCECloud ()
912
- framework .ExpectNoError (err , "failed to get GCE cloud provider" )
913
- // Deleting it after it is attached "demotes" it to an
914
- // ephemeral IP, which can be auto-released.
915
- if err := gceCloud .DeleteRegionAddress (staticIPName , gceCloud .Region ()); err != nil {
916
- framework .Failf ("failed to release static IP %s: %v" , staticIPName , err )
917
- }
918
- staticIPName = ""
919
- }
920
- }
921
-
922
643
ginkgo .By ("hitting the TCP service's LoadBalancer" )
923
644
e2eservice .TestReachableHTTP (ctx , tcpIngressIP , svcPort , loadBalancerLagTimeout )
924
645
0 commit comments