/
external_gateways.go
3424 lines (2958 loc) · 156 KB
/
external_gateways.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package e2e
import (
"context"
"encoding/json"
"fmt"
"net"
"os"
"strconv"
"strings"
"sync"
"time"
"github.com/google/go-cmp/cmp"
nettypes "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/klog"
"k8s.io/kubernetes/test/e2e/framework"
e2ekubectl "k8s.io/kubernetes/test/e2e/framework/kubectl"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
"k8s.io/kubernetes/test/e2e/framework/skipper"
utilnet "k8s.io/utils/net"
)
// This is the image used for the containers acting as externalgateways, built
// out from the e2e/images/Dockerfile.frr dockerfile
const (
externalContainerImage = "quay.io/trozet/ovnkbfdtest:0.3"
srcHTTPPort = 80
srcUDPPort = 90
externalGatewayPodIPsAnnotation = "k8s.ovn.org/external-gw-pod-ips"
defaultPolicyName = "default-route-policy"
anyLink = "any"
)
var externalContainerNetwork = "kind"
var externalContainerIPv4 = ""
var externalContainerIPv6 = ""
func init() {
// When the env variable is specified, we use a different docker network for
// containers acting as external gateways.
// In a specific case where the variable is set to `host` we create only one
// external container to act as an external gateway, as we can't create 2
// because of overlapping ip/ports (like the bfd port).
if exNetwork, found := os.LookupEnv("OVN_TEST_EX_GW_NETWORK"); found {
externalContainerNetwork = exNetwork
}
// When OVN_TEST_EX_GW_NETWORK is set to "host" we need to set the container's IP from outside
if exHostIPv4, found := os.LookupEnv("OVN_TEST_EX_GW_IPV4"); found {
externalContainerIPv4 = exHostIPv4
}
if exHostIPv6, found := os.LookupEnv("OVN_TEST_EX_GW_IPV6"); found {
externalContainerIPv6 = exHostIPv6
}
}
// gatewayTestIPs collects all the addresses required for an external gateway
// test.
type gatewayTestIPs struct {
gatewayIPs []string
srcPodIP string
nodeIP string
targetIPs []string
}
var _ = ginkgo.Describe("External Gateway", func() {
// Validate pods can reach a network running in a container's looback address via
// an external gateway running on eth0 of the container without any tunnel encap.
// Next, the test updates the namespace annotation to point to a second container,
// emulating the ext gateway. This test requires shared gateway mode in the job infra.
var _ = ginkgo.Describe("e2e non-vxlan external gateway and update validation", func() {
const (
svcname string = "multiple-novxlan-externalgw"
ovnNs string = "ovn-kubernetes"
ovnWorkerNode string = "ovn-worker"
ovnContainer string = "ovnkube-node"
gwContainerNameAlt1 string = "gw-novxlan-test-container-alt1"
gwContainerNameAlt2 string = "gw-novxlan-test-container-alt2"
ovnControlNode string = "ovn-control-plane"
)
var (
exGWRemoteIpAlt1 string
exGWRemoteIpAlt2 string
)
f := wrappedTestFramework(svcname)
// Determine what mode the CI is running in and get relevant endpoint information for the tests
ginkgo.BeforeEach(func() {
exGWRemoteIpAlt1 = "10.249.3.1"
exGWRemoteIpAlt2 = "10.249.4.1"
if IsIPv6Cluster(f.ClientSet) {
exGWRemoteIpAlt1 = "fc00:f853:ccd:e793::1"
exGWRemoteIpAlt2 = "fc00:f853:ccd:e794::1"
}
})
ginkgo.AfterEach(func() {
// tear down the containers simulating the gateways
if cid, _ := runCommand(containerRuntime, "ps", "-qaf", fmt.Sprintf("name=%s", gwContainerNameAlt1)); cid != "" {
if _, err := runCommand(containerRuntime, "rm", "-f", gwContainerNameAlt1); err != nil {
framework.Logf("failed to delete the gateway test container %s %v", gwContainerNameAlt1, err)
}
}
if cid, _ := runCommand(containerRuntime, "ps", "-qaf", fmt.Sprintf("name=%s", gwContainerNameAlt2)); cid != "" {
if _, err := runCommand(containerRuntime, "rm", "-f", gwContainerNameAlt2); err != nil {
framework.Logf("failed to delete the gateway test container %s %v", gwContainerNameAlt2, err)
}
}
})
ginkgo.It("Should validate connectivity without vxlan before and after updating the namespace annotation to a new external gateway", func() {
var pingSrc string
var validIP net.IP
isIPv6Cluster := IsIPv6Cluster(f.ClientSet)
srcPingPodName := "e2e-exgw-novxlan-src-ping-pod"
command := []string{"bash", "-c", "sleep 20000"}
testContainer := fmt.Sprintf("%s-container", srcPingPodName)
testContainerFlag := fmt.Sprintf("--container=%s", testContainer)
// non-ha ci mode runs a set of kind nodes prefixed with ovn-worker
ciWorkerNodeSrc := ovnWorkerNode
// start the container that will act as an external gateway
_, err := runCommand(containerRuntime, "run", "-itd", "--privileged", "--network", externalContainerNetwork, "--name", gwContainerNameAlt1, agnhostImage)
if err != nil {
framework.Failf("failed to start external gateway test container %s: %v", gwContainerNameAlt1, err)
}
// retrieve the container ip of the external gateway container
alt1IPv4, alt1IPv6 := getContainerAddressesForNetwork(gwContainerNameAlt1, externalContainerNetwork)
if err != nil {
framework.Failf("failed to start external gateway test container: %v", err)
}
nodeIPv4, nodeIPv6 := getContainerAddressesForNetwork(ciWorkerNodeSrc, externalContainerNetwork)
exGWRemoteCidrAlt1 := fmt.Sprintf("%s/24", exGWRemoteIpAlt1)
exGWRemoteCidrAlt2 := fmt.Sprintf("%s/24", exGWRemoteIpAlt2)
exGWIpAlt1 := alt1IPv4
nodeIP := nodeIPv4
if isIPv6Cluster {
exGWIpAlt1 = alt1IPv6
exGWRemoteCidrAlt1 = fmt.Sprintf("%s/64", exGWRemoteIpAlt1)
exGWRemoteCidrAlt2 = fmt.Sprintf("%s/64", exGWRemoteIpAlt2)
nodeIP = nodeIPv6
}
// annotate the test namespace
annotateArgs := []string{
"annotate",
"namespace",
f.Namespace.Name,
fmt.Sprintf("k8s.ovn.org/routing-external-gws=%s", exGWIpAlt1),
}
framework.Logf("Annotating the external gateway test namespace to a container gw: %s ", exGWIpAlt1)
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, annotateArgs...)
podCIDR, err := getNodePodCIDR(ciWorkerNodeSrc)
if err != nil {
framework.Failf("Error retrieving the pod cidr from %s %v", ciWorkerNodeSrc, err)
}
framework.Logf("the pod cidr for node %s is %s", ciWorkerNodeSrc, podCIDR)
// add loopback interface used to validate all traffic is getting drained through the gateway
_, err = runCommand(containerRuntime, "exec", gwContainerNameAlt1, "ip", "address", "add", exGWRemoteCidrAlt1, "dev", "lo")
if err != nil {
framework.Failf("failed to add the loopback ip to dev lo on the test container: %v", err)
}
// Create the pod that will be used as the source for the connectivity test
createGenericPod(f, srcPingPodName, ciWorkerNodeSrc, f.Namespace.Name, command)
// wait for pod setup to return a valid address
err = wait.PollImmediate(retryInterval, retryTimeout, func() (bool, error) {
pingSrc = getPodAddress(srcPingPodName, f.Namespace.Name)
validIP = net.ParseIP(pingSrc)
if validIP == nil {
return false, nil
}
return true, nil
})
// Fail the test if no address is ever retrieved
if err != nil {
framework.Failf("Error trying to get the pod IP address")
}
// add a host route on the first mock gateway for return traffic to the pod
_, err = runCommand(containerRuntime, "exec", gwContainerNameAlt1, "ip", "route", "add", pingSrc, "via", nodeIP)
if err != nil {
framework.Failf("failed to add the pod host route on the test container: %v", err)
}
_, err = runCommand(containerRuntime, "exec", gwContainerNameAlt1, "ping", "-c", "5", pingSrc)
framework.ExpectNoError(err, "Failed to ping %s from container %s", pingSrc, gwContainerNameAlt1)
time.Sleep(time.Second * 15)
// Verify the gateway and remote address is reachable from the initial pod
ginkgo.By(fmt.Sprintf("Verifying connectivity without vxlan to the updated annotation and initial external gateway %s and remote address %s", exGWIpAlt1, exGWRemoteIpAlt1))
_, err = e2ekubectl.RunKubectl(f.Namespace.Name, "exec", srcPingPodName, testContainerFlag, "--", "ping", "-w", "40", exGWRemoteIpAlt1)
if err != nil {
framework.Failf("Failed to ping the first gateway network %s from container %s on node %s: %v", exGWRemoteIpAlt1, ovnContainer, ovnWorkerNode, err)
}
// start the container that will act as a new external gateway that the tests will be updated to use
_, err = runCommand(containerRuntime, "run", "-itd", "--privileged", "--network", externalContainerNetwork, "--name", gwContainerNameAlt2, agnhostImage)
if err != nil {
framework.Failf("failed to start external gateway test container %s: %v", gwContainerNameAlt2, err)
}
// retrieve the container ip of the external gateway container
alt2IPv4, alt2IPv6 := getContainerAddressesForNetwork(gwContainerNameAlt2, externalContainerNetwork)
exGWIpAlt2 := alt2IPv4
if isIPv6Cluster {
exGWIpAlt2 = alt2IPv6
}
// override the annotation in the test namespace with the new gateway
annotateArgs = []string{
"annotate",
"namespace",
f.Namespace.Name,
fmt.Sprintf("k8s.ovn.org/routing-external-gws=%s", exGWIpAlt2),
"--overwrite",
}
framework.Logf("Annotating the external gateway test namespace to a new container remote IP:%s gw:%s ", exGWIpAlt2, exGWRemoteIpAlt2)
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, annotateArgs...)
// add loopback interface used to validate all traffic is getting drained through the gateway
_, err = runCommand(containerRuntime, "exec", gwContainerNameAlt2, "ip", "address", "add", exGWRemoteCidrAlt2, "dev", "lo")
if err != nil {
framework.Failf("failed to add the loopback ip to dev lo on the test container: %v", err)
}
// add a host route on the second mock gateway for return traffic to the pod
_, err = runCommand(containerRuntime, "exec", gwContainerNameAlt2, "ip", "route", "add", pingSrc, "via", nodeIP)
if err != nil {
framework.Failf("failed to add the pod route on the test container: %v", err)
}
_, err = runCommand(containerRuntime, "exec", gwContainerNameAlt2, "ping", "-c", "5", pingSrc)
framework.ExpectNoError(err, "Failed to ping %s from container %s", pingSrc, gwContainerNameAlt1)
// Verify the updated gateway and remote address is reachable from the initial pod
ginkgo.By(fmt.Sprintf("Verifying connectivity without vxlan to the updated annotation and new external gateway %s and remote IP %s", exGWRemoteIpAlt2, exGWIpAlt2))
_, err = e2ekubectl.RunKubectl(f.Namespace.Name, "exec", srcPingPodName, testContainerFlag, "--", "ping", "-w", "40", exGWRemoteIpAlt2)
if err != nil {
framework.Failf("Failed to ping the second gateway network %s from container %s on node %s: %v", exGWRemoteIpAlt2, ovnContainer, ovnWorkerNode, err)
}
})
})
// This test validates ingress traffic sourced from a mock external gateway
// running as a container. Add a namespace annotated with the IP of the
// mock external container's eth0 address. Add a loopback address and a
// route pointing to the pod in the test namespace. Validate connectivity
// sourcing from the mock gateway container loopback to the test ns pod.
var _ = ginkgo.Describe("e2e ingress gateway traffic validation", func() {
const (
svcname string = "novxlan-externalgw-ingress"
gwContainer string = "gw-ingress-test-container"
)
f := wrappedTestFramework(svcname)
type nodeInfo struct {
name string
nodeIP string
}
var (
workerNodeInfo nodeInfo
IsIPv6 bool
)
ginkgo.BeforeEach(func() {
// retrieve worker node names
nodes, err := e2enode.GetBoundedReadySchedulableNodes(context.TODO(), f.ClientSet, 3)
framework.ExpectNoError(err)
if len(nodes.Items) < 3 {
framework.Failf(
"Test requires >= 3 Ready nodes, but there are only %v nodes",
len(nodes.Items))
}
ips := e2enode.CollectAddresses(nodes, v1.NodeInternalIP)
workerNodeInfo = nodeInfo{
name: nodes.Items[1].Name,
nodeIP: ips[1],
}
IsIPv6 = IsIPv6Cluster(f.ClientSet)
})
ginkgo.AfterEach(func() {
// tear down the container simulating the gateway
if cid, _ := runCommand(containerRuntime, "ps", "-qaf", fmt.Sprintf("name=%s", gwContainer)); cid != "" {
if _, err := runCommand(containerRuntime, "rm", "-f", gwContainer); err != nil {
framework.Logf("failed to delete the gateway test container %s %v", gwContainer, err)
}
}
})
ginkgo.It("Should validate ingress connectivity from an external gateway", func() {
var (
pingDstPod string
dstPingPodName = "e2e-exgw-ingress-ping-pod"
command = []string{"bash", "-c", "sleep 20000"}
exGWLo = "10.30.1.1"
exGWLoCidr = fmt.Sprintf("%s/32", exGWLo)
pingCmd = ipv4PingCommand
pingCount = "3"
)
if IsIPv6 {
exGWLo = "fc00::1" // unique local ipv6 unicast addr as per rfc4193
exGWLoCidr = fmt.Sprintf("%s/64", exGWLo)
pingCmd = ipv6PingCommand
}
// start the first container that will act as an external gateway
_, err := runCommand(containerRuntime, "run", "-itd", "--privileged", "--network", externalContainerNetwork,
"--name", gwContainer, agnhostImage)
if err != nil {
framework.Failf("failed to start external gateway test container %s: %v", gwContainer, err)
}
exGWIp, exGWIpv6 := getContainerAddressesForNetwork(gwContainer, externalContainerNetwork)
if IsIPv6 {
exGWIp = exGWIpv6
}
// annotate the test namespace with the external gateway address
annotateArgs := []string{
"annotate",
"namespace",
f.Namespace.Name,
fmt.Sprintf("k8s.ovn.org/routing-external-gws=%s", exGWIp),
}
framework.Logf("Annotating the external gateway test namespace to container gateway: %s", exGWIp)
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, annotateArgs...)
nodeIP, nodeIPv6 := getContainerAddressesForNetwork(workerNodeInfo.name, externalContainerNetwork)
if IsIPv6 {
nodeIP = nodeIPv6
}
framework.Logf("the pod side node is %s and the source node ip is %s", workerNodeInfo.name, nodeIP)
podCIDR, err := getNodePodCIDR(workerNodeInfo.name)
if err != nil {
framework.Failf("Error retrieving the pod cidr from %s %v", workerNodeInfo.name, err)
}
framework.Logf("the pod cidr for node %s is %s", workerNodeInfo.name, podCIDR)
// Create the pod that will be used as the source for the connectivity test
createGenericPod(f, dstPingPodName, workerNodeInfo.name, f.Namespace.Name, command)
// wait for the pod setup to return a valid address
err = wait.PollImmediate(retryInterval, retryTimeout, func() (bool, error) {
pingDstPod = getPodAddress(dstPingPodName, f.Namespace.Name)
validIP := net.ParseIP(pingDstPod)
if validIP == nil {
return false, nil
}
return true, nil
})
// fail the test if a pod address is never retrieved
if err != nil {
framework.Failf("Error trying to get the pod IP address")
}
// add a host route on the gateway for return traffic to the pod
_, err = runCommand(containerRuntime, "exec", gwContainer, "ip", "route", "add", pingDstPod, "via", nodeIP)
if err != nil {
framework.Failf("failed to add the pod host route on the test container %s: %v", gwContainer, err)
}
// add a loopback address to the mock container that will source the ingress test
_, err = runCommand(containerRuntime, "exec", gwContainer, "ip", "address", "add", exGWLoCidr, "dev", "lo")
if err != nil {
framework.Failf("failed to add the loopback ip to dev lo on the test container: %v", err)
}
// Validate connectivity from the external gateway loopback to the pod in the test namespace
ginkgo.By(fmt.Sprintf("Validate ingress traffic from the external gateway %s can reach the pod in the exgw annotated namespace", gwContainer))
// generate traffic that will verify connectivity from the mock external gateway loopback
_, err = runCommand(containerRuntime, "exec", gwContainer, string(pingCmd), "-c", pingCount, "-I", "eth0", pingDstPod)
if err != nil {
framework.Failf("failed to ping the pod address %s from mock container %s: %v", pingDstPod, gwContainer, err)
}
})
})
var _ = ginkgo.Context("With annotations", func() {
// Validate pods can reach a network running in a container's looback address via
// an external gateway running on eth0 of the container without any tunnel encap.
// The traffic will get proxied through an annotated pod in the serving namespace.
var _ = ginkgo.Describe("e2e non-vxlan external gateway through a gateway pod", func() {
const (
svcname string = "externalgw-pod-novxlan"
gwContainer1 string = "ex-gw-container1"
gwContainer2 string = "ex-gw-container2"
srcPingPodName string = "e2e-exgw-src-ping-pod"
gatewayPodName1 string = "e2e-gateway-pod1"
gatewayPodName2 string = "e2e-gateway-pod2"
externalTCPPort = 91
externalUDPPort = 90
ecmpRetry int = 20
testTimeout string = "20"
)
var (
sleepCommand = []string{"bash", "-c", "sleep 20000"}
addressesv4, addressesv6 gatewayTestIPs
clientSet kubernetes.Interface
servingNamespace string
)
var (
gwContainers []string
)
f := wrappedTestFramework(svcname)
ginkgo.BeforeEach(func() {
clientSet = f.ClientSet // so it can be used in AfterEach
// retrieve worker node names
nodes, err := e2enode.GetBoundedReadySchedulableNodes(context.TODO(), f.ClientSet, 3)
framework.ExpectNoError(err)
if len(nodes.Items) < 3 {
framework.Failf(
"Test requires >= 3 Ready nodes, but there are only %v nodes",
len(nodes.Items))
}
ns, err := f.CreateNamespace(context.TODO(), "exgw-serving", nil)
framework.ExpectNoError(err)
servingNamespace = ns.Name
gwContainers, addressesv4, addressesv6 = setupGatewayContainers(f, nodes, gwContainer1, gwContainer2, srcPingPodName, externalUDPPort, externalTCPPort, ecmpRetry)
setupAnnotatedGatewayPods(f, nodes, gatewayPodName1, gatewayPodName2, servingNamespace, sleepCommand, addressesv4, addressesv6, false)
})
ginkgo.AfterEach(func() {
cleanExGWContainers(clientSet, []string{gwContainer1, gwContainer2}, addressesv4, addressesv6)
resetGatewayAnnotations(f)
})
ginkgo.DescribeTable("Should validate ICMP connectivity to an external gateway's loopback address via a pod with external gateway CR",
func(addresses *gatewayTestIPs, icmpCommand string) {
if addresses.srcPodIP == "" || addresses.nodeIP == "" {
skipper.Skipf("Skipping as pod ip / node ip are not set pod ip %s node ip %s", addresses.srcPodIP, addresses.nodeIP)
}
ginkgo.By(fmt.Sprintf("Verifying connectivity to the pod [%s] from external gateways", addresses.srcPodIP))
for _, gwContainer := range gwContainers {
_, err := runCommand(containerRuntime, "exec", gwContainer, "ping", "-c", testTimeout, addresses.srcPodIP)
framework.ExpectNoError(err, "Failed to ping %s from container %s", addresses.srcPodIP, gwContainer)
}
tcpDumpSync := sync.WaitGroup{}
tcpDumpSync.Add(len(gwContainers))
for _, gwContainer := range gwContainers {
go checkReceivedPacketsOnContainer(gwContainer, srcPingPodName, anyLink, []string{icmpCommand}, &tcpDumpSync)
}
pingSync := sync.WaitGroup{}
// Verify the external gateway loopback address running on the external container is reachable and
// that traffic from the source ping pod is proxied through the pod in the serving namespace
ginkgo.By("Verifying connectivity via the gateway namespace to the remote addresses")
for _, t := range addresses.targetIPs {
pingSync.Add(1)
go func(target string) {
defer ginkgo.GinkgoRecover()
defer pingSync.Done()
_, err := e2ekubectl.RunKubectl(f.Namespace.Name, "exec", srcPingPodName, "--", "ping", "-c", testTimeout, target)
framework.ExpectNoError(err, "Failed to ping remote gateway %s from pod %s", target, srcPingPodName)
}(t)
}
pingSync.Wait()
tcpDumpSync.Wait()
},
ginkgo.Entry("ipv4", &addressesv4, "icmp"),
ginkgo.Entry("ipv6", &addressesv6, "icmp6"))
ginkgo.DescribeTable("Should validate TCP/UDP connectivity to an external gateway's loopback address via a pod with external gateway annotations enabled",
func(protocol string, addresses *gatewayTestIPs, destPort, destPortOnPod int) {
if addresses.srcPodIP == "" || addresses.nodeIP == "" {
skipper.Skipf("Skipping as pod ip / node ip are not set pod ip %s node ip %s", addresses.srcPodIP, addresses.nodeIP)
}
for _, container := range gwContainers {
reachPodFromGateway(addresses.srcPodIP, strconv.Itoa(destPortOnPod), srcPingPodName, container, protocol)
}
expectedHostNames := make(map[string]struct{})
for _, c := range gwContainers {
res, err := runCommand(containerRuntime, "exec", c, "hostname")
framework.ExpectNoError(err, "failed to run hostname in %s", c)
hostname := strings.TrimSuffix(res, "\n")
framework.Logf("Hostname for %s is %s", c, hostname)
expectedHostNames[hostname] = struct{}{}
}
framework.Logf("Expected hostnames are %v", expectedHostNames)
ginkgo.By("Checking that external ips are reachable with both gateways")
returnedHostNames := make(map[string]struct{})
target := addresses.targetIPs[0]
success := false
for i := 0; i < 20; i++ {
args := []string{"exec", srcPingPodName, "--"}
if protocol == "tcp" {
args = append(args, "bash", "-c", fmt.Sprintf("echo | nc -w 1 %s %d", target, destPort))
} else {
args = append(args, "bash", "-c", fmt.Sprintf("echo | nc -w 1 -u %s %d", target, destPort))
}
res, err := e2ekubectl.RunKubectl(f.Namespace.Name, args...)
framework.ExpectNoError(err, "failed to reach %s (%s)", target, protocol)
hostname := strings.TrimSuffix(res, "\n")
if hostname != "" {
returnedHostNames[hostname] = struct{}{}
}
if cmp.Equal(returnedHostNames, expectedHostNames) {
success = true
break
}
}
framework.Logf("Received hostnames for protocol %s are %v ", protocol, returnedHostNames)
if !success {
framework.Failf("Failed to hit all the external gateways via for protocol %s, diff %s", protocol, cmp.Diff(expectedHostNames, returnedHostNames))
}
},
ginkgo.Entry("UDP ipv4", "udp", &addressesv4, externalUDPPort, srcUDPPort),
ginkgo.Entry("TCP ipv4", "tcp", &addressesv4, externalTCPPort, srcHTTPPort),
ginkgo.Entry("UDP ipv6", "udp", &addressesv6, externalUDPPort, srcUDPPort),
ginkgo.Entry("TCP ipv6", "tcp", &addressesv6, externalTCPPort, srcHTTPPort))
})
// Validate pods can reach a network running in multiple container's loopback
// addresses via two external gateways running on eth0 of the container without
// any tunnel encap. This test defines two external gateways and validates ECMP
// functionality to the container loopbacks. To verify traffic reaches the
// gateways, tcpdump is running on the external gateways and will exit successfully
// once an ICMP packet is received from the annotated pod in the k8s cluster.
// Two additional gateways are added to verify the tcp / udp protocols.
// They run the netexec command, and the pod asks to return their hostname.
// The test checks that both hostnames are collected at least once.
var _ = ginkgo.Describe("e2e multiple external gateway validation", func() {
const (
svcname string = "novxlan-externalgw-ecmp"
gwContainer1 string = "gw-test-container1"
gwContainer2 string = "gw-test-container2"
testTimeout string = "30"
ecmpRetry int = 20
srcPodName = "e2e-exgw-src-pod"
externalTCPPort = 80
externalUDPPort = 90
)
f := wrappedTestFramework(svcname)
var gwContainers []string
var addressesv4, addressesv6 gatewayTestIPs
ginkgo.BeforeEach(func() {
// retrieve worker node names
nodes, err := e2enode.GetBoundedReadySchedulableNodes(context.TODO(), f.ClientSet, 3)
framework.ExpectNoError(err)
if len(nodes.Items) < 3 {
framework.Failf(
"Test requires >= 3 Ready nodes, but there are only %v nodes",
len(nodes.Items))
}
if externalContainerNetwork == "host" {
skipper.Skipf("Skipping as host network doesn't support multiple external gateways")
}
gwContainers, addressesv4, addressesv6 = setupGatewayContainers(f, nodes, gwContainer1, gwContainer2, srcPodName, externalUDPPort, externalTCPPort, ecmpRetry)
})
ginkgo.AfterEach(func() {
// tear down the containers simulating the gateways
deleteClusterExternalContainer(gwContainer1)
deleteClusterExternalContainer(gwContainer2)
resetGatewayAnnotations(f)
})
ginkgo.DescribeTable("Should validate ICMP connectivity to multiple external gateways for an ECMP scenario", func(addresses *gatewayTestIPs, icmpToDump string) {
if addresses.srcPodIP == "" || addresses.nodeIP == "" {
skipper.Skipf("Skipping as pod ip / node ip are not set pod ip %s node ip %s", addresses.srcPodIP, addresses.nodeIP)
}
annotateNamespaceForGateway(f.Namespace.Name, false, addresses.gatewayIPs[:]...)
ginkgo.By("Verifying connectivity to the pod from external gateways")
for _, gwContainer := range gwContainers {
_, err := runCommand(containerRuntime, "exec", gwContainer, "ping", "-c", testTimeout, addresses.srcPodIP)
framework.ExpectNoError(err, "Failed to ping %s from container %s", addresses.srcPodIP, gwContainer)
}
ginkgo.By("Verifying connectivity to the pod from external gateways with large packets > pod MTU")
for _, gwContainer := range gwContainers {
_, err := runCommand(containerRuntime, "exec", gwContainer, "ping", "-s", "1420", "-c", testTimeout, addresses.srcPodIP)
framework.ExpectNoError(err, "Failed to ping %s from container %s", addresses.srcPodIP, gwContainer)
}
// Verify the gateways and remote loopback addresses are reachable from the pod.
// Iterate checking connectivity to the loopbacks on the gateways until tcpdump see
// the traffic or 20 attempts fail. Odds of a false negative here is ~ (1/2)^20
ginkgo.By("Verifying ecmp connectivity to the external gateways by iterating through the targets")
// Check for egress traffic to both gateway loopback addresses using tcpdump, since
// /proc/net/dev counters only record the ingress interface traffic is received on.
// The test will waits until an ICMP packet is matched on the gateways or fail the
// test if a packet to the loopback is not received within the timer interval.
// If an ICMP packet is never detected, return the error via the specified chanel.
tcpDumpSync := sync.WaitGroup{}
tcpDumpSync.Add(len(gwContainers))
for _, gwContainer := range gwContainers {
go checkReceivedPacketsOnContainer(gwContainer, srcPodName, anyLink, []string{icmpToDump}, &tcpDumpSync)
}
pingSync := sync.WaitGroup{}
// spawn a goroutine to asynchronously (to speed up the test)
// to ping the gateway loopbacks on both containers via ECMP.
for _, address := range addresses.targetIPs {
pingSync.Add(1)
go func(target string) {
defer ginkgo.GinkgoRecover()
defer pingSync.Done()
_, err := e2ekubectl.RunKubectl(f.Namespace.Name, "exec", srcPodName, "--", "ping", "-c", testTimeout, target)
if err != nil {
framework.Logf("error generating a ping from the test pod %s: %v", srcPodName, err)
}
}(address)
}
pingSync.Wait()
tcpDumpSync.Wait()
}, ginkgo.Entry("IPV4", &addressesv4, "icmp"),
ginkgo.Entry("IPV6", &addressesv6, "icmp6"))
// This test runs a listener on the external container, returning the host name both on tcp and udp.
// The src pod tries to hit the remote address until both the containers are hit.
ginkgo.DescribeTable("Should validate TCP/UDP connectivity to multiple external gateways for a UDP / TCP scenario", func(addresses *gatewayTestIPs, protocol string, destPort, destPortOnPod int) {
if addresses.srcPodIP == "" || addresses.nodeIP == "" {
skipper.Skipf("Skipping as pod ip / node ip are not set pod ip %s node ip %s", addresses.srcPodIP, addresses.nodeIP)
}
annotateNamespaceForGateway(f.Namespace.Name, false, addresses.gatewayIPs[:]...)
for _, container := range gwContainers {
reachPodFromGateway(addresses.srcPodIP, strconv.Itoa(destPortOnPod), srcPodName, container, protocol)
}
expectedHostNames := hostNamesForContainers(gwContainers)
framework.Logf("Expected hostnames are %v", expectedHostNames)
returnedHostNames := make(map[string]struct{})
success := false
// Picking only the first address, the one the udp listener is set for
target := addresses.targetIPs[0]
for i := 0; i < 20; i++ {
hostname := pokeHostnameViaNC(srcPodName, f.Namespace.Name, protocol, target, destPort)
if hostname != "" {
returnedHostNames[hostname] = struct{}{}
}
if cmp.Equal(returnedHostNames, expectedHostNames) {
success = true
break
}
}
framework.Logf("Received hostnames for protocol %s are %v ", protocol, returnedHostNames)
if !success {
framework.Failf("Failed to hit all the external gateways via for protocol %s, diff %s", protocol, cmp.Diff(expectedHostNames, returnedHostNames))
}
}, ginkgo.Entry("IPV4 udp", &addressesv4, "udp", externalUDPPort, srcUDPPort),
ginkgo.Entry("IPV4 tcp", &addressesv4, "tcp", externalTCPPort, srcHTTPPort),
ginkgo.Entry("IPV6 udp", &addressesv6, "udp", externalUDPPort, srcUDPPort),
ginkgo.Entry("IPV6 tcp", &addressesv6, "tcp", externalTCPPort, srcHTTPPort))
})
var _ = ginkgo.Describe("e2e multiple external gateway stale conntrack entry deletion validation", func() {
const (
svcname string = "novxlan-externalgw-ecmp"
gwContainer1 string = "gw-test-container1"
gwContainer2 string = "gw-test-container2"
srcPodName string = "e2e-exgw-src-pod"
gatewayPodName1 string = "e2e-gateway-pod1"
gatewayPodName2 string = "e2e-gateway-pod2"
)
var (
servingNamespace string
)
f := wrappedTestFramework(svcname)
var (
addressesv4, addressesv6 gatewayTestIPs
sleepCommand []string
nodes *v1.NodeList
err error
clientSet kubernetes.Interface
)
ginkgo.BeforeEach(func() {
clientSet = f.ClientSet // so it can be used in AfterEach
// retrieve worker node names
nodes, err = e2enode.GetBoundedReadySchedulableNodes(context.TODO(), clientSet, 3)
framework.ExpectNoError(err)
if len(nodes.Items) < 3 {
framework.Failf(
"Test requires >= 3 Ready nodes, but there are only %v nodes",
len(nodes.Items))
}
if externalContainerNetwork == "host" {
skipper.Skipf("Skipping as host network doesn't support multiple external gateways")
}
ns, err := f.CreateNamespace(context.TODO(), "exgw-conntrack-serving", nil)
framework.ExpectNoError(err)
servingNamespace = ns.Name
addressesv4, addressesv6 = setupGatewayContainersForConntrackTest(f, nodes, gwContainer1, gwContainer2, srcPodName)
sleepCommand = []string{"bash", "-c", "sleep 20000"}
_, err = createGenericPod(f, gatewayPodName1, nodes.Items[0].Name, servingNamespace, sleepCommand)
framework.ExpectNoError(err, "Create and annotate the external gw pods to manage the src app pod namespace, failed: %v", err)
_, err = createGenericPod(f, gatewayPodName2, nodes.Items[1].Name, servingNamespace, sleepCommand)
framework.ExpectNoError(err, "Create and annotate the external gw pods to manage the src app pod namespace, failed: %v", err)
})
ginkgo.AfterEach(func() {
// tear down the containers and pods simulating the gateways
ginkgo.By("Deleting the gateway containers")
deleteClusterExternalContainer(gwContainer1)
deleteClusterExternalContainer(gwContainer2)
resetGatewayAnnotations(f)
})
ginkgo.DescribeTable("Namespace annotation: Should validate conntrack entry deletion for TCP/UDP traffic via multiple external gateways a.k.a ECMP routes", func(addresses *gatewayTestIPs, protocol string) {
if addresses.srcPodIP == "" || addresses.nodeIP == "" {
skipper.Skipf("Skipping as pod ip / node ip are not set pod ip %s node ip %s", addresses.srcPodIP, addresses.nodeIP)
}
ginkgo.By("Annotate the app namespace to get managed by external gateways")
annotateNamespaceForGateway(f.Namespace.Name, false, addresses.gatewayIPs...)
setupIperf3Client := func(container, address string, port int) {
// note iperf3 even when using udp also spawns tcp connection first; so we indirectly also have the tcp connection when using "-u" flag
cmd := []string{containerRuntime, "exec", container, "iperf3", "-u", "-c", address, "-p", fmt.Sprintf("%d", port), "-b", "1M", "-i", "1", "-t", "3", "&"}
_, err := runCommand(cmd...)
framework.ExpectNoError(err, "failed to setup iperf3 client for %s", container)
}
macAddressGW := make([]string, 2)
for i, containerName := range []string{gwContainer1, gwContainer2} {
ginkgo.By("Start iperf3 client from external container to connect to iperf3 server running at the src pod")
setupIperf3Client(containerName, addresses.srcPodIP, 5201+i)
macAddressExtGW, err := net.ParseMAC(getMACAddressesForNetwork(containerName, externalContainerNetwork))
framework.ExpectNoError(err, "failed to parse MAC address for %s", containerName)
// Trim leading 0s because conntrack dumped labels are just integers
// in hex without leading 0s.
macAddressGW[i] = strings.TrimLeft(strings.Replace(macAddressExtGW.String(), ":", "", -1), "0")
}
ginkgo.By("Check if conntrack entries for ECMP routes are created for the 2 external gateways")
nodeName := getPod(f, srcPodName).Spec.NodeName
podConnEntriesWithMACLabelsSet := pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, macAddressGW)
gomega.Expect(podConnEntriesWithMACLabelsSet).To(gomega.Equal(2))
totalPodConnEntries := pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, nil)
gomega.Expect(totalPodConnEntries).To(gomega.Equal(6)) // total conntrack entries for this pod/protocol
ginkgo.By("Remove second external gateway IP from the app namespace annotation")
annotateNamespaceForGateway(f.Namespace.Name, false, addresses.gatewayIPs[0])
ginkgo.By("Check if conntrack entries for ECMP routes are removed for the deleted external gateway if traffic is UDP")
podConnEntriesWithMACLabelsSet = pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, macAddressGW)
totalPodConnEntries = pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, nil)
gomega.Expect(podConnEntriesWithMACLabelsSet).To(gomega.Equal(1)) // we still have the conntrack entry for the remaining gateway
gomega.Expect(totalPodConnEntries).To(gomega.Equal(5)) // 6-1
ginkgo.By("Remove first external gateway IP from the app namespace annotation")
annotateNamespaceForGateway(f.Namespace.Name, false, "")
ginkgo.By("Check if conntrack entries for ECMP routes are removed for the deleted external gateway if traffic is UDP")
podConnEntriesWithMACLabelsSet = pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, macAddressGW)
totalPodConnEntries = pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, nil)
gomega.Expect(podConnEntriesWithMACLabelsSet).To(gomega.Equal(0)) // we don't have any remaining gateways left
gomega.Expect(totalPodConnEntries).To(gomega.Equal(4)) // 6-2
},
ginkgo.Entry("IPV4 udp", &addressesv4, "udp"),
ginkgo.Entry("IPV4 tcp", &addressesv4, "tcp"),
ginkgo.Entry("IPV6 udp", &addressesv6, "udp"),
ginkgo.Entry("IPV6 tcp", &addressesv6, "tcp"))
ginkgo.DescribeTable("ExternalGWPod annotation: Should validate conntrack entry deletion for TCP/UDP traffic via multiple external gateways a.k.a ECMP routes", func(addresses *gatewayTestIPs, protocol string) {
if addresses.srcPodIP == "" || addresses.nodeIP == "" {
skipper.Skipf("Skipping as pod ip / node ip are not set pod ip %s node ip %s", addresses.srcPodIP, addresses.nodeIP)
}
ginkgo.By("Annotate the external gw pods to manage the src app pod namespace")
for i, gwPod := range []string{gatewayPodName1, gatewayPodName2} {
networkIPs := fmt.Sprintf("\"%s\"", addresses.gatewayIPs[i])
if addresses.srcPodIP != "" && addresses.nodeIP != "" {
networkIPs = fmt.Sprintf("\"%s\", \"%s\"", addresses.gatewayIPs[i], addresses.gatewayIPs[i])
}
annotatePodForGateway(gwPod, servingNamespace, f.Namespace.Name, networkIPs, false)
}
// ensure the conntrack deletion tracker annotation is updated
if !isInterconnectEnabled() {
ginkgo.By("Check if the k8s.ovn.org/external-gw-pod-ips got updated for the app namespace")
err := wait.PollImmediate(retryInterval, retryTimeout, func() (bool, error) {
ns := getNamespace(f, f.Namespace.Name)
return (ns.Annotations[externalGatewayPodIPsAnnotation] == fmt.Sprintf("%s,%s", addresses.gatewayIPs[0], addresses.gatewayIPs[1])), nil
})
framework.ExpectNoError(err, "Check if the k8s.ovn.org/external-gw-pod-ips got updated, failed: %v", err)
}
setupIperf3Client := func(container, address string, port int) {
// note iperf3 even when using udp also spawns tcp connection first; so we indirectly also have the tcp connection when using "-u" flag
cmd := []string{containerRuntime, "exec", container, "iperf3", "-u", "-c", address, "-p", fmt.Sprintf("%d", port), "-b", "1M", "-i", "1", "-t", "3", "&"}
_, err := runCommand(cmd...)
framework.ExpectNoError(err, "failed to setup iperf3 client for %s", container)
}
macAddressGW := make([]string, 2)
for i, containerName := range []string{gwContainer1, gwContainer2} {
ginkgo.By("Start iperf3 client from external container to connect to iperf3 server running at the src pod")
setupIperf3Client(containerName, addresses.srcPodIP, 5201+i)
macAddressExtGW, err := net.ParseMAC(getMACAddressesForNetwork(containerName, externalContainerNetwork))
framework.ExpectNoError(err, "failed to parse MAC address for %s", containerName)
// Trim leading 0s because conntrack dumped labels are just integers
// in hex without leading 0s.
macAddressGW[i] = strings.TrimLeft(strings.Replace(macAddressExtGW.String(), ":", "", -1), "0")
}
ginkgo.By("Check if conntrack entries for ECMP routes are created for the 2 external gateways")
nodeName := getPod(f, srcPodName).Spec.NodeName
podConnEntriesWithMACLabelsSet := pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, macAddressGW)
gomega.Expect(podConnEntriesWithMACLabelsSet).To(gomega.Equal(2))
totalPodConnEntries := pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, nil)
gomega.Expect(totalPodConnEntries).To(gomega.Equal(6)) // total conntrack entries for this pod/protocol
ginkgo.By("Remove second external gateway pod's routing-namespace annotation")
annotatePodForGateway(gatewayPodName2, servingNamespace, "", addresses.gatewayIPs[1], false)
// ensure the conntrack deletion tracker annotation is updated
if !isInterconnectEnabled() {
ginkgo.By("Check if the k8s.ovn.org/external-gw-pod-ips got updated for the app namespace")
err = wait.PollImmediate(retryInterval, retryTimeout, func() (bool, error) {
ns := getNamespace(f, f.Namespace.Name)
return (ns.Annotations[externalGatewayPodIPsAnnotation] == addresses.gatewayIPs[0]), nil
})
framework.ExpectNoError(err, "Check if the k8s.ovn.org/external-gw-pod-ips got updated, failed: %v", err)
}
ginkgo.By("Check if conntrack entries for ECMP routes are removed for the deleted external gateway if traffic is UDP")
podConnEntriesWithMACLabelsSet = pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, macAddressGW)
totalPodConnEntries = pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, nil)
gomega.Expect(podConnEntriesWithMACLabelsSet).To(gomega.Equal(1)) // we still have the conntrack entry for the remaining gateway
gomega.Expect(totalPodConnEntries).To(gomega.Equal(5)) // 6-1
ginkgo.By("Remove first external gateway pod's routing-namespace annotation")
annotatePodForGateway(gatewayPodName1, servingNamespace, "", addresses.gatewayIPs[0], false)
// ensure the conntrack deletion tracker annotation is updated
if !isInterconnectEnabled() {
ginkgo.By("Check if the k8s.ovn.org/external-gw-pod-ips got updated for the app namespace")
err = wait.PollImmediate(retryInterval, retryTimeout, func() (bool, error) {
ns := getNamespace(f, f.Namespace.Name)
return (ns.Annotations[externalGatewayPodIPsAnnotation] == ""), nil
})
framework.ExpectNoError(err, "Check if the k8s.ovn.org/external-gw-pod-ips got updated, failed: %v", err)
}
ginkgo.By("Check if conntrack entries for ECMP routes are removed for the deleted external gateway if traffic is UDP")
podConnEntriesWithMACLabelsSet = pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, macAddressGW)
totalPodConnEntries = pokeConntrackEntries(nodeName, addresses.srcPodIP, protocol, nil)
gomega.Expect(podConnEntriesWithMACLabelsSet).To(gomega.Equal(0)) // we don't have any remaining gateways left
gomega.Expect(totalPodConnEntries).To(gomega.Equal(4)) // 6-2
},
ginkgo.Entry("IPV4 udp", &addressesv4, "udp"),
ginkgo.Entry("IPV4 tcp", &addressesv4, "tcp"),
ginkgo.Entry("IPV6 udp", &addressesv6, "udp"),
ginkgo.Entry("IPV6 tcp", &addressesv6, "tcp"))
})
// BFD Tests are dual of external gateway. The only difference is that they enable BFD on ovn and
// on the external containers, and after doing one round veryfing that the traffic reaches both containers,
// they delete one and verify that the traffic is always reaching the only alive container.
var _ = ginkgo.Context("BFD", func() {
var _ = ginkgo.Describe("e2e non-vxlan external gateway through an annotated gateway pod", func() {
const (
svcname string = "externalgw-pod-novxlan"
gwContainer1 string = "ex-gw-container1"
gwContainer2 string = "ex-gw-container2"
srcPingPodName string = "e2e-exgw-src-ping-pod"
gatewayPodName1 string = "e2e-gateway-pod1"
gatewayPodName2 string = "e2e-gateway-pod2"
externalTCPPort = 91
externalUDPPort = 90
ecmpRetry int = 20
testTimeout string = "20"
defaultPolicyName = "default-route-policy"
)
var (
sleepCommand = []string{"bash", "-c", "sleep 20000"}
addressesv4, addressesv6 gatewayTestIPs
clientSet kubernetes.Interface
servingNamespace string
)
var (
gwContainers []string
)
f := wrappedTestFramework(svcname)
ginkgo.BeforeEach(func() {
clientSet = f.ClientSet // so it can be used in AfterEach
// retrieve worker node names
nodes, err := e2enode.GetBoundedReadySchedulableNodes(context.TODO(), f.ClientSet, 3)
framework.ExpectNoError(err)
if len(nodes.Items) < 3 {
framework.Failf(
"Test requires >= 3 Ready nodes, but there are only %v nodes",
len(nodes.Items))
}
ns, err := f.CreateNamespace(context.TODO(), "exgw-bfd-serving", nil)
framework.ExpectNoError(err)
servingNamespace = ns.Name
setupBFD := setupBFDOnContainer(nodes.Items)
gwContainers, addressesv4, addressesv6 = setupGatewayContainers(f, nodes, gwContainer1, gwContainer2, srcPingPodName, externalUDPPort, externalTCPPort, ecmpRetry, setupBFD)
setupAnnotatedGatewayPods(f, nodes, gatewayPodName1, gatewayPodName2, servingNamespace, sleepCommand, addressesv4, addressesv6, true)
})
ginkgo.AfterEach(func() {
cleanExGWContainers(clientSet, []string{gwContainer1, gwContainer2}, addressesv4, addressesv6)
resetGatewayAnnotations(f)
})
ginkgo.DescribeTable("Should validate ICMP connectivity to an external gateway's loopback address via a pod with external gateway annotations enabled",
func(addresses *gatewayTestIPs, icmpCommand string) {
if addresses.srcPodIP == "" || addresses.nodeIP == "" {
skipper.Skipf("Skipping as pod ip / node ip are not set pod ip %s node ip %s", addresses.srcPodIP, addresses.nodeIP)
}
ginkgo.By("Verifying connectivity to the pod from external gateways")
for _, gwContainer := range gwContainers {
_, err := runCommand(containerRuntime, "exec", gwContainer, "ping", "-c", testTimeout, addresses.srcPodIP)
framework.ExpectNoError(err, "Failed to ping %s from container %s", addresses.srcPodIP, gwContainer)
}
// This is needed for bfd to sync up
time.Sleep(3 * time.Second)
for _, gwContainer := range gwContainers {
gomega.Expect(isBFDPaired(gwContainer, addresses.nodeIP)).To(gomega.Equal(true), "Bfd not paired")
}
tcpDumpSync := sync.WaitGroup{}
tcpDumpSync.Add(len(gwContainers))
for _, gwContainer := range gwContainers {
go checkReceivedPacketsOnContainer(gwContainer, srcPingPodName, anyLink, []string{icmpCommand}, &tcpDumpSync)
}
// Verify the external gateway loopback address running on the external container is reachable and
// that traffic from the source ping pod is proxied through the pod in the serving namespace
ginkgo.By("Verifying connectivity via the gateway namespace to the remote addresses")
pingSync := sync.WaitGroup{}
// spawn a goroutine to asynchronously (to speed up the test)
// to ping the gateway loopbacks on both containers via ECMP.
for _, address := range addresses.targetIPs {
pingSync.Add(1)
go func(target string) {
defer ginkgo.GinkgoRecover()
defer pingSync.Done()
_, err := e2ekubectl.RunKubectl(f.Namespace.Name, "exec", srcPingPodName, "--", "ping", "-c", testTimeout, target)
if err != nil {
framework.Logf("error generating a ping from the test pod %s: %v", srcPingPodName, err)
}
}(address)
}
pingSync.Wait()
tcpDumpSync.Wait()