Use HOSTNAME in the output of docker node ls
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>
(cherry picked from commit 4bc91ceeb7
)
This commit is contained in:
parent
b375ccfee7
commit
b34706b152
2 changed files with 13 additions and 6 deletions
|
@ -74,16 +74,12 @@ func printTable(out io.Writer, nodes []swarm.Node, info types.Info) {
|
|||
// Ignore flushing errors
|
||||
defer writer.Flush()
|
||||
|
||||
fmt.Fprintf(writer, listItemFmt, "ID", "NAME", "MEMBERSHIP", "STATUS", "AVAILABILITY", "MANAGER STATUS")
|
||||
fmt.Fprintf(writer, listItemFmt, "ID", "HOSTNAME", "MEMBERSHIP", "STATUS", "AVAILABILITY", "MANAGER STATUS")
|
||||
for _, node := range nodes {
|
||||
name := node.Spec.Name
|
||||
name := node.Description.Hostname
|
||||
availability := string(node.Spec.Availability)
|
||||
membership := string(node.Spec.Membership)
|
||||
|
||||
if name == "" {
|
||||
name = node.Description.Hostname
|
||||
}
|
||||
|
||||
reachability := ""
|
||||
if node.ManagerStatus != nil {
|
||||
if node.ManagerStatus.Leader {
|
||||
|
|
|
@ -5,6 +5,7 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
|
@ -158,3 +159,13 @@ func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *check.C) {
|
|||
// restart for teardown
|
||||
c.Assert(d.Start(), checker.IsNil)
|
||||
}
|
||||
|
||||
// Test case for #24090
|
||||
func (s *DockerSwarmSuite) TestSwarmNodeListHostname(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
// The first line should contain "HOSTNAME"
|
||||
out, err := d.Cmd("node", "ls")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.Split(out, "\n")[0], checker.Contains, "HOSTNAME")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue