Merge pull request #25042 from tiborvass/carry-24492
Carry 24492: Remove swarm inspect and use info instead
This commit is contained in:
commit
9ee430fcf5
9 changed files with 33 additions and 65 deletions
|
@ -25,7 +25,6 @@ func NewSwarmCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|||
newJoinTokenCommand(dockerCli),
|
||||
newUpdateCommand(dockerCli),
|
||||
newLeaveCommand(dockerCli),
|
||||
newInspectCommand(dockerCli),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
package swarm
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/docker/docker/api/client"
|
||||
"github.com/docker/docker/api/client/inspect"
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type inspectOptions struct {
|
||||
format string
|
||||
}
|
||||
|
||||
func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
|
||||
var opts inspectOptions
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "inspect [OPTIONS]",
|
||||
Short: "Inspect the swarm",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runInspect(dockerCli, opts)
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
|
||||
client := dockerCli.Client()
|
||||
ctx := context.Background()
|
||||
|
||||
swarm, err := client.SwarmInspect(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
getRef := func(_ string) (interface{}, []byte, error) {
|
||||
return swarm, nil, nil
|
||||
}
|
||||
|
||||
return inspect.Inspect(dockerCli.Out(), []string{""}, opts.format, getRef)
|
||||
}
|
|
@ -3,6 +3,7 @@ package system
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
|
@ -30,7 +31,8 @@ func NewInfoCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|||
}
|
||||
|
||||
func runInfo(dockerCli *client.DockerCli) error {
|
||||
info, err := dockerCli.Client().Info(context.Background())
|
||||
ctx := context.Background()
|
||||
info, err := dockerCli.Client().Info(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -83,8 +85,19 @@ func runInfo(dockerCli *client.DockerCli) error {
|
|||
}
|
||||
fmt.Fprintf(dockerCli.Out(), " Is Manager: %v\n", info.Swarm.ControlAvailable)
|
||||
if info.Swarm.ControlAvailable {
|
||||
fmt.Fprintf(dockerCli.Out(), " ClusterID: %s\n", info.Swarm.Cluster.ID)
|
||||
fmt.Fprintf(dockerCli.Out(), " Managers: %d\n", info.Swarm.Managers)
|
||||
fmt.Fprintf(dockerCli.Out(), " Nodes: %d\n", info.Swarm.Nodes)
|
||||
fmt.Fprintf(dockerCli.Out(), " Orchestration:\n")
|
||||
fmt.Fprintf(dockerCli.Out(), " Task History Retention Limit: %d\n", info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit)
|
||||
fmt.Fprintf(dockerCli.Out(), " Raft:\n")
|
||||
fmt.Fprintf(dockerCli.Out(), " Snapshot interval: %d\n", info.Swarm.Cluster.Spec.Raft.SnapshotInterval)
|
||||
fmt.Fprintf(dockerCli.Out(), " Heartbeat tick: %d\n", info.Swarm.Cluster.Spec.Raft.HeartbeatTick)
|
||||
fmt.Fprintf(dockerCli.Out(), " Election tick: %d\n", info.Swarm.Cluster.Spec.Raft.ElectionTick)
|
||||
fmt.Fprintf(dockerCli.Out(), " Dispatcher:\n")
|
||||
fmt.Fprintf(dockerCli.Out(), " Heartbeat period: %s\n", units.HumanDuration(time.Duration(info.Swarm.Cluster.Spec.Dispatcher.HeartbeatPeriod)))
|
||||
fmt.Fprintf(dockerCli.Out(), " CA configuration:\n")
|
||||
fmt.Fprintf(dockerCli.Out(), " Expiry duration: %s\n", units.HumanDuration(info.Swarm.Cluster.Spec.CAConfig.NodeCertExpiry))
|
||||
}
|
||||
fmt.Fprintf(dockerCli.Out(), " Node Address: %s\n", info.Swarm.NodeAddr)
|
||||
}
|
||||
|
|
|
@ -729,6 +729,11 @@ func (c *Cluster) Info() types.Info {
|
|||
|
||||
if c.isActiveManager() {
|
||||
info.ControlAvailable = true
|
||||
swarm, err := c.Inspect()
|
||||
if err != nil {
|
||||
info.Error = err.Error()
|
||||
}
|
||||
info.Cluster = swarm
|
||||
if r, err := c.client.ListNodes(ctx, &swarmapi.ListNodesRequest{}); err == nil {
|
||||
info.Nodes = len(r.Nodes)
|
||||
for _, n := range r.Nodes {
|
||||
|
|
|
@ -60,7 +60,7 @@ clone git golang.org/x/net 2beffdc2e92c8a3027590f898fe88f69af48a3f8 https://gith
|
|||
clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
|
||||
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
|
||||
clone git github.com/docker/go-connections fa2850ff103453a9ad190da0df0af134f0314b3d
|
||||
clone git github.com/docker/engine-api 53b6b19ee622c8584c28fdde0e3893383b290da3
|
||||
clone git github.com/docker/engine-api a52656d77f09d394104c1639824eada038bfdb89
|
||||
clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
|
||||
clone git github.com/imdario/mergo 0.2.1
|
||||
|
||||
|
|
|
@ -246,18 +246,22 @@ func (d *SwarmDaemon) listServices(c *check.C) []swarm.Service {
|
|||
return services
|
||||
}
|
||||
|
||||
func (d *SwarmDaemon) updateSwarm(c *check.C, f ...specConstructor) {
|
||||
func (d *SwarmDaemon) getSwarm(c *check.C) swarm.Swarm {
|
||||
var sw swarm.Swarm
|
||||
status, out, err := d.SockRequest("GET", "/swarm", nil)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
||||
c.Assert(json.Unmarshal(out, &sw), checker.IsNil)
|
||||
return sw
|
||||
}
|
||||
|
||||
func (d *SwarmDaemon) updateSwarm(c *check.C, f ...specConstructor) {
|
||||
sw := d.getSwarm(c)
|
||||
for _, fn := range f {
|
||||
fn(&sw.Spec)
|
||||
}
|
||||
url := fmt.Sprintf("/swarm/update?version=%d", sw.Version.Index)
|
||||
status, out, err = d.SockRequest("POST", url, sw.Spec)
|
||||
status, out, err := d.SockRequest("POST", url, sw.Spec)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -17,12 +16,8 @@ func (s *DockerSwarmSuite) TestSwarmUpdate(c *check.C) {
|
|||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
getSpec := func() swarm.Spec {
|
||||
out, err := d.Cmd("swarm", "inspect")
|
||||
c.Assert(err, checker.IsNil)
|
||||
var sw []swarm.Swarm
|
||||
c.Assert(json.Unmarshal([]byte(out), &sw), checker.IsNil)
|
||||
c.Assert(len(sw), checker.Equals, 1)
|
||||
return sw[0].Spec
|
||||
sw := d.getSwarm(c)
|
||||
return sw.Spec
|
||||
}
|
||||
|
||||
out, err := d.Cmd("swarm", "update", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s")
|
||||
|
@ -44,12 +39,8 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) {
|
|||
d := s.AddDaemon(c, false, false)
|
||||
|
||||
getSpec := func() swarm.Spec {
|
||||
out, err := d.Cmd("swarm", "inspect")
|
||||
c.Assert(err, checker.IsNil)
|
||||
var sw []swarm.Swarm
|
||||
c.Assert(json.Unmarshal([]byte(out), &sw), checker.IsNil)
|
||||
c.Assert(len(sw), checker.Equals, 1)
|
||||
return sw[0].Spec
|
||||
sw := d.getSwarm(c)
|
||||
return sw.Spec
|
||||
}
|
||||
|
||||
out, err := d.Cmd("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s")
|
||||
|
|
|
@ -118,6 +118,8 @@ type Info struct {
|
|||
RemoteManagers []Peer
|
||||
Nodes int
|
||||
Managers int
|
||||
|
||||
Cluster Swarm
|
||||
}
|
||||
|
||||
// Peer represents a peer.
|
||||
|
|
|
@ -256,6 +256,7 @@ type Info struct {
|
|||
Runtimes map[string]Runtime
|
||||
DefaultRuntime string
|
||||
Swarm swarm.Info
|
||||
LiveRestore bool
|
||||
}
|
||||
|
||||
// PluginsInfo is a temp struct holding Plugins name
|
||||
|
|
Loading…
Add table
Reference in a new issue