diff --git a/cmd/minikube/cmd/dashboard.go b/cmd/minikube/cmd/dashboard.go index a082abee0a..bcf01fa318 100644 --- a/cmd/minikube/cmd/dashboard.go +++ b/cmd/minikube/cmd/dashboard.go @@ -53,7 +53,7 @@ var dashboardCmd = &cobra.Command{ os.Exit(1) } - urls, err := cluster.GetServiceURLs(api, namespace, service, nil) + urls, err := cluster.GetServiceURLsForService(api, namespace, service, nil) if err != nil { fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, "Check that minikube is running.") diff --git a/cmd/minikube/cmd/service.go b/cmd/minikube/cmd/service.go index 452db6b182..30d96678a4 100644 --- a/cmd/minikube/cmd/service.go +++ b/cmd/minikube/cmd/service.go @@ -76,7 +76,7 @@ var serviceCmd = &cobra.Command{ os.Exit(1) } - urls, err := cluster.GetServiceURLs(api, namespace, service, serviceURLTemplate) + urls, err := cluster.GetServiceURLsForService(api, namespace, service, serviceURLTemplate) if err != nil { fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, "Check that minikube is running and that you have specified the correct namespace (-n flag).") diff --git a/cmd/minikube/cmd/service_list.go b/cmd/minikube/cmd/service_list.go index 2c5a1c0e32..e867b1d4dc 100644 --- a/cmd/minikube/cmd/service_list.go +++ b/cmd/minikube/cmd/service_list.go @@ -19,6 +19,7 @@ package cmd import ( "fmt" "os" + "strings" "github.com/docker/machine/libmachine" "github.com/olekukonko/tablewriter" @@ -48,7 +49,12 @@ var serviceListCmd = &cobra.Command{ var data [][]string for _, serviceURL := range serviceURLs { - data = append(data, []string{serviceURL.Namespace, serviceURL.Name, serviceURL.URL}) + if len(serviceURL.URLs) == 0 { + data = append(data, []string{serviceURL.Namespace, serviceURL.Name, "No node port"}) + } else { + data = append(data, []string{serviceURL.Namespace, serviceURL.Name, strings.Join(serviceURL.URLs, "\n")}) + } + } table := tablewriter.NewWriter(os.Stdout) diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index d6911b1e39..070d3f4bf9 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -515,7 +515,7 @@ type ipPort struct { Port int32 } -func GetServiceURLs(api libmachine.API, namespace, service string, t *template.Template) ([]string, error) { +func GetServiceURLsForService(api libmachine.API, namespace, service string, t *template.Template) ([]string, error) { host, err := CheckIfApiExistsAndLoad(api) if err != nil { return nil, errors.Wrap(err, "Error checking if api exist and loading it") @@ -596,7 +596,9 @@ func getServicePortsFromServiceGetter(services serviceGetter, service string) ([ var nodePorts []int32 if len(svc.Spec.Ports) > 0 { for _, port := range svc.Spec.Ports { - nodePorts = append(nodePorts, port.NodePort) + if port.NodePort > 0 { + nodePorts = append(nodePorts, port.NodePort) + } } } if len(nodePorts) == 0 { @@ -637,7 +639,7 @@ func EnsureMinikubeRunningOrExit(api libmachine.API, exitStatus int) { type ServiceURL struct { Namespace string Name string - URL string + URLs []string } type ServiceURLs []ServiceURL @@ -668,15 +670,15 @@ func GetServiceURLs(api libmachine.API, namespace string, t *template.Template) var serviceURLs []ServiceURL for _, svc := range svcs.Items { - url, err := getServiceURLWithClient(client, ip, svc.Namespace, svc.Name, t) + urls, err := getServiceURLsWithClient(client, ip, svc.Namespace, svc.Name, t) if err != nil { if _, ok := err.(MissingNodePortError); ok { - serviceURLs = append(serviceURLs, ServiceURL{Namespace: svc.Namespace, Name: svc.Name, URL: "No node port"}) + serviceURLs = append(serviceURLs, ServiceURL{Namespace: svc.Namespace, Name: svc.Name}) continue } return nil, err } - serviceURLs = append(serviceURLs, ServiceURL{Namespace: svc.Namespace, Name: svc.Name, URL: url}) + serviceURLs = append(serviceURLs, ServiceURL{Namespace: svc.Namespace, Name: svc.Name, URLs: urls}) } return serviceURLs, nil