From 3da66c44e899c5ae1cb276b921b49e72be8423d8 Mon Sep 17 00:00:00 2001 From: alejandrox1 Date: Fri, 25 Oct 2019 16:17:11 -0400 Subject: [PATCH] Cleaned up skip functions from e2e framework This patch moves skip-related functions from framework/util.go to another file. Signed-off-by: alejandrox1 --- test/e2e/framework/skip.go | 100 +++++++++++++++++++++++++++---------- test/e2e/framework/util.go | 42 ---------------- 2 files changed, 73 insertions(+), 69 deletions(-) diff --git a/test/e2e/framework/skip.go b/test/e2e/framework/skip.go index 139f289bcd6..60ff5f5254c 100644 --- a/test/e2e/framework/skip.go +++ b/test/e2e/framework/skip.go @@ -19,7 +19,13 @@ package framework import ( "fmt" + apierrs "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + utilversion "k8s.io/apimachinery/pkg/util/version" utilfeature "k8s.io/apiserver/pkg/util/feature" + "k8s.io/client-go/discovery" + "k8s.io/client-go/dynamic" clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/test/e2e/framework/ginkgowrapper" @@ -37,6 +43,42 @@ func Skipf(format string, args ...interface{}) { skipInternalf(1, format, args...) } +// SkipUnlessAtLeast skips if the value is less than the minValue. +func SkipUnlessAtLeast(value int, minValue int, message string) { + if value < minValue { + skipInternalf(1, message) + } +} + +// SkipIfContainerRuntimeIs skips if the container runtime is included in the runtimes. +func SkipIfContainerRuntimeIs(runtimes ...string) { + for _, containerRuntime := range runtimes { + if containerRuntime == TestContext.ContainerRuntime { + skipInternalf(1, "Not supported under container runtime %s", containerRuntime) + } + } +} + +// SkipUnlessLocalEphemeralStorageEnabled skips if the LocalStorageCapacityIsolation is not enabled. +func SkipUnlessLocalEphemeralStorageEnabled() { + if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) { + skipInternalf(1, "Only supported when %v feature is enabled", features.LocalStorageCapacityIsolation) + } +} + +// SkipIfMissingResource skips if the gvr resource is missing. +func SkipIfMissingResource(dynamicClient dynamic.Interface, gvr schema.GroupVersionResource, namespace string) { + resourceClient := dynamicClient.Resource(gvr).Namespace(namespace) + _, err := resourceClient.List(metav1.ListOptions{}) + if err != nil { + // not all resources support list, so we ignore those + if apierrs.IsMethodNotSupported(err) || apierrs.IsNotFound(err) || apierrs.IsForbidden(err) { + skipInternalf(1, "Could not find %s resource, skipping test: %#v", gvr, err) + } + Failf("Unexpected error getting %v: %v", gvr, err) + } +} + // SkipUnlessNodeCountIsAtLeast skips if the number of nodes is less than the minNodeCount. func SkipUnlessNodeCountIsAtLeast(minNodeCount int) { if TestContext.CloudConfig.NumNodes < minNodeCount { @@ -51,13 +93,6 @@ func SkipUnlessNodeCountIsAtMost(maxNodeCount int) { } } -// SkipUnlessAtLeast skips if the value is less than the minValue. -func SkipUnlessAtLeast(value int, minValue int, message string) { - if value < minValue { - skipInternalf(1, message) - } -} - // SkipIfProviderIs skips if the provider is included in the unsupportedProviders. func SkipIfProviderIs(unsupportedProviders ...string) { if ProviderIs(unsupportedProviders...) { @@ -65,20 +100,6 @@ func SkipIfProviderIs(unsupportedProviders ...string) { } } -// SkipUnlessLocalEphemeralStorageEnabled skips if the LocalStorageCapacityIsolation is not enabled. -func SkipUnlessLocalEphemeralStorageEnabled() { - if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) { - skipInternalf(1, "Only supported when %v feature is enabled", features.LocalStorageCapacityIsolation) - } -} - -// SkipUnlessSSHKeyPresent skips if no SSH key is found. -func SkipUnlessSSHKeyPresent() { - if _, err := e2essh.GetSigner(TestContext.Provider); err != nil { - skipInternalf(1, "No SSH Key for provider %s: '%v'", TestContext.Provider, err) - } -} - // SkipUnlessProviderIs skips if the provider is not included in the supportedProviders. func SkipUnlessProviderIs(supportedProviders ...string) { if !ProviderIs(supportedProviders...) { @@ -129,6 +150,24 @@ func SkipIfNodeOSDistroIs(unsupportedNodeOsDistros ...string) { } } +// SkipUnlessServerVersionGTE skips if the server version is less than v. +func SkipUnlessServerVersionGTE(v *utilversion.Version, c discovery.ServerVersionInterface) { + gte, err := serverVersionGTE(v, c) + if err != nil { + Failf("Failed to get server version: %v", err) + } + if !gte { + skipInternalf(1, "Not supported for server versions before %q", v) + } +} + +// SkipUnlessSSHKeyPresent skips if no SSH key is found. +func SkipUnlessSSHKeyPresent() { + if _, err := e2essh.GetSigner(TestContext.Provider); err != nil { + skipInternalf(1, "No SSH Key for provider %s: '%v'", TestContext.Provider, err) + } +} + // SkipUnlessTaintBasedEvictionsEnabled skips if the TaintBasedEvictions is not enabled. func SkipUnlessTaintBasedEvictionsEnabled() { if !utilfeature.DefaultFeatureGate.Enabled(features.TaintBasedEvictions) { @@ -136,11 +175,18 @@ func SkipUnlessTaintBasedEvictionsEnabled() { } } -// SkipIfContainerRuntimeIs skips if the container runtime is included in the runtimes. -func SkipIfContainerRuntimeIs(runtimes ...string) { - for _, containerRuntime := range runtimes { - if containerRuntime == TestContext.ContainerRuntime { - skipInternalf(1, "Not supported under container runtime %s", containerRuntime) - } +// serverVersionGTE returns true if v is greater than or equal to the server +// version. +// +// TODO(18726): This should be incorporated into client.VersionInterface. +func serverVersionGTE(v *utilversion.Version, c discovery.ServerVersionInterface) (bool, error) { + serverVersion, err := c.ServerVersion() + if err != nil { + return false, fmt.Errorf("Unable to get server version: %v", err) } + sv, err := utilversion.ParseSemantic(serverVersion.GitVersion) + if err != nil { + return false, fmt.Errorf("Unable to parse server version %q: %v", serverVersion.GitVersion, err) + } + return sv.AtLeast(v), nil } diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 0319b12e9dc..cd8827c8f23 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -60,8 +60,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" utilyaml "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/discovery" - "k8s.io/client-go/dynamic" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" restclient "k8s.io/client-go/rest" @@ -339,30 +337,6 @@ func ProxyMode(f *Framework) (string, error) { return stdout, nil } -// SkipUnlessServerVersionGTE skips if the server version is less than v. -func SkipUnlessServerVersionGTE(v *utilversion.Version, c discovery.ServerVersionInterface) { - gte, err := ServerVersionGTE(v, c) - if err != nil { - Failf("Failed to get server version: %v", err) - } - if !gte { - skipInternalf(1, "Not supported for server versions before %q", v) - } -} - -// SkipIfMissingResource skips if the gvr resource is missing. -func SkipIfMissingResource(dynamicClient dynamic.Interface, gvr schema.GroupVersionResource, namespace string) { - resourceClient := dynamicClient.Resource(gvr).Namespace(namespace) - _, err := resourceClient.List(metav1.ListOptions{}) - if err != nil { - // not all resources support list, so we ignore those - if apierrs.IsMethodNotSupported(err) || apierrs.IsNotFound(err) || apierrs.IsForbidden(err) { - skipInternalf(1, "Could not find %s resource, skipping test: %#v", gvr, err) - } - Failf("Unexpected error getting %v: %v", gvr, err) - } -} - // WaitForDaemonSets for all daemonsets in the given namespace to be ready // (defined as all but 'allowedNotReadyNodes' pods associated with that // daemonset are ready). @@ -852,22 +826,6 @@ func countEndpointsNum(e *v1.Endpoints) int { return num } -// ServerVersionGTE returns true if v is greater than or equal to the server -// version. -// -// TODO(18726): This should be incorporated into client.VersionInterface. -func ServerVersionGTE(v *utilversion.Version, c discovery.ServerVersionInterface) (bool, error) { - serverVersion, err := c.ServerVersion() - if err != nil { - return false, fmt.Errorf("Unable to get server version: %v", err) - } - sv, err := utilversion.ParseSemantic(serverVersion.GitVersion) - if err != nil { - return false, fmt.Errorf("Unable to parse server version %q: %v", serverVersion.GitVersion, err) - } - return sv.AtLeast(v), nil -} - // KubectlVersion gets the version of kubectl that's currently being used (see // --kubectl-path in e2e.go to use an alternate kubectl). func KubectlVersion() (*utilversion.Version, error) {