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