Skip to content

Commit da1d411

Browse files
authored
Merge pull request #6879 from prasadkatti/populate_target_port_in_svc_list
service list: populate target port
2 parents 5535242 + b7463fd commit da1d411

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

cmd/minikube/cmd/service_list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ var serviceListCmd = &cobra.Command{
5252
if len(serviceURL.URLs) == 0 {
5353
data = append(data, []string{serviceURL.Namespace, serviceURL.Name, "No node port"})
5454
} else {
55+
servicePortNames := strings.Join(serviceURL.PortNames, "\n")
5556
serviceURLs := strings.Join(serviceURL.URLs, "\n")
5657

5758
// if we are running Docker on OSX we empty the internal service URLs
5859
if runtime.GOOS == "darwin" && co.Config.Driver == oci.Docker {
5960
serviceURLs = ""
6061
}
6162

62-
data = append(data, []string{serviceURL.Namespace, serviceURL.Name, "", serviceURLs})
63+
data = append(data, []string{serviceURL.Namespace, serviceURL.Name, servicePortNames, serviceURLs})
6364
}
6465
}
6566

pkg/minikube/service/service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"net/url"
2424
"os"
25+
"strconv"
2526
"strings"
2627
"text/template"
2728
"time"
@@ -196,6 +197,13 @@ func printURLsForService(c typed_core.CoreV1Interface, ip, service, namespace st
196197
urls := []string{}
197198
portNames := []string{}
198199
for _, port := range svc.Spec.Ports {
200+
201+
if port.Name != "" {
202+
m[port.TargetPort.IntVal] = fmt.Sprintf("%s/%d", port.Name, port.Port)
203+
} else {
204+
m[port.TargetPort.IntVal] = strconv.Itoa(int(port.Port))
205+
}
206+
199207
if port.NodePort > 0 {
200208
var doc bytes.Buffer
201209
err = t.Execute(&doc, struct {

pkg/minikube/service/service_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,17 @@ var defaultNamespaceServiceInterface = &MockServiceInterface{
134134
Spec: core.ServiceSpec{
135135
Ports: []core.ServicePort{
136136
{
137+
Name: "port1",
137138
NodePort: int32(1111),
139+
Port: int32(11111),
138140
TargetPort: intstr.IntOrString{
139141
IntVal: int32(11111),
140142
},
141143
},
142144
{
145+
Name: "port2",
143146
NodePort: int32(2222),
147+
Port: int32(22222),
144148
TargetPort: intstr.IntOrString{
145149
IntVal: int32(22222),
146150
},
@@ -324,7 +328,7 @@ func TestPrintURLsForService(t *testing.T) {
324328
serviceName: "mock-dashboard",
325329
namespace: "default",
326330
tmpl: template.Must(template.New("svc-arbitrary-template").Parse("{{.Name}}={{.IP}}:{{.Port}}")),
327-
expectedOutput: []string{"port1=127.0.0.1:1111", "port2=127.0.0.1:2222"},
331+
expectedOutput: []string{"port1/11111=127.0.0.1:1111", "port2/22222=127.0.0.1:2222"},
328332
},
329333
{
330334
description: "empty slice for no node ports",
@@ -452,7 +456,7 @@ func TestGetServiceURLs(t *testing.T) {
452456
Namespace: "default",
453457
Name: "mock-dashboard",
454458
URLs: []string{"http://127.0.0.1:1111", "http://127.0.0.1:2222"},
455-
PortNames: []string{"port1", "port2"},
459+
PortNames: []string{"port1/11111", "port2/22222"},
456460
},
457461
{
458462
Namespace: "default",

0 commit comments

Comments
 (0)