/
k8s_util.go
1134 lines (1045 loc) · 44 KB
/
k8s_util.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
// Copyright 2020 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package e2e
import (
"context"
"fmt"
"strings"
"sync"
"time"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
v1net "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1"
crdv1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2"
crdv1alpha3 "antrea.io/antrea/pkg/apis/crd/v1alpha3"
"antrea.io/antrea/test/e2e/utils"
)
type KubernetesUtils struct {
*TestData
podCache map[string][]v1.Pod
podLock sync.Mutex
}
func NewKubernetesUtils(data *TestData) (*KubernetesUtils, error) {
return &KubernetesUtils{
TestData: data,
podCache: map[string][]v1.Pod{},
}, nil
}
// TestCase is a collection of TestSteps to be tested against.
type TestCase struct {
Name string
Steps []*TestStep
}
// TestStep is a single unit of testing spec. It includes the policy specs that need to be
// applied for this test, the port to test traffic on and the expected Reachability matrix.
type TestStep struct {
Name string
Reachability *Reachability
TestResources []metav1.Object
Ports []int32
Protocol utils.AntreaPolicyProtocol
Duration time.Duration
CustomProbes []*CustomProbe
}
// CustomProbe will spin up (or update) SourcePod and DestPod such that Add event of Pods
// can be tested against expected connectivity among those Pods.
type CustomProbe struct {
// Create or update a source Pod.
SourcePod CustomPod
// Create or update a destination Pod.
DestPod CustomPod
// Port on which the probe will be made.
Port int32
// Set the expected connectivity.
ExpectConnectivity PodConnectivityMark
}
// GetPodByLabel returns a Pod with the matching Namespace and "pod" label.
func (k *KubernetesUtils) GetPodByLabel(ns string, name string) (*v1.Pod, error) {
pods, err := k.getPodsUncached(ns, "pod", name)
if err != nil || len(pods) == 0 {
return nil, errors.WithMessagef(err, "unable to get Pod in Namespace %s with label pod=%s", ns, name)
}
return &pods[0], nil
}
func (k *KubernetesUtils) getPodsUncached(ns string, key, val string) ([]v1.Pod, error) {
v1PodList, err := k.clientset.CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{
LabelSelector: fmt.Sprintf("%v=%v", key, val),
})
if err != nil {
return nil, errors.WithMessage(err, "unable to list pods")
}
return v1PodList.Items, nil
}
// GetPodsByLabel returns an array of all Pods in the given Namespace having a k/v label pair.
func (k *KubernetesUtils) GetPodsByLabel(ns string, key string, val string) ([]v1.Pod, error) {
k.podLock.Lock()
defer k.podLock.Unlock()
if p, ok := k.podCache[fmt.Sprintf("%v_%v_%v", ns, key, val)]; ok {
return p, nil
}
v1PodList, err := k.getPodsUncached(ns, key, val)
if err != nil {
return nil, errors.WithMessage(err, "unable to list pods")
}
k.podCache[fmt.Sprintf("%v_%v_%v", ns, key, val)] = v1PodList
return v1PodList, nil
}
func (k *KubernetesUtils) LabelPod(ns, name, key, value string) (*v1.Pod, error) {
pod, err := k.clientset.CoreV1().Pods(ns).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
pod.Labels[key] = value
return k.clientset.CoreV1().Pods(ns).Update(context.TODO(), pod, metav1.UpdateOptions{})
}
func (k *KubernetesUtils) probe(
pod *v1.Pod,
podName string,
containerName string,
dstAddr string,
dstName string,
port int32,
protocol utils.AntreaPolicyProtocol,
) PodConnectivityMark {
protocolStr := map[utils.AntreaPolicyProtocol]string{
utils.ProtocolTCP: "tcp",
utils.ProtocolUDP: "udp",
utils.ProtocolSCTP: "sctp",
}
// We try to connect 3 times. This dates back to when we were using the OVS netdev datapath
// for Kind clusters, as the first packet sent on a tunnel was always dropped
// (https://github.com/antrea-io/antrea/issues/467). We may be able to revisit this now that
// we use the OVS kernel datapath for Kind.
cmd := []string{
"/bin/sh",
"-c",
fmt.Sprintf("for i in $(seq 1 3); do /agnhost connect %s:%d --timeout=1s --protocol=%s; done;", dstAddr, port, protocolStr[protocol]),
}
log.Tracef("Running: kubectl exec %s -c %s -n %s -- %s", pod.Name, containerName, pod.Namespace, strings.Join(cmd, " "))
stdout, stderr, err := k.RunCommandFromPod(pod.Namespace, pod.Name, containerName, cmd)
// It needs to check both err and stderr because:
// 1. The probe tried 3 times. If it checks err only, failure+failure+success would be considered connected.
// 2. There might be an issue in Pod exec API that it sometimes doesn't return error when the probe fails. See #2394.
if err != nil || stderr != "" {
// log this error as trace since may be an expected failure
log.Tracef("%s -> %s: error when running command: err - %v /// stdout - %s /// stderr - %s", podName, dstName, err, stdout, stderr)
// If err != nil and stderr == "", then it means this probe failed because of
// the command instead of connectivity. For example, container name doesn't exist.
if stderr == "" {
return Error
}
return DecideProbeResult(stderr, 3)
}
return Connected
}
// DecideProbeResult uses the probe stderr to decide the connectivity.
func DecideProbeResult(stderr string, probeNum int) PodConnectivityMark {
countConnected := probeNum - strings.Count(stderr, "\n")
countDropped := strings.Count(stderr, "TIMEOUT")
// For our UDP rejection cases, agnhost will return:
// For IPv4: 'UNKNOWN: read udp [src]->[dst]: read: no route to host'
// For IPv6: 'UNKNOWN: read udp [src]->[dst]: read: permission denied'
// To avoid incorrect identification, we use 'no route to host' and
// `permission denied`, instead of 'UNKNOWN' as key string.
// For our other protocols rejection cases, agnhost will return 'REFUSED'.
countRejected := strings.Count(stderr, "REFUSED") + strings.Count(stderr, "no route to host") + strings.Count(stderr, "permission denied")
if countRejected == 0 && countConnected > 0 {
return Connected
}
if countConnected == 0 && countRejected > 0 {
return Rejected
}
if countDropped == probeNum {
return Dropped
}
return Error
}
func (k *KubernetesUtils) pingProbe(
pod *v1.Pod,
podName string,
containerName string,
dstAddr string,
dstName string,
) PodConnectivityMark {
pingCmd := fmt.Sprintf("ping -4 -c 3 -W 1 %s", dstAddr)
if strings.Contains(dstAddr, ":") {
pingCmd = fmt.Sprintf("ping -6 -c 3 -W 1 %s", dstAddr)
}
cmd := []string{
"/bin/sh",
"-c",
pingCmd,
}
log.Tracef("Running: kubectl exec %s -c %s -n %s -- %s", pod.Name, containerName, pod.Namespace, strings.Join(cmd, " "))
stdout, stderr, err := k.RunCommandFromPod(pod.Namespace, pod.Name, containerName, cmd)
log.Tracef("%s -> %s: error when running command: err - %v /// stdout - %s /// stderr - %s", podName, dstName, err, stdout, stderr)
return DecidePingProbeResult(stdout, 3)
}
// DecidePingProbeResult uses the pingProbe stdout to decide the connectivity.
func DecidePingProbeResult(stdout string, probeNum int) PodConnectivityMark {
// Provide stdout example for different connectivity:
// ================== Connected stdout ==================
// PING 10.10.1.2 (10.10.1.2) 56(84) bytes of data.
// 64 bytes from 10.10.1.2: icmp_seq=1 ttl=64 time=0.695 ms
// 64 bytes from 10.10.1.2: icmp_seq=2 ttl=64 time=0.250 ms
// 64 bytes from 10.10.1.2: icmp_seq=3 ttl=64 time=0.058 ms
//
// --- 10.10.1.2 ping statistics ---
// 3 packets transmitted, 3 received, 0% packet loss, time 2043ms
// rtt min/avg/max/mdev = 0.058/0.334/0.695/0.266 ms
// ======================================================
// =================== Dropped stdout ===================
// PING 10.10.1.2 (10.10.1.2) 56(84) bytes of data.
//
// --- 10.10.1.2 ping statistics ---
// 3 packets transmitted, 0 received, 100% packet loss, time 2037ms
// =======================================================
// =================== Rejected stdout ===================
// PING 10.10.1.2 (10.10.1.2) 56(84) bytes of data.
// From 10.10.1.2 icmp_seq=1 Destination Host Prohibited
// From 10.10.1.2 icmp_seq=2 Destination Host Prohibited
// From 10.10.1.2 icmp_seq=3 Destination Host Prohibited
//
// --- 10.10.1.2 ping statistics ---
// 3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2042ms
// =======================================================
// =================== Rejected ICMPv6 stdout ===================
// PING fd02:0:0:f8::11(fd02:0:0:f8::11) 56 data bytes
// From fd02:0:0:f8::11 icmp_seq=1 Destination unreachable: Administratively prohibited
// From fd02:0:0:f8::11 icmp_seq=2 Destination unreachable: Administratively prohibited
// From fd02:0:0:f8::11 icmp_seq=3 Destination unreachable: Administratively prohibited
//
// --- fd02:0:0:f8::11 ping statistics ---
// 3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2047ms
// =======================================================
countConnected := strings.Count(stdout, "bytes from")
countRejected := strings.Count(stdout, "Prohibited") + strings.Count(stdout, "prohibited")
countDropped := probeNum - strings.Count(stdout, "icmp_seq")
if countRejected == 0 && countConnected > 0 {
return Connected
}
if countConnected == 0 && countRejected > 0 {
return Rejected
}
if countDropped == probeNum {
return Dropped
}
return Error
}
// Probe execs into a Pod and checks its connectivity to another Pod. Of course it
// assumes that the target Pod is serving on the input port, and also that agnhost
// is installed. The connectivity from source Pod to all IPs of the target Pod
// should be consistent. Otherwise, Error PodConnectivityMark will be returned.
func (k *KubernetesUtils) Probe(ns1, pod1, ns2, pod2 string, port int32, protocol utils.AntreaPolicyProtocol) (PodConnectivityMark, error) {
fromPods, err := k.GetPodsByLabel(ns1, "pod", pod1)
if err != nil {
return Error, fmt.Errorf("unable to get Pods from Namespace %s: %v", ns1, err)
}
if len(fromPods) == 0 {
return Error, fmt.Errorf("no Pod of label pod=%s in Namespace %s found", pod1, ns1)
}
fromPod := fromPods[0]
toPods, err := k.GetPodsByLabel(ns2, "pod", pod2)
if err != nil {
return Error, fmt.Errorf("unable to get Pods from Namespace %s: %v", ns2, err)
}
if len(toPods) == 0 {
return Error, fmt.Errorf("no Pod of label pod=%s in Namespace %s found", pod2, ns2)
}
toPod := toPods[0]
// Both IPv4 and IPv6 address should be tested.
connectivity := Unknown
for _, eachIP := range toPod.Status.PodIPs {
toIP := eachIP.IP
// If it's an IPv6 address, add "[]" around it.
if strings.Contains(toIP, ":") {
toIP = fmt.Sprintf("[%s]", toIP)
}
// HACK: inferring container name as c80, c81, etc, for simplicity.
containerName := fmt.Sprintf("c%v", port)
curConnectivity := k.probe(&fromPod, fmt.Sprintf("%s/%s", ns1, pod1), containerName, toIP, fmt.Sprintf("%s/%s", ns2, pod2), port, protocol)
if connectivity == Unknown {
connectivity = curConnectivity
} else if connectivity != curConnectivity {
return Error, nil
}
}
return connectivity, nil
}
// ProbeAddr execs into a Pod and checks its connectivity to an arbitrary destination
// address.
func (k *KubernetesUtils) ProbeAddr(ns, podLabelKey, podLabelValue, dstAddr string, port int32, protocol utils.AntreaPolicyProtocol) (PodConnectivityMark, error) {
fromPods, err := k.GetPodsByLabel(ns, podLabelKey, podLabelValue)
if err != nil {
return Error, fmt.Errorf("unable to get Pods from Namespace %s: %v", ns, err)
}
if len(fromPods) == 0 {
return Error, fmt.Errorf("no Pod of label podLabelKey=%s podLabelValue=%s in Namespace %s found", podLabelKey, podLabelValue, ns)
}
fromPod := fromPods[0]
containerName := fromPod.Spec.Containers[0].Name
var connectivity PodConnectivityMark
if protocol == utils.ProtocolICMP {
connectivity = k.pingProbe(&fromPod, fmt.Sprintf("%s/%s", ns, podLabelValue), containerName, dstAddr, dstAddr)
} else {
// If it's an IPv6 address, add "[]" around it.
if strings.Contains(dstAddr, ":") {
dstAddr = fmt.Sprintf("[%s]", dstAddr)
}
connectivity = k.probe(&fromPod, fmt.Sprintf("%s/%s", ns, podLabelValue), containerName, dstAddr, dstAddr, port, protocol)
}
return connectivity, nil
}
// CreateOrUpdateNamespace is a convenience function for idempotent setup of Namespaces
func (data *TestData) CreateOrUpdateNamespace(n string, labels map[string]string) (*v1.Namespace, error) {
ns := &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: n,
Labels: labels,
},
}
nsr, err := data.clientset.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{})
if err == nil {
log.Infof("Created Namespace %s", n)
return nsr, nil
}
log.Debugf("Unable to create Namespace %s, let's try updating it instead (error: %s)", ns.Name, err)
nsr, err = data.clientset.CoreV1().Namespaces().Update(context.TODO(), ns, metav1.UpdateOptions{})
if err != nil {
log.Debugf("Unable to update Namespace %s: %s", ns, err)
}
return nsr, err
}
// CreateOrUpdateDeployment is a convenience function for idempotent setup of deployments
func (data *TestData) CreateOrUpdateDeployment(ns, deploymentName string, replicas int32, labels map[string]string) (*appsv1.Deployment, error) {
zero := int64(0)
log.Infof("Creating/updating Deployment '%s/%s'", ns, deploymentName)
makeContainerSpec := func(port int32, protocol v1.Protocol) v1.Container {
var args []string
switch protocol {
case v1.ProtocolTCP:
args = []string{fmt.Sprintf("/agnhost serve-hostname --tcp --http=false --port=%d", port)}
case v1.ProtocolUDP:
args = []string{fmt.Sprintf("/agnhost serve-hostname --udp --http=false --port=%d", port)}
case v1.ProtocolSCTP:
args = []string{"/agnhost porter"}
default:
args = []string{fmt.Sprintf("/agnhost serve-hostname --udp --http=false --port=%d & /agnhost serve-hostname --tcp --http=false --port=%d & /agnhost porter", port, port)}
}
return v1.Container{
Name: fmt.Sprintf("c%d", port),
ImagePullPolicy: v1.PullIfNotPresent,
Image: agnhostImage,
Env: []v1.EnvVar{{Name: fmt.Sprintf("SERVE_SCTP_PORT_%d", port), Value: "foo"}},
Command: []string{"/bin/bash", "-c"},
Args: args,
SecurityContext: &v1.SecurityContext{},
Ports: []v1.ContainerPort{
{
ContainerPort: port,
Name: fmt.Sprintf("serve-%d", port),
},
},
}
}
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Labels: labels,
Namespace: ns,
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{MatchLabels: labels},
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Namespace: ns,
},
Spec: v1.PodSpec{
TerminationGracePeriodSeconds: &zero,
Containers: []v1.Container{
makeContainerSpec(80, "ALL"),
makeContainerSpec(81, "ALL"),
makeContainerSpec(8080, v1.ProtocolTCP),
makeContainerSpec(8081, v1.ProtocolTCP),
makeContainerSpec(8082, v1.ProtocolTCP),
makeContainerSpec(8083, v1.ProtocolTCP),
makeContainerSpec(8084, v1.ProtocolTCP),
makeContainerSpec(8085, v1.ProtocolTCP),
},
},
},
},
}
d, err := data.clientset.AppsV1().Deployments(ns).Create(context.TODO(), deployment, metav1.CreateOptions{})
if err == nil {
log.Infof("Created deployment '%s/%s'", ns, d.Name)
return d, nil
}
log.Debugf("Unable to create deployment %s in Namespace %s, let's try update instead", deployment.Name, ns)
d, err = data.clientset.AppsV1().Deployments(ns).Update(context.TODO(), deployment, metav1.UpdateOptions{})
if err != nil {
log.Debugf("Unable to update deployment '%s/%s': %s", ns, deployment.Name, err)
}
return d, err
}
// BuildService is a convenience function for building a corev1.Service spec.
func (data *TestData) BuildService(svcName, svcNS string, port, targetPort int, selector map[string]string, serviceType *v1.ServiceType) *v1.Service {
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: svcName,
Namespace: svcNS,
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{{
Port: int32(port),
TargetPort: intstr.FromInt(targetPort),
}},
Selector: selector,
},
}
if serviceType != nil {
service.Spec.Type = *serviceType
}
return service
}
// CreateOrUpdateService is a convenience function for updating/creating Services.
func (data *TestData) CreateOrUpdateService(svc *v1.Service) (*v1.Service, error) {
log.Infof("Creating/updating Service %s in ns %s", svc.Name, svc.Namespace)
svcReturned, err := data.clientset.CoreV1().Services(svc.Namespace).Get(context.TODO(), svc.Name, metav1.GetOptions{})
if err != nil {
service, err := data.clientset.CoreV1().Services(svc.Namespace).Create(context.TODO(), svc, metav1.CreateOptions{})
if err != nil {
log.Infof("Unable to create Service %s/%s: %s", svc.Namespace, svc.Name, err)
return nil, err
}
return service, nil
} else if svcReturned.Name != "" {
log.Debugf("Service %s/%s already exists, updating", svc.Namespace, svc.Name)
clusterIP := svcReturned.Spec.ClusterIP
svcReturned.Spec = svc.Spec
svcReturned.Spec.ClusterIP = clusterIP
service, err := data.clientset.CoreV1().Services(svc.Namespace).Update(context.TODO(), svcReturned, metav1.UpdateOptions{})
return service, err
}
return nil, fmt.Errorf("error occurred in creating/updating Service %s", svc.Name)
}
// GetService is a convenience function for getting Service
func (data *TestData) GetService(namespace, name string) (*v1.Service, error) {
return data.clientset.CoreV1().Services(namespace).Get(context.TODO(), name, metav1.GetOptions{})
}
// DeleteService is a convenience function for deleting a Service by Namespace and name.
func (data *TestData) DeleteService(ns, name string) error {
log.Infof("Deleting Service %s in ns %s", name, ns)
err := data.clientset.CoreV1().Services(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete Service %s", name)
}
return nil
}
// CleanServices is a convenience function for deleting Services in the cluster.
func (data *TestData) CleanServices(namespaces map[string]string) error {
for _, ns := range namespaces {
l, err := data.clientset.CoreV1().Services(ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list Services in ns %s", ns)
}
for _, svc := range l.Items {
if err := data.DeleteService(svc.Namespace, svc.Name); err != nil {
return err
}
}
}
return nil
}
// BuildServiceAccount is a convenience function for building a corev1.SerivceAccount spec.
func (data *TestData) BuildServiceAccount(name, ns string, labels map[string]string) *v1.ServiceAccount {
serviceAccount := &v1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
Labels: labels,
},
}
return serviceAccount
}
// CreateOrUpdateServiceAccount is a convenience function for updating/creating ServiceAccount.
func (data *TestData) CreateOrUpdateServiceAccount(sa *v1.ServiceAccount) (*v1.ServiceAccount, error) {
log.Infof("Creating/updating ServiceAccount %s in ns %s", sa.Name, sa.Namespace)
saReturned, err := data.clientset.CoreV1().ServiceAccounts(sa.Namespace).Get(context.TODO(), sa.Name, metav1.GetOptions{})
if err != nil {
serviceAccount, err := data.clientset.CoreV1().ServiceAccounts(sa.Namespace).Create(context.TODO(), sa, metav1.CreateOptions{})
if err != nil {
log.Infof("Unable to create ServiceAccount %s/%s: %s", sa.Namespace, sa.Name, err)
return nil, err
}
return serviceAccount, nil
}
log.Debugf("ServiceAccount %s/%s already exists, updating", sa.Namespace, sa.Name)
saReturned.Labels = sa.Labels
serviceAccount, err := data.clientset.CoreV1().ServiceAccounts(sa.Namespace).Update(context.TODO(), saReturned, metav1.UpdateOptions{})
if err != nil {
log.Infof("Unable to update ServiceAccount %s/%s: %s", sa.Namespace, sa.Name, err)
return nil, err
}
return serviceAccount, nil
}
// DeleteServiceAccount is a convenience function for deleting a ServiceAccount by Namespace and name.
func (data *TestData) DeleteServiceAccount(ns, name string) error {
log.Infof("Deleting ServiceAccount %s in ns %s", name, ns)
err := data.clientset.CoreV1().ServiceAccounts(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete ServiceAccount %s in ns %s", name, ns)
}
return nil
}
// CreateOrUpdateNetworkPolicy is a convenience function for updating/creating netpols. Updating is important since
// some tests update a network policy to confirm that mutation works with a CNI.
func (data *TestData) CreateOrUpdateNetworkPolicy(netpol *v1net.NetworkPolicy) (*v1net.NetworkPolicy, error) {
log.Infof("Creating/updating NetworkPolicy '%s/%s'", netpol.Namespace, netpol.Name)
np, err := data.clientset.NetworkingV1().NetworkPolicies(netpol.Namespace).Update(context.TODO(), netpol, metav1.UpdateOptions{})
if err == nil {
return np, err
}
log.Debugf("Unable to update NetworkPolicy '%s/%s', let's try creating it instead (error: %s)", netpol.Namespace, netpol.Name, err)
np, err = data.clientset.NetworkingV1().NetworkPolicies(netpol.Namespace).Create(context.TODO(), netpol, metav1.CreateOptions{})
if err != nil {
log.Debugf("Unable to create network policy: %s", err)
}
return np, err
}
// GetNetworkPolicy is a convenience function for getting k8s NetworkPolicies.
func (data *TestData) GetNetworkPolicy(namespace, name string) (*v1net.NetworkPolicy, error) {
return data.clientset.NetworkingV1().NetworkPolicies(namespace).Get(context.TODO(), name, metav1.GetOptions{})
}
// DeleteNetworkPolicy is a convenience function for deleting NetworkPolicy by name and Namespace.
func (data *TestData) DeleteNetworkPolicy(ns, name string) error {
log.Infof("Deleting NetworkPolicy '%s/%s'", ns, name)
err := data.clientset.NetworkingV1().NetworkPolicies(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete NetworkPolicy '%s'", name)
}
return nil
}
// CleanNetworkPolicies is a convenience function for deleting NetworkPolicies in the provided namespaces.
func (data *TestData) CleanNetworkPolicies(namespaces map[string]string) error {
for _, ns := range namespaces {
l, err := data.clientset.NetworkingV1().NetworkPolicies(ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list NetworkPolicy in Namespace '%s'", ns)
}
for _, np := range l.Items {
if err = data.DeleteNetworkPolicy(np.Namespace, np.Name); err != nil {
return err
}
}
}
return nil
}
// CreateTier is a convenience function for creating an Antrea Policy Tier by name and priority.
func (data *TestData) CreateNewTier(name string, tierPriority int32) (*crdv1alpha1.Tier, error) {
log.Infof("Creating tier %s", name)
_, err := data.crdClient.CrdV1alpha1().Tiers().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
tr := &crdv1alpha1.Tier{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: crdv1alpha1.TierSpec{Priority: tierPriority},
}
tr, err = data.crdClient.CrdV1alpha1().Tiers().Create(context.TODO(), tr, metav1.CreateOptions{})
if err != nil {
log.Debugf("Unable to create tier %s: %s", name, err)
}
return tr, err
}
return nil, fmt.Errorf("tier with name %s already exists", name)
}
// GetTier is a convenience function for getting Tier.
func (data *TestData) GetTier(name string) (*crdv1alpha1.Tier, error) {
return data.crdClient.CrdV1alpha1().Tiers().Get(context.TODO(), name, metav1.GetOptions{})
}
// UpdateTier is a convenience function for updating an Antrea Policy Tier.
func (data *TestData) UpdateTier(tier *crdv1alpha1.Tier) (*crdv1alpha1.Tier, error) {
log.Infof("Updating tier %s", tier.Name)
updatedTier, err := data.crdClient.CrdV1alpha1().Tiers().Update(context.TODO(), tier, metav1.UpdateOptions{})
return updatedTier, err
}
// DeleteTier is a convenience function for deleting an Antrea Policy Tier with specific name.
func (data *TestData) DeleteTier(name string) error {
_, err := data.crdClient.CrdV1alpha1().Tiers().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return errors.Wrapf(err, "unable to get tier %s", name)
}
log.Infof("Deleting tier %s", name)
if err = data.crdClient.CrdV1alpha1().Tiers().Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil {
return errors.Wrapf(err, "unable to delete tier %s", name)
}
return nil
}
// CreateOrUpdateV1Alpha2CG is a convenience function for idempotent setup of crd/v1alpha2 ClusterGroups
func (data *TestData) CreateOrUpdateV1Alpha2CG(cg *crdv1alpha2.ClusterGroup) (*crdv1alpha2.ClusterGroup, error) {
log.Infof("Creating/updating ClusterGroup %s", cg.Name)
cgReturned, err := data.crdClient.CrdV1alpha2().ClusterGroups().Get(context.TODO(), cg.Name, metav1.GetOptions{})
if err != nil {
cgr, err := data.crdClient.CrdV1alpha2().ClusterGroups().Create(context.TODO(), cg, metav1.CreateOptions{})
if err != nil {
log.Infof("Unable to create cluster group %s: %v", cg.Name, err)
return nil, err
}
return cgr, nil
} else if cgReturned.Name != "" {
log.Debugf("ClusterGroup with name %s already exists, updating", cg.Name)
cgReturned.Spec = cg.Spec
cgr, err := data.crdClient.CrdV1alpha2().ClusterGroups().Update(context.TODO(), cgReturned, metav1.UpdateOptions{})
return cgr, err
}
return nil, fmt.Errorf("error occurred in creating/updating ClusterGroup %s", cg.Name)
}
// CreateOrUpdateV1Alpha3CG is a convenience function for idempotent setup of crd/v1alpha3 ClusterGroups
func (data *TestData) CreateOrUpdateV1Alpha3CG(cg *crdv1alpha3.ClusterGroup) (*crdv1alpha3.ClusterGroup, error) {
log.Infof("Creating/updating ClusterGroup %s", cg.Name)
cgReturned, err := data.crdClient.CrdV1alpha3().ClusterGroups().Get(context.TODO(), cg.Name, metav1.GetOptions{})
if err != nil {
cgr, err := data.crdClient.CrdV1alpha3().ClusterGroups().Create(context.TODO(), cg, metav1.CreateOptions{})
if err != nil {
log.Infof("Unable to create cluster group %s: %v", cg.Name, err)
return nil, err
}
return cgr, nil
} else if cgReturned.Name != "" {
log.Debugf("ClusterGroup with name %s already exists, updating", cg.Name)
cgReturned.Spec = cg.Spec
cgr, err := data.crdClient.CrdV1alpha3().ClusterGroups().Update(context.TODO(), cgReturned, metav1.UpdateOptions{})
return cgr, err
}
return nil, fmt.Errorf("error occurred in creating/updating ClusterGroup %s", cg.Name)
}
func (data *TestData) GetV1Alpha2CG(cgName string) (*crdv1alpha2.ClusterGroup, error) {
return data.crdClient.CrdV1alpha2().ClusterGroups().Get(context.TODO(), cgName, metav1.GetOptions{})
}
// CreateOrUpdateV1Alpha3Group is a convenience function for idempotent setup of crd/v1alpha3 Groups
func (k *KubernetesUtils) CreateOrUpdateV1Alpha3Group(g *crdv1alpha3.Group) (*crdv1alpha3.Group, error) {
log.Infof("Creating/updating Group %s/%s", g.Namespace, g.Name)
gReturned, err := k.crdClient.CrdV1alpha3().Groups(g.Namespace).Get(context.TODO(), g.Name, metav1.GetOptions{})
if err != nil {
gr, err := k.crdClient.CrdV1alpha3().Groups(g.Namespace).Create(context.TODO(), g, metav1.CreateOptions{})
if err != nil {
log.Infof("Unable to create group %s/%s: %v", g.Namespace, g.Name, err)
return nil, err
}
return gr, nil
} else if gReturned.Name != "" {
log.Debugf("Group %s/%s already exists, updating", g.Namespace, g.Name)
gReturned.Spec = g.Spec
gr, err := k.crdClient.CrdV1alpha3().Groups(g.Namespace).Update(context.TODO(), gReturned, metav1.UpdateOptions{})
return gr, err
}
return nil, fmt.Errorf("error occurred in creating/updating Group %s/%s", g.Namespace, g.Name)
}
func (data *TestData) GetV1Alpha3CG(cgName string) (*crdv1alpha3.ClusterGroup, error) {
return data.crdClient.CrdV1alpha3().ClusterGroups().Get(context.TODO(), cgName, metav1.GetOptions{})
}
// CreateCG is a convenience function for creating an Antrea ClusterGroup by name and selector.
func (data *TestData) CreateCG(name string, pSelector, nSelector *metav1.LabelSelector, ipBlocks []crdv1alpha1.IPBlock) (*crdv1alpha3.ClusterGroup, error) {
log.Infof("Creating clustergroup %s", name)
_, err := data.crdClient.CrdV1alpha3().ClusterGroups().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
cg := &crdv1alpha3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
if pSelector != nil {
cg.Spec.PodSelector = pSelector
}
if nSelector != nil {
cg.Spec.NamespaceSelector = nSelector
}
if len(ipBlocks) > 0 {
cg.Spec.IPBlocks = ipBlocks
}
cg, err = data.crdClient.CrdV1alpha3().ClusterGroups().Create(context.TODO(), cg, metav1.CreateOptions{})
if err != nil {
log.Debugf("Unable to create clustergroup %s: %s", name, err)
}
return cg, err
}
return nil, fmt.Errorf("clustergroup with name %s already exists", name)
}
// GetCG is a convenience function for getting ClusterGroups
func (k *KubernetesUtils) GetCG(name string) (*crdv1alpha2.ClusterGroup, error) {
res, err := k.crdClient.CrdV1alpha2().ClusterGroups().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
return res, nil
}
// CreateGroup is a convenience function for creating an Antrea Group by namespace, name and selector.
func (k *KubernetesUtils) CreateGroup(namespace, name string, pSelector, nSelector *metav1.LabelSelector, ipBlocks []crdv1alpha1.IPBlock) (*crdv1alpha3.Group, error) {
log.Infof("Creating group %s/%s", namespace, name)
_, err := k.crdClient.CrdV1alpha3().Groups(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
g := &crdv1alpha3.Group{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
}
if pSelector != nil {
g.Spec.PodSelector = pSelector
}
if nSelector != nil {
g.Spec.NamespaceSelector = nSelector
}
if len(ipBlocks) > 0 {
g.Spec.IPBlocks = ipBlocks
}
g, err = k.crdClient.CrdV1alpha3().Groups(namespace).Create(context.TODO(), g, metav1.CreateOptions{})
if err != nil {
log.Debugf("Unable to create group %s/%s: %s", namespace, name, err)
}
return g, err
}
return nil, fmt.Errorf("group with name %s/%s already exists", namespace, name)
}
// GetGroup is a convenience function for getting Groups
func (k *KubernetesUtils) GetGroup(namespace, name string) (*crdv1alpha3.Group, error) {
res, err := k.crdClient.CrdV1alpha3().Groups(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
return res, nil
}
// DeleteV1Alpha2CG is a convenience function for deleting crd/v1alpha2 ClusterGroup by name.
func (data *TestData) DeleteV1Alpha2CG(name string) error {
log.Infof("Deleting ClusterGroup %s", name)
err := data.crdClient.CrdV1alpha2().ClusterGroups().Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete ClusterGroup %s", name)
}
return nil
}
// DeleteV1Alpha3CG is a convenience function for deleting core/v1alpha3 ClusterGroup by name.
func (data *TestData) DeleteV1Alpha3CG(name string) error {
log.Infof("deleting ClusterGroup %s", name)
err := data.crdClient.CrdV1alpha3().ClusterGroups().Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete ClusterGroup %s", name)
}
return nil
}
// DeleteV1Alpha3Group is a convenience function for deleting core/v1alpha3 Group by namespace and name.
func (k *KubernetesUtils) DeleteV1Alpha3Group(namespace, name string) error {
log.Infof("deleting Group %s/%s", namespace, name)
err := k.crdClient.CrdV1alpha3().Groups(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete Group %s/%s", namespace, name)
}
return nil
}
// CleanCGs is a convenience function for deleting all ClusterGroups in the cluster.
func (data *TestData) CleanCGs() error {
l, err := data.crdClient.CrdV1alpha2().ClusterGroups().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list ClusterGroups in v1alpha2")
}
for _, cg := range l.Items {
if err := data.DeleteV1Alpha2CG(cg.Name); err != nil {
return err
}
}
l2, err := data.crdClient.CrdV1alpha3().ClusterGroups().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list ClusterGroups in v1alpha3")
}
for _, cg := range l2.Items {
if err := data.DeleteV1Alpha3CG(cg.Name); err != nil {
return err
}
}
return nil
}
// CleanGroups is a convenience function for deleting all Groups in the namespace.
func (k *KubernetesUtils) CleanGroups(namespace string) error {
l, err := k.crdClient.CrdV1alpha3().Groups(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list Groups in v1alpha3")
}
for _, g := range l.Items {
if err := k.DeleteV1Alpha3Group(namespace, g.Name); err != nil {
return err
}
}
return nil
}
// CreateOrUpdateACNP is a convenience function for updating/creating AntreaClusterNetworkPolicies.
func (data *TestData) CreateOrUpdateACNP(cnp *crdv1alpha1.ClusterNetworkPolicy) (*crdv1alpha1.ClusterNetworkPolicy, error) {
log.Infof("Creating/updating ClusterNetworkPolicy %s", cnp.Name)
cnpReturned, err := data.crdClient.CrdV1alpha1().ClusterNetworkPolicies().Get(context.TODO(), cnp.Name, metav1.GetOptions{})
if err != nil {
log.Debugf("Creating ClusterNetworkPolicy %s", cnp.Name)
cnp, err = data.crdClient.CrdV1alpha1().ClusterNetworkPolicies().Create(context.TODO(), cnp, metav1.CreateOptions{})
if err != nil {
log.Debugf("Unable to create ClusterNetworkPolicy: %s", err)
}
return cnp, err
} else if cnpReturned.Name != "" {
log.Debugf("ClusterNetworkPolicy with name %s already exists, updating", cnp.Name)
cnpReturned.Spec = cnp.Spec
cnp, err = data.crdClient.CrdV1alpha1().ClusterNetworkPolicies().Update(context.TODO(), cnpReturned, metav1.UpdateOptions{})
return cnp, err
}
return nil, fmt.Errorf("error occurred in creating/updating ClusterNetworkPolicy %s", cnp.Name)
}
// GetACNP is a convenience function for getting AntreaClusterNetworkPolicies.
func (data *TestData) GetACNP(name string) (*crdv1alpha1.ClusterNetworkPolicy, error) {
res, err := data.crdClient.CrdV1alpha1().ClusterNetworkPolicies().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
return res, nil
}
// DeleteACNP is a convenience function for deleting ACNP by name.
func (data *TestData) DeleteACNP(name string) error {
log.Infof("Deleting AntreaClusterNetworkPolicies %s", name)
err := data.crdClient.CrdV1alpha1().ClusterNetworkPolicies().Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete ClusterNetworkPolicy %s", name)
}
return nil
}
// CleanACNPs is a convenience function for deleting all Antrea ClusterNetworkPolicies in the cluster.
func (data *TestData) CleanACNPs() error {
l, err := data.crdClient.CrdV1alpha1().ClusterNetworkPolicies().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list AntreaClusterNetworkPolicies")
}
for _, cnp := range l.Items {
if err = data.DeleteACNP(cnp.Name); err != nil {
return err
}
}
return nil
}
// CreateOrUpdateANP is a convenience function for updating/creating Antrea NetworkPolicies.
func (data *TestData) CreateOrUpdateANP(anp *crdv1alpha1.NetworkPolicy) (*crdv1alpha1.NetworkPolicy, error) {
log.Infof("Creating/updating Antrea NetworkPolicy %s/%s", anp.Namespace, anp.Name)
cnpReturned, err := data.crdClient.CrdV1alpha1().NetworkPolicies(anp.Namespace).Get(context.TODO(), anp.Name, metav1.GetOptions{})
if err != nil {
log.Debugf("Creating Antrea NetworkPolicy %s", anp.Name)
anp, err = data.crdClient.CrdV1alpha1().NetworkPolicies(anp.Namespace).Create(context.TODO(), anp, metav1.CreateOptions{})
if err != nil {
log.Debugf("Unable to create Antrea NetworkPolicy: %s", err)
}
return anp, err
} else if cnpReturned.Name != "" {
log.Debugf("Antrea NetworkPolicy with name %s already exists, updating", anp.Name)
anp, err = data.crdClient.CrdV1alpha1().NetworkPolicies(anp.Namespace).Update(context.TODO(), anp, metav1.UpdateOptions{})
return anp, err
}
return nil, fmt.Errorf("error occurred in creating/updating Antrea NetworkPolicy %s", anp.Name)
}
// GetANP is a convenience function for getting AntreaNetworkPolicies.
func (data *TestData) GetANP(namespace, name string) (*crdv1alpha1.NetworkPolicy, error) {
return data.crdClient.CrdV1alpha1().NetworkPolicies(namespace).Get(context.TODO(), name, metav1.GetOptions{})
}
// DeleteANP is a convenience function for deleting ANP by name and Namespace.
func (data *TestData) DeleteANP(ns, name string) error {
log.Infof("Deleting Antrea NetworkPolicy '%s/%s'", ns, name)
err := data.crdClient.CrdV1alpha1().NetworkPolicies(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "unable to delete Antrea NetworkPolicy %s", name)
}
return nil
}
// CleanANPs is a convenience function for deleting all Antrea NetworkPolicies in provided namespaces.
func (data *TestData) CleanANPs(namespaces []string) error {
for _, ns := range namespaces {
l, err := data.crdClient.CrdV1alpha1().NetworkPolicies(ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "unable to list Antrea NetworkPolicies in ns %s", ns)
}
for _, anp := range l.Items {
if err = data.DeleteANP(anp.Namespace, anp.Name); err != nil {
return err
}
}
}
return nil
}
func (k *KubernetesUtils) waitForPodInNamespace(ns string, pod string) ([]string, error) {
log.Infof("Waiting for Pod '%s/%s'", ns, pod)
for {
k8sPod, err := k.GetPodByLabel(ns, pod)
if err != nil {
return nil, errors.WithMessagef(err, "unable to get Pod '%s/%s'", ns, pod)
}
if k8sPod != nil && k8sPod.Status.Phase == v1.PodRunning {
if k8sPod.Status.PodIP == "" {
return nil, errors.WithMessagef(err, "unable to get IP of Pod '%s/%s'", ns, pod)
}
var podIPs []string
for _, podIP := range k8sPod.Status.PodIPs {
podIPs = append(podIPs, podIP.IP)
}
log.Debugf("IPs of Pod '%s/%s': %s", ns, pod, podIPs)
log.Debugf("Pod running: %s/%s", ns, pod)
return podIPs, nil
}
log.Infof("Pod '%s/%s' not ready, waiting ...", ns, pod)
time.Sleep(2 * time.Second)
}
}
func (k *KubernetesUtils) waitForHTTPServers(allPods []Pod) error {
const maxTries = 10
log.Infof("waiting for HTTP servers (ports 80, 81 and 8080:8085) to become ready")
serversAreReady := func() bool {
reachability := NewReachability(allPods, Connected)
k.Validate(allPods, reachability, []int32{80, 81, 8080, 8081, 8082, 8083, 8084, 8085}, utils.ProtocolTCP)
if _, wrong, _ := reachability.Summary(); wrong != 0 {
return false
}
k.Validate(allPods, reachability, []int32{80, 81}, utils.ProtocolUDP)
if _, wrong, _ := reachability.Summary(); wrong != 0 {
return false
}