Skip to content

E2E: Add function to determine a cluster's supported IP families #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
k8serrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/dynamic"
Expand Down Expand Up @@ -69,6 +70,14 @@ const (
BasicTestLabel = "basic"
)

type IPFamilyType string

const (
SingleStackIPv4 IPFamilyType = "SingleStackIPv4"
SingleStackIPv6 IPFamilyType = "SingleStackIPv6"
DualStack IPFamilyType = "DualStack"
)

type PatchFunc func(pt types.PatchType, payload []byte) error

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

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

Expand Down Expand Up @@ -487,6 +498,44 @@ func (f *Framework) AddNamespacesToDelete(namespaces ...*corev1.Namespace) {
}
}

func (f *Framework) DetermineIPFamilyType(cluster ClusterIndex) IPFamilyType {
ipFamilyType, ok := f.ipFamilyTypes[cluster]
if ok {
return ipFamilyType
}

svc, err := KubeClients[cluster].CoreV1().Services(f.Namespace).Create(context.TODO(), &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "test-ip-families"},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
IPFamilyPolicy: ptr.To(corev1.IPFamilyPolicyPreferDualStack),
Ports: []corev1.ServicePort{
{
Port: 9000,
TargetPort: intstr.IntOrString{
IntVal: 9000,
},
},
},
},
}, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())

ipFamilyType = SingleStackIPv4
if len(svc.Spec.IPFamilies) == 2 {
ipFamilyType = DualStack
} else if svc.Spec.IPFamilies[0] == corev1.IPv6Protocol {
ipFamilyType = SingleStackIPv6
}

f.ipFamilyTypes[cluster] = ipFamilyType

err = KubeClients[cluster].CoreV1().Services(f.Namespace).Delete(context.TODO(), svc.Name, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())

return ipFamilyType
}

func generateNamespace(client kubeclientset.Interface, baseName string, labels map[string]string) *corev1.Namespace {
namespaceObj := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Loading