Explorar el Código

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 4bc91ceeb750db6a6270b2f1821cb0b2f30117fc)
Yong Tang hace 9 años
padre
commit
b34706b152
Se han modificado 2 ficheros con 13 adiciones y 6 borrados
  1. 2 6
      api/client/node/list.go
  2. 11 0
      integration-cli/docker_cli_swarm_test.go

+ 2 - 6
api/client/node/list.go

@@ -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 {

+ 11 - 0
integration-cli/docker_cli_swarm_test.go

@@ -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")
+}