wait.go 1.8 KB

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