Skip to content

Commit 69af200

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 69af200

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/e2e/framework/framework.go

+49
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"k8s.io/apimachinery/pkg/runtime/schema"
3838
"k8s.io/apimachinery/pkg/types"
3939
k8serrors "k8s.io/apimachinery/pkg/util/errors"
40+
"k8s.io/apimachinery/pkg/util/intstr"
4041
"k8s.io/apimachinery/pkg/util/uuid"
4142
"k8s.io/apimachinery/pkg/util/wait"
4243
"k8s.io/client-go/dynamic"
@@ -69,6 +70,14 @@ const (
6970
BasicTestLabel = "basic"
7071
)
7172

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

7483
type PatchStringValue struct {
@@ -103,6 +112,7 @@ type Framework struct {
103112
namespacesToDelete map[string]bool // Some tests have more than one.
104113
NamespaceDeletionTimeout time.Duration
105114
gatewayNodesToReset map[int][]string // Store GW nodes for the final cleanup
115+
ipFamilyTypes map[ClusterIndex]IPFamilyType
106116

107117
// To make sure that this framework cleans up after itself, no matter what,
108118
// we install a Cleanup action before each test and clear it after. If we
@@ -126,6 +136,7 @@ func NewBareFramework(baseName string) *Framework {
126136
BaseName: baseName,
127137
namespacesToDelete: map[string]bool{},
128138
gatewayNodesToReset: map[int][]string{},
139+
ipFamilyTypes: map[ClusterIndex]IPFamilyType{},
129140
}
130141
}
131142

@@ -487,6 +498,44 @@ func (f *Framework) AddNamespacesToDelete(namespaces ...*corev1.Namespace) {
487498
}
488499
}
489500

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

0 commit comments

Comments
 (0)