Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service list cmd: display target port and name #6879

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/minikube/cmd/service_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ 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
if runtime.GOOS == "darwin" && cfg.Driver == oci.Docker {
serviceURLs = ""
}

data = append(data, []string{serviceURL.Namespace, serviceURL.Name, "", serviceURLs})
data = append(data, []string{serviceURL.Namespace, serviceURL.Name, servicePortNames, serviceURLs})
Copy link
Member

@josedonizetti josedonizetti Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we print for minikube service list must be consistent with what we print for minikube service <service-name>, so if we are printing name || port there, the same should be done here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both minikube service list and minikube service <service-name> eventually call printURLsForService which is where I am making these changes. So the results should be consistent. Maybe the variable name needs to change?

}
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/minikube/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"net/url"
"os"
"strconv"
"strings"
"text/template"
"time"
Expand Down Expand Up @@ -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] = fmt.Sprintf("%s/%d", port.Name, port.Port)
} else {
m[port.TargetPort.IntVal] = strconv.Itoa(int(port.Port))
}

if port.NodePort > 0 {
var doc bytes.Buffer
err = t.Execute(&doc, struct {
Expand Down
8 changes: 6 additions & 2 deletions pkg/minikube/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down