Skip to content

Commit

Permalink
Add information for Manager Addresses in the output of docker info
Browse files Browse the repository at this point in the history
As is specified in 28018, it would be useful to know the manager's addresses
even in a worker node. This is especially useful when there are many
worker nodes in a big cluster.

The information is available in `info.Swarm.RemoteManagers`.

This fix add the information of `Manager Addresses` to the output
of `docker info`, to explicitly show it.

A test has been added for this fix.

This fix fixes 28018.

Signed-off-by: Yong Tang <[email protected]>
  • Loading branch information
yongtang committed Nov 11, 2016
1 parent 0bb6bac commit 828bd44
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package system

import (
"fmt"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -131,6 +132,17 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error {
}
}
fmt.Fprintf(dockerCli.Out(), " Node Address: %s\n", info.Swarm.NodeAddr)
managers := []string{}
for _, entry := range info.Swarm.RemoteManagers {
managers = append(managers, entry.Addr)
}
if len(managers) > 0 {
sort.Strings(managers)
fmt.Fprintf(dockerCli.Out(), " Manager Addresses:\n")
for _, entry := range managers {
fmt.Fprintf(dockerCli.Out(), " %s\n", entry)
}
}
}

if len(info.Runtimes) > 0 {
Expand Down
21 changes: 21 additions & 0 deletions integration-cli/docker_cli_swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,3 +1051,24 @@ func (s *DockerSwarmSuite) TestExtraHosts(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
}

func (s *DockerSwarmSuite) TestSwarmManagerAddress(c *check.C) {
d1 := s.AddDaemon(c, true, true)
d2 := s.AddDaemon(c, true, false)
d3 := s.AddDaemon(c, true, false)

// Manager Addresses will always show Node 1's address
expectedOutput := fmt.Sprintf("Manager Addresses:\n 127.0.0.1:%d\n", d1.port)

out, err := d1.Cmd("info")
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, expectedOutput)

out, err = d2.Cmd("info")
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, expectedOutput)

out, err = d3.Cmd("info")
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, expectedOutput)
}

0 comments on commit 828bd44

Please sign in to comment.