提交 5bc95b8d 编写于 作者: D dlorenc 提交者: GitHub

Merge pull request #776 from jimmidyson/fix-dashboard-url

Fix dashboard command and integration test
...@@ -19,6 +19,7 @@ package cmd ...@@ -19,6 +19,7 @@ package cmd
import ( import (
"fmt" "fmt"
"os" "os"
"text/template"
"time" "time"
"github.com/docker/machine/libmachine" "github.com/docker/machine/libmachine"
...@@ -53,7 +54,7 @@ var dashboardCmd = &cobra.Command{ ...@@ -53,7 +54,7 @@ var dashboardCmd = &cobra.Command{
os.Exit(1) os.Exit(1)
} }
urls, err := cluster.GetServiceURLsForService(api, namespace, service, nil) urls, err := cluster.GetServiceURLsForService(api, namespace, service, template.Must(template.New("dashboardServiceFormat").Parse(defaultServiceFormatTemplate)))
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, "Check that minikube is running.") fmt.Fprintln(os.Stderr, "Check that minikube is running.")
......
...@@ -96,12 +96,14 @@ var serviceCmd = &cobra.Command{ ...@@ -96,12 +96,14 @@ var serviceCmd = &cobra.Command{
}, },
} }
const defaultServiceFormatTemplate = "http://{{.IP}}:{{.Port}}"
func init() { func init() {
serviceCmd.Flags().StringVarP(&namespace, "namespace", "n", "default", "The service namespace") serviceCmd.Flags().StringVarP(&namespace, "namespace", "n", "default", "The service namespace")
serviceCmd.Flags().BoolVar(&serviceURLMode, "url", false, "Display the kubernetes service URL in the CLI instead of opening it in the default browser") serviceCmd.Flags().BoolVar(&serviceURLMode, "url", false, "Display the kubernetes service URL in the CLI instead of opening it in the default browser")
serviceCmd.Flags().BoolVar(&https, "https", false, "Open the service URL with https instead of http") serviceCmd.Flags().BoolVar(&https, "https", false, "Open the service URL with https instead of http")
serviceCmd.PersistentFlags().StringVar(&serviceURLFormat, "format", "http://{{.IP}}:{{.Port}}", "Format to output service URL in. This format will be applied to each url individually and they will be printed one at a time.") serviceCmd.PersistentFlags().StringVar(&serviceURLFormat, "format", defaultServiceFormatTemplate, "Format to output service URL in. This format will be applied to each url individually and they will be printed one at a time.")
RootCmd.AddCommand(serviceCmd) RootCmd.AddCommand(serviceCmd)
} }
......
...@@ -20,6 +20,8 @@ package integration ...@@ -20,6 +20,8 @@ package integration
import ( import (
"fmt" "fmt"
"net"
"net/url"
"strings" "strings"
"testing" "testing"
"time" "time"
...@@ -60,7 +62,7 @@ func TestAddons(t *testing.T) { ...@@ -60,7 +62,7 @@ func TestAddons(t *testing.T) {
} }
} }
return &commonutil.RetriableError{Err: fmt.Errorf("Addon manager not found. Found pods: %s", pods)} return &commonutil.RetriableError{Err: fmt.Errorf("Addon manager not found. Found pods: %v", pods)}
} }
if err := commonutil.RetryAfter(20, checkAddon, 5*time.Second); err != nil { if err := commonutil.RetryAfter(20, checkAddon, 5*time.Second); err != nil {
...@@ -89,11 +91,11 @@ func TestDashboard(t *testing.T) { ...@@ -89,11 +91,11 @@ func TestDashboard(t *testing.T) {
} }
if rc.Status.Replicas != rc.Status.FullyLabeledReplicas { if rc.Status.Replicas != rc.Status.FullyLabeledReplicas {
return &commonutil.RetriableError{Err: fmt.Errorf("Not enough pods running. Expected %s, got %s.", rc.Status.Replicas, rc.Status.FullyLabeledReplicas)} return &commonutil.RetriableError{Err: fmt.Errorf("Not enough pods running. Expected %d, got %d.", rc.Status.Replicas, rc.Status.FullyLabeledReplicas)}
} }
if svc.Spec.Ports[0].NodePort != 30000 { if svc.Spec.Ports[0].NodePort != 30000 {
return fmt.Errorf("Dashboard is not exposed on port {}", svc.Spec.Ports[0].NodePort) return fmt.Errorf("Dashboard is exposed on wrong port, expected 30000, actual %d", svc.Spec.Ports[0].NodePort)
} }
return nil return nil
...@@ -102,4 +104,20 @@ func TestDashboard(t *testing.T) { ...@@ -102,4 +104,20 @@ func TestDashboard(t *testing.T) {
if err := commonutil.RetryAfter(10, checkDashboard, 5*time.Second); err != nil { if err := commonutil.RetryAfter(10, checkDashboard, 5*time.Second); err != nil {
t.Fatalf("Dashboard is unhealthy: %s", err) t.Fatalf("Dashboard is unhealthy: %s", err)
} }
dashboardURL := minikubeRunner.RunCommand("dashboard --url", true)
u, err := url.Parse(strings.TrimSpace(dashboardURL))
if err != nil {
t.Fatalf("failed to parse dashboard URL %s: %v", dashboardURL, err)
}
if u.Scheme != "http" {
t.Fatalf("wrong scheme in dashboard URL, expected http, actual %s", u.Scheme)
}
_, port, err := net.SplitHostPort(u.Host)
if err != nil {
t.Fatalf("failed to split dashboard host %s: %v", u.Host, err)
}
if port != "30000" {
t.Fatalf("Dashboard is exposed on wrong port, expected 30000, actual %s", port)
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册