|
| 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 | +} |
0 commit comments