dashboard.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright 2015 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 e2e
  14. import (
  15. "net/http"
  16. "time"
  17. "k8s.io/kubernetes/pkg/api"
  18. "k8s.io/kubernetes/pkg/labels"
  19. "k8s.io/kubernetes/pkg/util/wait"
  20. "k8s.io/kubernetes/test/e2e/framework"
  21. . "github.com/onsi/ginkgo"
  22. . "github.com/onsi/gomega"
  23. )
  24. var _ = framework.KubeDescribe("Kubernetes Dashboard", func() {
  25. const (
  26. uiServiceName = "kubernetes-dashboard"
  27. uiAppName = uiServiceName
  28. uiNamespace = api.NamespaceSystem
  29. serverStartTimeout = 1 * time.Minute
  30. )
  31. f := framework.NewDefaultFramework(uiServiceName)
  32. It("should check that the kubernetes-dashboard instance is alive", func() {
  33. By("Checking whether the kubernetes-dashboard service exists.")
  34. err := framework.WaitForService(f.Client, uiNamespace, uiServiceName, true, framework.Poll, framework.ServiceStartTimeout)
  35. Expect(err).NotTo(HaveOccurred())
  36. By("Checking to make sure the kubernetes-dashboard pods are running")
  37. selector := labels.SelectorFromSet(labels.Set(map[string]string{"k8s-app": uiAppName}))
  38. err = framework.WaitForPodsWithLabelRunning(f.Client, uiNamespace, selector)
  39. Expect(err).NotTo(HaveOccurred())
  40. By("Checking to make sure we get a response from the kubernetes-dashboard.")
  41. err = wait.Poll(framework.Poll, serverStartTimeout, func() (bool, error) {
  42. var status int
  43. proxyRequest, errProxy := framework.GetServicesProxyRequest(f.Client, f.Client.Get())
  44. if errProxy != nil {
  45. framework.Logf("Get services proxy request failed: %v", errProxy)
  46. }
  47. // Query against the proxy URL for the kube-ui service.
  48. err := proxyRequest.Namespace(uiNamespace).
  49. Name(uiServiceName).
  50. Timeout(framework.SingleCallTimeout).
  51. Do().
  52. StatusCode(&status).
  53. Error()
  54. if status != http.StatusOK {
  55. framework.Logf("Unexpected status from kubernetes-dashboard: %v", status)
  56. } else if err != nil {
  57. framework.Logf("Request to kube-ui failed: %v", err)
  58. }
  59. // Don't return err here as it aborts polling.
  60. return status == http.StatusOK, nil
  61. })
  62. Expect(err).NotTo(HaveOccurred())
  63. By("Checking that the ApiServer /ui endpoint redirects to a valid server.")
  64. var status int
  65. err = f.Client.Get().
  66. AbsPath("/ui").
  67. Timeout(framework.SingleCallTimeout).
  68. Do().
  69. StatusCode(&status).
  70. Error()
  71. Expect(err).NotTo(HaveOccurred())
  72. Expect(status).To(Equal(http.StatusOK), "Unexpected status from /ui")
  73. })
  74. })