Merge pull request #34922 from zreigz/add-nodeport
Automatic merge from submit-queue Add NodePort value in kubectl output This PR enhances kubectl output after the command execution: `kubectl get svc`. It additionally shows the value of the NodePort. This PR is a response for this issue: https://github.com/kubernetes/kubernetes/issues/34100
This commit is contained in:
commit
10ebd65913
@ -1101,6 +1101,9 @@ func makePortString(ports []api.ServicePort) string {
|
|||||||
for ix := range ports {
|
for ix := range ports {
|
||||||
port := &ports[ix]
|
port := &ports[ix]
|
||||||
pieces[ix] = fmt.Sprintf("%d/%s", port.Port, port.Protocol)
|
pieces[ix] = fmt.Sprintf("%d/%s", port.Port, port.Protocol)
|
||||||
|
if port.NodePort > 0 {
|
||||||
|
pieces[ix] = fmt.Sprintf("%d:%d/%s", port.Port, port.NodePort, port.Protocol)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return strings.Join(pieces, ",")
|
return strings.Join(pieces, ",")
|
||||||
}
|
}
|
||||||
|
@ -1572,3 +1572,53 @@ func TestPrintPodShowLabels(t *testing.T) {
|
|||||||
buf.Reset()
|
buf.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrintService(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
service api.Service
|
||||||
|
expect string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
// Test name, cluster ip, port with protocol
|
||||||
|
api.Service{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: "test1"},
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
|
Type: api.ServiceTypeClusterIP,
|
||||||
|
Ports: []api.ServicePort{
|
||||||
|
{Protocol: "tcp",
|
||||||
|
Port: 2233},
|
||||||
|
},
|
||||||
|
ClusterIP: "0.0.0.0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"test1\t0.0.0.0\t<none>\t2233/tcp\t<unknown>\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Test name, cluster ip, port:nodePort with protocol
|
||||||
|
api.Service{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: "test2"},
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
|
Type: api.ServiceTypeClusterIP,
|
||||||
|
Ports: []api.ServicePort{
|
||||||
|
{Protocol: "tcp",
|
||||||
|
Port: 8888,
|
||||||
|
NodePort: 9999,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ClusterIP: "10.9.8.7",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"test2\t10.9.8.7\t<none>\t8888:9999/tcp\t<unknown>\n",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
for _, test := range tests {
|
||||||
|
printService(&test.service, buf, PrintOptions{false, false, false, false, true, false, false, "", []string{}})
|
||||||
|
// We ignore time
|
||||||
|
if buf.String() != test.expect {
|
||||||
|
t.Fatalf("Expected: %s, got: %s %d", test.expect, buf.String(), strings.Compare(test.expect, buf.String()))
|
||||||
|
}
|
||||||
|
buf.Reset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user