Skip to content

Commit 91c8ad6

Browse files
committed
E2E: Add function to determine a cluster's supported IP families
Create a service with IPFamilyPolicy set to "PreferDualStack". If the resulting IPFamilies has 2 values then it's dual-stack otherwise check the single value. Signed-off-by: Tom Pantelis <[email protected]>
1 parent 5ca601c commit 91c8ad6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/e2e/framework/framework.go

+40
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ const (
6969
BasicTestLabel = "basic"
7070
)
7171

72+
type IPFamilyType string
73+
74+
const (
75+
SingleStackIPv4 IPFamilyType = "SingleStackIPv4"
76+
SingleStackIPv6 IPFamilyType = "SingleStackIPv6"
77+
DualStack IPFamilyType = "DualStack"
78+
)
79+
7280
type PatchFunc func(pt types.PatchType, payload []byte) error
7381

7482
type PatchStringValue struct {
@@ -103,6 +111,7 @@ type Framework struct {
103111
namespacesToDelete map[string]bool // Some tests have more than one.
104112
NamespaceDeletionTimeout time.Duration
105113
gatewayNodesToReset map[int][]string // Store GW nodes for the final cleanup
114+
ipFamilyTypes map[ClusterIndex]IPFamilyType
106115

107116
// To make sure that this framework cleans up after itself, no matter what,
108117
// we install a Cleanup action before each test and clear it after. If we
@@ -126,6 +135,7 @@ func NewBareFramework(baseName string) *Framework {
126135
BaseName: baseName,
127136
namespacesToDelete: map[string]bool{},
128137
gatewayNodesToReset: map[int][]string{},
138+
ipFamilyTypes: map[ClusterIndex]IPFamilyType{},
129139
}
130140
}
131141

@@ -487,6 +497,36 @@ func (f *Framework) AddNamespacesToDelete(namespaces ...*corev1.Namespace) {
487497
}
488498
}
489499

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+
490530
func generateNamespace(client kubeclientset.Interface, baseName string, labels map[string]string) *corev1.Namespace {
491531
namespaceObj := &corev1.Namespace{
492532
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)