Skip to content
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
25 changes: 19 additions & 6 deletions openshift-hack/cmd/k8s-tests-ext/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/kubernetes/openshift-hack/e2e"
Expand All @@ -21,6 +22,7 @@ import (
"k8s.io/kubernetes/test/e2e/storage/external"
e2etestingmanifests "k8s.io/kubernetes/test/e2e/testing-manifests"
testfixtures "k8s.io/kubernetes/test/fixtures"
utilnet "k8s.io/utils/net"

// this appears to inexplicably auto-register global flags.
_ "k8s.io/kubernetes/test/e2e/storage/drivers"
Expand Down Expand Up @@ -91,12 +93,6 @@ func updateTestFrameworkForTests(provider string) error {
ConfigFile: config.ConfigFile,
}

// these constants are taken from kube e2e and used by tests
testContext.IPFamily = "ipv4"
if config.HasIPv6 && !config.HasIPv4 {
testContext.IPFamily = "ipv6"
}

// load and set the host variable for kubectl
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&clientcmd.ClientConfigLoadingRules{ExplicitPath: testContext.KubeConfig}, &clientcmd.ConfigOverrides{})
cfg, err := clientConfig.ClientConfig()
Expand All @@ -105,6 +101,23 @@ func updateTestFrameworkForTests(provider string) error {
}
testContext.Host = cfg.Host

// Detect the cluster's primary IP family by checking the kubernetes.default service ClusterIP.
// This is the same approach used in upstream test/e2e/e2e.go's getDefaultClusterIPFamily().
// For dual-stack clusters, the primary IP family is determined by the ClusterIP of the kubernetes service.
testContext.IPFamily = "ipv4" // default
c, err := kclientset.NewForConfig(cfg)
if err != nil {
return fmt.Errorf("failed to create kubernetes client: %v", err)
}
ctx := context.Background()
svc, err := c.CoreV1().Services("default").Get(ctx, "kubernetes", metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get kubernetes.default service: %v", err)
}
if utilnet.IsIPv6String(svc.Spec.ClusterIP) {
testContext.IPFamily = "ipv6"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't silently discard the errors... neither of these operations should fail, so return the error if they do.
otherwise lgtm


// Ensure that Kube tests run privileged (like they do upstream)
testContext.CreateTestingNS = func(ctx context.Context, baseName string, c kclientset.Interface, labels map[string]string) (*corev1.Namespace, error) {
return e2e.CreateTestingNS(ctx, baseName, c, labels, true)
Expand Down