@@ -37,6 +37,7 @@ import (
37
37
"k8s.io/apimachinery/pkg/runtime/schema"
38
38
"k8s.io/apimachinery/pkg/types"
39
39
k8serrors "k8s.io/apimachinery/pkg/util/errors"
40
+ "k8s.io/apimachinery/pkg/util/intstr"
40
41
"k8s.io/apimachinery/pkg/util/uuid"
41
42
"k8s.io/apimachinery/pkg/util/wait"
42
43
"k8s.io/client-go/dynamic"
@@ -69,6 +70,14 @@ const (
69
70
BasicTestLabel = "basic"
70
71
)
71
72
73
+ type IPFamilyType string
74
+
75
+ const (
76
+ SingleStackIPv4 IPFamilyType = "SingleStackIPv4"
77
+ SingleStackIPv6 IPFamilyType = "SingleStackIPv6"
78
+ DualStack IPFamilyType = "DualStack"
79
+ )
80
+
72
81
type PatchFunc func (pt types.PatchType , payload []byte ) error
73
82
74
83
type PatchStringValue struct {
@@ -103,6 +112,7 @@ type Framework struct {
103
112
namespacesToDelete map [string ]bool // Some tests have more than one.
104
113
NamespaceDeletionTimeout time.Duration
105
114
gatewayNodesToReset map [int ][]string // Store GW nodes for the final cleanup
115
+ ipFamilyTypes map [ClusterIndex ]IPFamilyType
106
116
107
117
// To make sure that this framework cleans up after itself, no matter what,
108
118
// we install a Cleanup action before each test and clear it after. If we
@@ -126,6 +136,7 @@ func NewBareFramework(baseName string) *Framework {
126
136
BaseName : baseName ,
127
137
namespacesToDelete : map [string ]bool {},
128
138
gatewayNodesToReset : map [int ][]string {},
139
+ ipFamilyTypes : map [ClusterIndex ]IPFamilyType {},
129
140
}
130
141
}
131
142
@@ -487,6 +498,44 @@ func (f *Framework) AddNamespacesToDelete(namespaces ...*corev1.Namespace) {
487
498
}
488
499
}
489
500
501
+ func (f * Framework ) DetermineIPFamilyType (cluster ClusterIndex ) IPFamilyType {
502
+ ipFamilyType , ok := f .ipFamilyTypes [cluster ]
503
+ if ok {
504
+ return ipFamilyType
505
+ }
506
+
507
+ svc , err := KubeClients [cluster ].CoreV1 ().Services (f .Namespace ).Create (context .TODO (), & corev1.Service {
508
+ ObjectMeta : metav1.ObjectMeta {Name : "test-ip-families" },
509
+ Spec : corev1.ServiceSpec {
510
+ Type : corev1 .ServiceTypeClusterIP ,
511
+ IPFamilyPolicy : ptr .To (corev1 .IPFamilyPolicyPreferDualStack ),
512
+ Ports : []corev1.ServicePort {
513
+ {
514
+ Port : 9000 ,
515
+ TargetPort : intstr.IntOrString {
516
+ IntVal : 9000 ,
517
+ },
518
+ },
519
+ },
520
+ },
521
+ }, metav1.CreateOptions {})
522
+ Expect (err ).NotTo (HaveOccurred ())
523
+
524
+ ipFamilyType = SingleStackIPv4
525
+ if len (svc .Spec .IPFamilies ) == 2 {
526
+ ipFamilyType = DualStack
527
+ } else if svc .Spec .IPFamilies [0 ] == corev1 .IPv6Protocol {
528
+ ipFamilyType = SingleStackIPv6
529
+ }
530
+
531
+ f .ipFamilyTypes [cluster ] = ipFamilyType
532
+
533
+ err = KubeClients [cluster ].CoreV1 ().Services (f .Namespace ).Delete (context .TODO (), svc .Name , metav1.DeleteOptions {})
534
+ Expect (err ).NotTo (HaveOccurred ())
535
+
536
+ return ipFamilyType
537
+ }
538
+
490
539
func generateNamespace (client kubeclientset.Interface , baseName string , labels map [string ]string ) * corev1.Namespace {
491
540
namespaceObj := & corev1.Namespace {
492
541
ObjectMeta : metav1.ObjectMeta {
0 commit comments