From 19c474fc4db481076e0da159e1a717c4c1da63d4 Mon Sep 17 00:00:00 2001 From: Kenichi Omichi Date: Fri, 9 Aug 2019 19:53:45 +0000 Subject: [PATCH] Remove core dependency from endpoints e2e fw WaitForEndpoint() of the endpoints e2e framework was used in test/e2e/network/proxy.go only. In addition, the endpoints e2e framework imported the core of e2e framework only for the function. So this moves the function into test/e2e/network/proxy.go then we can remove dependency of core framework from the sub e2e framework. --- test/e2e/framework/endpoints/BUILD | 7 +--- test/e2e/framework/endpoints/wait.go | 57 ---------------------------- test/e2e/network/proxy.go | 23 ++++++++++- 3 files changed, 22 insertions(+), 65 deletions(-) delete mode 100644 test/e2e/framework/endpoints/wait.go diff --git a/test/e2e/framework/endpoints/BUILD b/test/e2e/framework/endpoints/BUILD index 2310197e48c..43020ee8a4b 100644 --- a/test/e2e/framework/endpoints/BUILD +++ b/test/e2e/framework/endpoints/BUILD @@ -2,19 +2,14 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "go_default_library", - srcs = [ - "ports.go", - "wait.go", - ], + srcs = ["ports.go"], importpath = "k8s.io/kubernetes/test/e2e/framework/endpoints", visibility = ["//visibility:public"], deps = [ "//staging/src/k8s.io/api/core/v1:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/client-go/kubernetes:go_default_library", - "//test/e2e/framework:go_default_library", "//test/e2e/framework/log:go_default_library", "//vendor/github.com/onsi/ginkgo:go_default_library", ], diff --git a/test/e2e/framework/endpoints/wait.go b/test/e2e/framework/endpoints/wait.go deleted file mode 100644 index b1d1c87b523..00000000000 --- a/test/e2e/framework/endpoints/wait.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -This soak tests places a specified number of pods on each node and then -repeatedly sends queries to a service running on these pods via -a serivce -*/ - -package endpoints - -import ( - "fmt" - "time" - - apierrs "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - clientset "k8s.io/client-go/kubernetes" - "k8s.io/kubernetes/test/e2e/framework" - e2elog "k8s.io/kubernetes/test/e2e/framework/log" -) - -const ( - // registerTimeout is how long to wait for an endpoint to be registered. - registerTimeout = time.Minute -) - -// WaitForEndpoint waits for the specified endpoint to be ready. -func WaitForEndpoint(c clientset.Interface, ns, name string) error { - for t := time.Now(); time.Since(t) < registerTimeout; time.Sleep(framework.Poll) { - endpoint, err := c.CoreV1().Endpoints(ns).Get(name, metav1.GetOptions{}) - if apierrs.IsNotFound(err) { - e2elog.Logf("Endpoint %s/%s is not ready yet", ns, name) - continue - } - framework.ExpectNoError(err, "Failed to get endpoints for %s/%s", ns, name) - if len(endpoint.Subsets) == 0 || len(endpoint.Subsets[0].Addresses) == 0 { - e2elog.Logf("Endpoint %s/%s is not ready yet", ns, name) - continue - } - return nil - } - return fmt.Errorf("failed to get endpoints for %s/%s", ns, name) -} diff --git a/test/e2e/network/proxy.go b/test/e2e/network/proxy.go index a0fb8614be8..05ad256d1b2 100644 --- a/test/e2e/network/proxy.go +++ b/test/e2e/network/proxy.go @@ -33,7 +33,6 @@ import ( "k8s.io/apimachinery/pkg/util/net" clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/test/e2e/framework" - "k8s.io/kubernetes/test/e2e/framework/endpoints" e2elog "k8s.io/kubernetes/test/e2e/framework/log" testutils "k8s.io/kubernetes/test/utils" imageutils "k8s.io/kubernetes/test/utils/image" @@ -165,7 +164,7 @@ var _ = SIGDescribe("Proxy", func() { framework.ExpectNoError(err) defer framework.DeleteRCAndWaitForGC(f.ClientSet, f.Namespace.Name, cfg.Name) - err = endpoints.WaitForEndpoint(f.ClientSet, f.Namespace.Name, service.Name) + err = waitForEndpoint(f.ClientSet, f.Namespace.Name, service.Name) framework.ExpectNoError(err) // table constructors @@ -322,3 +321,23 @@ func nodeProxyTest(f *framework.Framework, prefix, nodeDest string) { maxFailures := int(math.Floor(0.1 * float64(proxyAttempts))) gomega.Expect(serviceUnavailableErrors).To(gomega.BeNumerically("<", maxFailures)) } + +// waitForEndpoint waits for the specified endpoint to be ready. +func waitForEndpoint(c clientset.Interface, ns, name string) error { + // registerTimeout is how long to wait for an endpoint to be registered. + registerTimeout := time.Minute + for t := time.Now(); time.Since(t) < registerTimeout; time.Sleep(framework.Poll) { + endpoint, err := c.CoreV1().Endpoints(ns).Get(name, metav1.GetOptions{}) + if errors.IsNotFound(err) { + e2elog.Logf("Endpoint %s/%s is not ready yet", ns, name) + continue + } + framework.ExpectNoError(err, "Failed to get endpoints for %s/%s", ns, name) + if len(endpoint.Subsets) == 0 || len(endpoint.Subsets[0].Addresses) == 0 { + e2elog.Logf("Endpoint %s/%s is not ready yet", ns, name) + continue + } + return nil + } + return fmt.Errorf("failed to get endpoints for %s/%s", ns, name) +}