Merge pull request #57507 from dixudx/describe_pod_hostport

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

add hostPorts to pod describer

**What this PR does / why we need it**:
Missing `HostPorts` when describing pods

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:
/assign @mengqiy @shiywang
**Release note**:

```release-note
None
```
This commit is contained in:
Kubernetes Submit Queue 2018-01-16 10:26:19 -08:00 committed by GitHub
commit ff626a35fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1315,11 +1315,13 @@ func describeContainerBasicInfo(container api.Container, status api.ContainerSta
if strings.Contains(portString, ",") {
w.Write(LEVEL_2, "Ports:\t%s\n", portString)
} else {
if len(portString) == 0 {
w.Write(LEVEL_2, "Port:\t<none>\n")
} else {
w.Write(LEVEL_2, "Port:\t%s\n", portString)
}
w.Write(LEVEL_2, "Port:\t%s\n", stringOrNone(portString))
}
hostPortString := describeContainerHostPorts(container.Ports)
if strings.Contains(hostPortString, ",") {
w.Write(LEVEL_2, "Host Ports:\t%s\n", hostPortString)
} else {
w.Write(LEVEL_2, "Host Port:\t%s\n", stringOrNone(hostPortString))
}
}
@ -1331,6 +1333,14 @@ func describeContainerPorts(cPorts []api.ContainerPort) string {
return strings.Join(ports, ", ")
}
func describeContainerHostPorts(cPorts []api.ContainerPort) string {
ports := make([]string, 0, len(cPorts))
for _, cPort := range cPorts {
ports = append(ports, fmt.Sprintf("%d/%s", cPort.HostPort, cPort.Protocol))
}
return strings.Join(ports, ", ")
}
func describeContainerCommand(container api.Container, w PrefixWriter) {
if len(container.Command) > 0 {
w.Write(LEVEL_2, "Command:\n")