Przeglądaj źródła

Merge pull request #24159 from yongtang/24090-docker-node-list-hostname

Use HOSTNAME in the output of `docker node ls`
Alexander Morozov 9 lat temu
rodzic
commit
0f687aafaf
2 zmienionych plików z 13 dodań i 6 usunięć
  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")
+}