Merge pull request #45474 from xiangpengzhao/fix-port-none

Automatic merge from submit-queue (batch tested with PRs 41903, 45311, 45474, 45472, 45501)

Display <none> when port is empty.

**What this PR does / why we need it**:
If container ports are not specified, `kubectl describe` displays `<none>` instead of empty.

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

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-05-08 15:46:39 -07:00 committed by GitHub
commit d092fc546b

View File

@ -1072,10 +1072,14 @@ func describeContainerBasicInfo(container api.Container, status api.ContainerSta
portString := describeContainerPorts(container.Ports) portString := describeContainerPorts(container.Ports)
if strings.Contains(portString, ",") { if strings.Contains(portString, ",") {
w.Write(LEVEL_2, "Ports:\t%s\n", portString) w.Write(LEVEL_2, "Ports:\t%s\n", portString)
} else {
if len(portString) == 0 {
w.Write(LEVEL_2, "Port:\t<none>\n")
} else { } else {
w.Write(LEVEL_2, "Port:\t%s\n", portString) w.Write(LEVEL_2, "Port:\t%s\n", portString)
} }
} }
}
func describeContainerPorts(cPorts []api.ContainerPort) string { func describeContainerPorts(cPorts []api.ContainerPort) string {
ports := make([]string, 0, len(cPorts)) ports := make([]string, 0, len(cPorts))