Skip to content

Commit 306740f

Browse files
authored
Merge pull request kubernetes#77156 from draveness/feature/refactor-util-endpoints
refactor: move wait for endpoints to new pkg
2 parents 0f7d124 + 774c15f commit 306740f

File tree

6 files changed

+89
-23
lines changed

6 files changed

+89
-23
lines changed

test/e2e/framework/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ filegroup(
149149
"//test/e2e/framework/auth:all-srcs",
150150
"//test/e2e/framework/config:all-srcs",
151151
"//test/e2e/framework/deployment:all-srcs",
152+
"//test/e2e/framework/endpoints:all-srcs",
152153
"//test/e2e/framework/ginkgowrapper:all-srcs",
153154
"//test/e2e/framework/gpu:all-srcs",
154155
"//test/e2e/framework/ingress:all-srcs",

test/e2e/framework/endpoints/BUILD

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["wait.go"],
6+
importpath = "k8s.io/kubernetes/test/e2e/framework/endpoints",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
10+
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
11+
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
12+
"//test/e2e/framework:go_default_library",
13+
],
14+
)
15+
16+
filegroup(
17+
name = "package-srcs",
18+
srcs = glob(["**"]),
19+
tags = ["automanaged"],
20+
visibility = ["//visibility:private"],
21+
)
22+
23+
filegroup(
24+
name = "all-srcs",
25+
srcs = [":package-srcs"],
26+
tags = ["automanaged"],
27+
visibility = ["//visibility:public"],
28+
)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
This soak tests places a specified number of pods on each node and then
19+
repeatedly sends queries to a service running on these pods via
20+
a serivce
21+
*/
22+
23+
package endpoints
24+
25+
import (
26+
"fmt"
27+
"time"
28+
29+
apierrs "k8s.io/apimachinery/pkg/api/errors"
30+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+
clientset "k8s.io/client-go/kubernetes"
32+
"k8s.io/kubernetes/test/e2e/framework"
33+
)
34+
35+
const (
36+
// registerTimeout is how long to wait for an endpoint to be registered.
37+
registerTimeout = time.Minute
38+
)
39+
40+
// WaitForEndpoint waits for the specified endpoint to be ready.
41+
func WaitForEndpoint(c clientset.Interface, ns, name string) error {
42+
for t := time.Now(); time.Since(t) < registerTimeout; time.Sleep(framework.Poll) {
43+
endpoint, err := c.CoreV1().Endpoints(ns).Get(name, metav1.GetOptions{})
44+
if apierrs.IsNotFound(err) {
45+
framework.Logf("Endpoint %s/%s is not ready yet", ns, name)
46+
continue
47+
}
48+
framework.ExpectNoError(err, "Failed to get endpoints for %s/%s", ns, name)
49+
if len(endpoint.Subsets) == 0 || len(endpoint.Subsets[0].Addresses) == 0 {
50+
framework.Logf("Endpoint %s/%s is not ready yet", ns, name)
51+
continue
52+
}
53+
return nil
54+
}
55+
return fmt.Errorf("failed to get endpoints for %s/%s", ns, name)
56+
}

test/e2e/framework/util.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ const (
158158
podRespondingTimeout = 15 * time.Minute
159159
// ServiceRespondingTimeout is how long to wait for a service to be responding.
160160
ServiceRespondingTimeout = 2 * time.Minute
161-
// EndpointRegisterTimeout is how long to wait for an endpoint to be registered.
162-
EndpointRegisterTimeout = time.Minute
163161

164162
// ClaimProvisionTimeout is how long claims have to become dynamically provisioned.
165163
ClaimProvisionTimeout = 5 * time.Minute
@@ -1748,25 +1746,6 @@ func countEndpointsNum(e *v1.Endpoints) int {
17481746
return num
17491747
}
17501748

1751-
// WaitForEndpoint waits for the specified endpoint to be ready.
1752-
func WaitForEndpoint(c clientset.Interface, ns, name string) error {
1753-
for t := time.Now(); time.Since(t) < EndpointRegisterTimeout; time.Sleep(Poll) {
1754-
endpoint, err := c.CoreV1().Endpoints(ns).Get(name, metav1.GetOptions{})
1755-
if apierrs.IsNotFound(err) {
1756-
Logf("Endpoint %s/%s is not ready yet", ns, name)
1757-
continue
1758-
}
1759-
ExpectNoError(err, "Failed to get endpoints for %s/%s", ns, name)
1760-
if len(endpoint.Subsets) == 0 || len(endpoint.Subsets[0].Addresses) == 0 {
1761-
Logf("Endpoint %s/%s is not ready yet", ns, name)
1762-
continue
1763-
} else {
1764-
return nil
1765-
}
1766-
}
1767-
return fmt.Errorf("Failed to get endpoints for %s/%s", ns, name)
1768-
}
1769-
17701749
// PodProxyResponseChecker is a context for checking pods responses by issuing GETs to them (via the API
17711750
// proxy) and verifying that they answer with their own pod name.
17721751
type PodProxyResponseChecker struct {

test/e2e/network/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ go_library(
5959
"//staging/src/k8s.io/cloud-provider:go_default_library",
6060
"//test/e2e/framework:go_default_library",
6161
"//test/e2e/framework/auth:go_default_library",
62+
"//test/e2e/framework/endpoints:go_default_library",
6263
"//test/e2e/framework/ingress:go_default_library",
6364
"//test/e2e/framework/providers/gce:go_default_library",
6465
"//test/e2e/network/scale:go_default_library",

test/e2e/network/proxy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ import (
2626
"sync"
2727
"time"
2828

29-
"k8s.io/api/core/v1"
29+
v1 "k8s.io/api/core/v1"
3030
"k8s.io/apimachinery/pkg/api/errors"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/util/intstr"
3333
"k8s.io/apimachinery/pkg/util/net"
3434
clientset "k8s.io/client-go/kubernetes"
3535
"k8s.io/kubernetes/test/e2e/framework"
36+
"k8s.io/kubernetes/test/e2e/framework/endpoints"
3637
testutils "k8s.io/kubernetes/test/utils"
3738
imageutils "k8s.io/kubernetes/test/utils/image"
3839

@@ -161,7 +162,7 @@ var _ = SIGDescribe("Proxy", func() {
161162
Expect(framework.RunRC(cfg)).NotTo(HaveOccurred())
162163
defer framework.DeleteRCAndWaitForGC(f.ClientSet, f.Namespace.Name, cfg.Name)
163164

164-
Expect(framework.WaitForEndpoint(f.ClientSet, f.Namespace.Name, service.Name)).NotTo(HaveOccurred())
165+
Expect(endpoints.WaitForEndpoint(f.ClientSet, f.Namespace.Name, service.Name)).NotTo(HaveOccurred())
165166

166167
// table constructors
167168
// Try proxying through the service and directly to through the pod.

0 commit comments

Comments
 (0)