This fix tries to address an issue raised in #24090 where
the title field of `docker node ls` use NAME instead of
HOSTNAME. Yet the content of this field is actually
hostname.
The fix makes needed changes for the output of
`docker node ls`.
An additional test has been added to cover the change in
this fix.
This fix fixes #24090.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| ... | ... |
@@ -74,16 +74,12 @@ func printTable(out io.Writer, nodes []swarm.Node, info types.Info) {
|
| 74 | 74 |
// Ignore flushing errors |
| 75 | 75 |
defer writer.Flush() |
| 76 | 76 |
|
| 77 |
- fmt.Fprintf(writer, listItemFmt, "ID", "NAME", "MEMBERSHIP", "STATUS", "AVAILABILITY", "MANAGER STATUS") |
|
| 77 |
+ fmt.Fprintf(writer, listItemFmt, "ID", "HOSTNAME", "MEMBERSHIP", "STATUS", "AVAILABILITY", "MANAGER STATUS") |
|
| 78 | 78 |
for _, node := range nodes {
|
| 79 |
- name := node.Spec.Name |
|
| 79 |
+ name := node.Description.Hostname |
|
| 80 | 80 |
availability := string(node.Spec.Availability) |
| 81 | 81 |
membership := string(node.Spec.Membership) |
| 82 | 82 |
|
| 83 |
- if name == "" {
|
|
| 84 |
- name = node.Description.Hostname |
|
| 85 |
- } |
|
| 86 |
- |
|
| 87 | 83 |
reachability := "" |
| 88 | 84 |
if node.ManagerStatus != nil {
|
| 89 | 85 |
if node.ManagerStatus.Leader {
|
| ... | ... |
@@ -5,6 +5,7 @@ package main |
| 5 | 5 |
import ( |
| 6 | 6 |
"encoding/json" |
| 7 | 7 |
"io/ioutil" |
| 8 |
+ "strings" |
|
| 8 | 9 |
"time" |
| 9 | 10 |
|
| 10 | 11 |
"github.com/docker/docker/pkg/integration/checker" |
| ... | ... |
@@ -158,3 +159,13 @@ func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *check.C) {
|
| 158 | 158 |
// restart for teardown |
| 159 | 159 |
c.Assert(d.Start(), checker.IsNil) |
| 160 | 160 |
} |
| 161 |
+ |
|
| 162 |
+// Test case for #24090 |
|
| 163 |
+func (s *DockerSwarmSuite) TestSwarmNodeListHostname(c *check.C) {
|
|
| 164 |
+ d := s.AddDaemon(c, true, true) |
|
| 165 |
+ |
|
| 166 |
+ // The first line should contain "HOSTNAME" |
|
| 167 |
+ out, err := d.Cmd("node", "ls")
|
|
| 168 |
+ c.Assert(err, checker.IsNil) |
|
| 169 |
+ c.Assert(strings.Split(out, "\n")[0], checker.Contains, "HOSTNAME") |
|
| 170 |
+} |