From 9f41fd42e1cd78a285383f494000bc6f95f94e1a Mon Sep 17 00:00:00 2001 From: Prasad Katti Date: Tue, 3 Mar 2020 22:23:52 -0800 Subject: [PATCH 1/3] populate target port in service list --- cmd/minikube/cmd/service_list.go | 3 ++- pkg/minikube/service/service.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/service_list.go b/cmd/minikube/cmd/service_list.go index 9d86d5a8b8ca..7dddcd826cc0 100644 --- a/cmd/minikube/cmd/service_list.go +++ b/cmd/minikube/cmd/service_list.go @@ -66,6 +66,7 @@ var serviceListCmd = &cobra.Command{ if len(serviceURL.URLs) == 0 { data = append(data, []string{serviceURL.Namespace, serviceURL.Name, "No node port"}) } else { + servicePortNames := strings.Join(serviceURL.PortNames, "\n") serviceURLs := strings.Join(serviceURL.URLs, "\n") // if we are running Docker on OSX we empty the internal service URLs @@ -73,7 +74,7 @@ var serviceListCmd = &cobra.Command{ serviceURLs = "" } - data = append(data, []string{serviceURL.Namespace, serviceURL.Name, "", serviceURLs}) + data = append(data, []string{serviceURL.Namespace, serviceURL.Name, servicePortNames, serviceURLs}) } } diff --git a/pkg/minikube/service/service.go b/pkg/minikube/service/service.go index 3f3c159cd4e6..16579e31b30e 100644 --- a/pkg/minikube/service/service.go +++ b/pkg/minikube/service/service.go @@ -22,6 +22,7 @@ import ( "io" "net/url" "os" + "strconv" "strings" "text/template" "time" @@ -196,6 +197,13 @@ func printURLsForService(c typed_core.CoreV1Interface, ip, service, namespace st urls := []string{} portNames := []string{} for _, port := range svc.Spec.Ports { + + if port.Name != "" { + m[port.TargetPort.IntVal] = port.Name + } else { + m[port.TargetPort.IntVal] = strconv.Itoa(int(port.Port)) + } + if port.NodePort > 0 { var doc bytes.Buffer err = t.Execute(&doc, struct { From d19f27a3c293ca63b42ad550d39e9faa4f57abb4 Mon Sep 17 00:00:00 2001 From: Prasad Katti Date: Wed, 4 Mar 2020 13:48:23 -0800 Subject: [PATCH 2/3] Add name/port instead of just the name for the target port --- pkg/minikube/service/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/service/service.go b/pkg/minikube/service/service.go index 16579e31b30e..3cd16f79e725 100644 --- a/pkg/minikube/service/service.go +++ b/pkg/minikube/service/service.go @@ -199,7 +199,7 @@ func printURLsForService(c typed_core.CoreV1Interface, ip, service, namespace st for _, port := range svc.Spec.Ports { if port.Name != "" { - m[port.TargetPort.IntVal] = port.Name + m[port.TargetPort.IntVal] = fmt.Sprintf("%s/%d", port.Name, port.Port) } else { m[port.TargetPort.IntVal] = strconv.Itoa(int(port.Port)) } From b7463fda7eda282d3b806c6a6c35b2ff2841301c Mon Sep 17 00:00:00 2001 From: Prasad Katti Date: Wed, 4 Mar 2020 22:38:37 -0800 Subject: [PATCH 3/3] fix minikube service tests --- pkg/minikube/service/service_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/minikube/service/service_test.go b/pkg/minikube/service/service_test.go index 47fd341f42e9..59a32f8454de 100644 --- a/pkg/minikube/service/service_test.go +++ b/pkg/minikube/service/service_test.go @@ -134,13 +134,17 @@ var defaultNamespaceServiceInterface = &MockServiceInterface{ Spec: core.ServiceSpec{ Ports: []core.ServicePort{ { + Name: "port1", NodePort: int32(1111), + Port: int32(11111), TargetPort: intstr.IntOrString{ IntVal: int32(11111), }, }, { + Name: "port2", NodePort: int32(2222), + Port: int32(22222), TargetPort: intstr.IntOrString{ IntVal: int32(22222), }, @@ -324,7 +328,7 @@ func TestPrintURLsForService(t *testing.T) { serviceName: "mock-dashboard", namespace: "default", tmpl: template.Must(template.New("svc-arbitrary-template").Parse("{{.Name}}={{.IP}}:{{.Port}}")), - expectedOutput: []string{"port1=127.0.0.1:1111", "port2=127.0.0.1:2222"}, + expectedOutput: []string{"port1/11111=127.0.0.1:1111", "port2/22222=127.0.0.1:2222"}, }, { description: "empty slice for no node ports", @@ -452,7 +456,7 @@ func TestGetServiceURLs(t *testing.T) { Namespace: "default", Name: "mock-dashboard", URLs: []string{"http://127.0.0.1:1111", "http://127.0.0.1:2222"}, - PortNames: []string{"port1", "port2"}, + PortNames: []string{"port1/11111", "port2/22222"}, }, { Namespace: "default",