mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #77156 from draveness/feature/refactor-util-endpoints
refactor: move wait for endpoints to new pkg
This commit is contained in:
commit
306740f81c
@ -149,6 +149,7 @@ filegroup(
|
|||||||
"//test/e2e/framework/auth:all-srcs",
|
"//test/e2e/framework/auth:all-srcs",
|
||||||
"//test/e2e/framework/config:all-srcs",
|
"//test/e2e/framework/config:all-srcs",
|
||||||
"//test/e2e/framework/deployment:all-srcs",
|
"//test/e2e/framework/deployment:all-srcs",
|
||||||
|
"//test/e2e/framework/endpoints:all-srcs",
|
||||||
"//test/e2e/framework/ginkgowrapper:all-srcs",
|
"//test/e2e/framework/ginkgowrapper:all-srcs",
|
||||||
"//test/e2e/framework/gpu:all-srcs",
|
"//test/e2e/framework/gpu:all-srcs",
|
||||||
"//test/e2e/framework/ingress:all-srcs",
|
"//test/e2e/framework/ingress:all-srcs",
|
||||||
|
28
test/e2e/framework/endpoints/BUILD
Normal file
28
test/e2e/framework/endpoints/BUILD
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["wait.go"],
|
||||||
|
importpath = "k8s.io/kubernetes/test/e2e/framework/endpoints",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"//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/client-go/kubernetes:go_default_library",
|
||||||
|
"//test/e2e/framework:go_default_library",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "package-srcs",
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "all-srcs",
|
||||||
|
srcs = [":package-srcs"],
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
56
test/e2e/framework/endpoints/wait.go
Normal file
56
test/e2e/framework/endpoints/wait.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
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) {
|
||||||
|
framework.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 {
|
||||||
|
framework.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)
|
||||||
|
}
|
@ -158,8 +158,6 @@ const (
|
|||||||
podRespondingTimeout = 15 * time.Minute
|
podRespondingTimeout = 15 * time.Minute
|
||||||
// ServiceRespondingTimeout is how long to wait for a service to be responding.
|
// ServiceRespondingTimeout is how long to wait for a service to be responding.
|
||||||
ServiceRespondingTimeout = 2 * time.Minute
|
ServiceRespondingTimeout = 2 * time.Minute
|
||||||
// EndpointRegisterTimeout is how long to wait for an endpoint to be registered.
|
|
||||||
EndpointRegisterTimeout = time.Minute
|
|
||||||
|
|
||||||
// ClaimProvisionTimeout is how long claims have to become dynamically provisioned.
|
// ClaimProvisionTimeout is how long claims have to become dynamically provisioned.
|
||||||
ClaimProvisionTimeout = 5 * time.Minute
|
ClaimProvisionTimeout = 5 * time.Minute
|
||||||
@ -1748,25 +1746,6 @@ func countEndpointsNum(e *v1.Endpoints) int {
|
|||||||
return num
|
return num
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) < EndpointRegisterTimeout; time.Sleep(Poll) {
|
|
||||||
endpoint, err := c.CoreV1().Endpoints(ns).Get(name, metav1.GetOptions{})
|
|
||||||
if apierrs.IsNotFound(err) {
|
|
||||||
Logf("Endpoint %s/%s is not ready yet", ns, name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
ExpectNoError(err, "Failed to get endpoints for %s/%s", ns, name)
|
|
||||||
if len(endpoint.Subsets) == 0 || len(endpoint.Subsets[0].Addresses) == 0 {
|
|
||||||
Logf("Endpoint %s/%s is not ready yet", ns, name)
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fmt.Errorf("Failed to get endpoints for %s/%s", ns, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodProxyResponseChecker is a context for checking pods responses by issuing GETs to them (via the API
|
// PodProxyResponseChecker is a context for checking pods responses by issuing GETs to them (via the API
|
||||||
// proxy) and verifying that they answer with their own pod name.
|
// proxy) and verifying that they answer with their own pod name.
|
||||||
type PodProxyResponseChecker struct {
|
type PodProxyResponseChecker struct {
|
||||||
|
@ -59,6 +59,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/cloud-provider:go_default_library",
|
"//staging/src/k8s.io/cloud-provider:go_default_library",
|
||||||
"//test/e2e/framework:go_default_library",
|
"//test/e2e/framework:go_default_library",
|
||||||
"//test/e2e/framework/auth:go_default_library",
|
"//test/e2e/framework/auth:go_default_library",
|
||||||
|
"//test/e2e/framework/endpoints:go_default_library",
|
||||||
"//test/e2e/framework/ingress:go_default_library",
|
"//test/e2e/framework/ingress:go_default_library",
|
||||||
"//test/e2e/framework/providers/gce:go_default_library",
|
"//test/e2e/framework/providers/gce:go_default_library",
|
||||||
"//test/e2e/network/scale:go_default_library",
|
"//test/e2e/network/scale:go_default_library",
|
||||||
|
@ -26,13 +26,14 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
"k8s.io/apimachinery/pkg/util/net"
|
"k8s.io/apimachinery/pkg/util/net"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
|
"k8s.io/kubernetes/test/e2e/framework/endpoints"
|
||||||
testutils "k8s.io/kubernetes/test/utils"
|
testutils "k8s.io/kubernetes/test/utils"
|
||||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||||
|
|
||||||
@ -161,7 +162,7 @@ var _ = SIGDescribe("Proxy", func() {
|
|||||||
Expect(framework.RunRC(cfg)).NotTo(HaveOccurred())
|
Expect(framework.RunRC(cfg)).NotTo(HaveOccurred())
|
||||||
defer framework.DeleteRCAndWaitForGC(f.ClientSet, f.Namespace.Name, cfg.Name)
|
defer framework.DeleteRCAndWaitForGC(f.ClientSet, f.Namespace.Name, cfg.Name)
|
||||||
|
|
||||||
Expect(framework.WaitForEndpoint(f.ClientSet, f.Namespace.Name, service.Name)).NotTo(HaveOccurred())
|
Expect(endpoints.WaitForEndpoint(f.ClientSet, f.Namespace.Name, service.Name)).NotTo(HaveOccurred())
|
||||||
|
|
||||||
// table constructors
|
// table constructors
|
||||||
// Try proxying through the service and directly to through the pod.
|
// Try proxying through the service and directly to through the pod.
|
||||||
|
Loading…
Reference in New Issue
Block a user