util.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright 2014 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. package network
  14. import (
  15. "bytes"
  16. "fmt"
  17. "time"
  18. "k8s.io/apimachinery/pkg/util/wait"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. e2enetwork "k8s.io/kubernetes/test/e2e/framework/network"
  21. )
  22. // GetHTTPContent returns the content of the given url by HTTP.
  23. func GetHTTPContent(host string, port int, timeout time.Duration, url string) bytes.Buffer {
  24. var body bytes.Buffer
  25. if pollErr := wait.PollImmediate(framework.Poll, timeout, func() (bool, error) {
  26. result := e2enetwork.PokeHTTP(host, port, url, nil)
  27. if result.Status == e2enetwork.HTTPSuccess {
  28. body.Write(result.Body)
  29. return true, nil
  30. }
  31. return false, nil
  32. }); pollErr != nil {
  33. framework.Failf("Could not reach HTTP service through %v:%v%v after %v: %v", host, port, url, timeout, pollErr)
  34. }
  35. return body
  36. }
  37. // DescribeSvc logs the output of kubectl describe svc for the given namespace
  38. func DescribeSvc(ns string) {
  39. framework.Logf("\nOutput of kubectl describe svc:\n")
  40. desc, _ := framework.RunKubectl(
  41. ns, "describe", "svc", fmt.Sprintf("--namespace=%v", ns))
  42. framework.Logf(desc)
  43. }