dashboard.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 ui
  14. import (
  15. "context"
  16. "net/http"
  17. "time"
  18. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  19. "k8s.io/apimachinery/pkg/labels"
  20. utilnet "k8s.io/apimachinery/pkg/util/net"
  21. "k8s.io/apimachinery/pkg/util/wait"
  22. "k8s.io/kubernetes/test/e2e/framework"
  23. e2eservice "k8s.io/kubernetes/test/e2e/framework/service"
  24. e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
  25. testutils "k8s.io/kubernetes/test/utils"
  26. "github.com/onsi/ginkgo"
  27. )
  28. var _ = SIGDescribe("Kubernetes Dashboard [Feature:Dashboard]", func() {
  29. ginkgo.BeforeEach(func() {
  30. // TODO(kubernetes/kubernetes#61559): Enable dashboard here rather than skip the test.
  31. e2eskipper.SkipIfProviderIs("gke")
  32. })
  33. const (
  34. uiServiceName = "kubernetes-dashboard"
  35. uiAppName = uiServiceName
  36. uiNamespace = metav1.NamespaceSystem
  37. serverStartTimeout = 1 * time.Minute
  38. )
  39. f := framework.NewDefaultFramework(uiServiceName)
  40. ginkgo.It("should check that the kubernetes-dashboard instance is alive", func() {
  41. ginkgo.By("Checking whether the kubernetes-dashboard service exists.")
  42. err := framework.WaitForService(f.ClientSet, uiNamespace, uiServiceName, true, framework.Poll, framework.ServiceStartTimeout)
  43. framework.ExpectNoError(err)
  44. ginkgo.By("Checking to make sure the kubernetes-dashboard pods are running")
  45. selector := labels.SelectorFromSet(labels.Set(map[string]string{"k8s-app": uiAppName}))
  46. err = testutils.WaitForPodsWithLabelRunning(f.ClientSet, uiNamespace, selector)
  47. framework.ExpectNoError(err)
  48. ginkgo.By("Checking to make sure we get a response from the kubernetes-dashboard.")
  49. err = wait.Poll(framework.Poll, serverStartTimeout, func() (bool, error) {
  50. var status int
  51. proxyRequest, errProxy := e2eservice.GetServicesProxyRequest(f.ClientSet, f.ClientSet.CoreV1().RESTClient().Get())
  52. if errProxy != nil {
  53. framework.Logf("Get services proxy request failed: %v", errProxy)
  54. }
  55. ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
  56. defer cancel()
  57. // Query against the proxy URL for the kubernetes-dashboard service.
  58. err := proxyRequest.Namespace(uiNamespace).
  59. Name(utilnet.JoinSchemeNamePort("https", uiServiceName, "")).
  60. Timeout(framework.SingleCallTimeout).
  61. Do(ctx).
  62. StatusCode(&status).
  63. Error()
  64. if err != nil {
  65. if ctx.Err() != nil {
  66. framework.Failf("Request to kubernetes-dashboard failed: %v", err)
  67. return true, err
  68. }
  69. framework.Logf("Request to kubernetes-dashboard failed: %v", err)
  70. } else if status != http.StatusOK {
  71. framework.Logf("Unexpected status from kubernetes-dashboard: %v", status)
  72. }
  73. // Don't return err here as it aborts polling.
  74. return status == http.StatusOK, nil
  75. })
  76. framework.ExpectNoError(err)
  77. })
  78. })