Add Swarm management CLI commands #23363

Merged
merged 33 commits into from Jun 14, 2016

Projects

None yet
@dnephin
Member
dnephin commented Jun 8, 2016

As described in our ROADMAP.md, introduce new Swarm management commands to call to the corresponding API endpoints.

This PR is fully backward compatible (joining a Swarm is an optional feature of the Engine, and existing commands are not impacted)

@icecrime icecrime added this to the 1.12.0 milestone Jun 8, 2016
@aluzzardi aluzzardi commented on an outdated diff Jun 8, 2016
api/client/service/opts.go
+func (m *memBytes) Value() int64 {
+ return int64(*m)
+}
+
+type nanoCPUs int64
+
+func (c *nanoCPUs) String() string {
+ return strconv.FormatInt(c.Value(), 10)
+}
+
+func (c *nanoCPUs) Set(value string) error {
+ cpu, ok := new(big.Rat).SetString(value)
+ if !ok {
+ return fmt.Errorf("Failed to parse %v as a rational number", value)
+ }
+ *c = nanoCPUs(cpu.Mul(cpu, big.NewRat(1e9, 1)).Num().Int64())
@aluzzardi
aluzzardi Jun 8, 2016 Contributor

Before calling Int64(), you have to check IsInt() or return an error. This is to make sure there's no loss (user input is not below nanos).

@aluzzardi aluzzardi commented on the diff Jun 8, 2016
api/client/service/opts.go
+ // DefaultScale is the default scale to use for a replicated service
+ DefaultScale uint64 = 1
+)
+
+type int64Value interface {
+ Value() int64
+}
+
+type memBytes int64
+
+func (m *memBytes) String() string {
+ return strconv.FormatInt(m.Value(), 10)
+}
+
+func (m *memBytes) Set(value string) error {
+ val, err := units.RAMInBytes(value)
@aluzzardi
aluzzardi Jun 8, 2016 Contributor

Check err

@dnephin
dnephin Jun 8, 2016 Member

In what case would I need to check err here? We always return the err, so if there is an error it will be reported.

This is how all the types in pflag are implemented, ex: https://github.com/spf13/pflag/blob/master/int64.go#L16-L19

@aluzzardi
aluzzardi Jun 9, 2016 Contributor

Right - my bad!

@vdemeester vdemeester and 1 other commented on an outdated diff Jun 9, 2016
api/client/node/inspect.go
+ opts.nodeIds = args
+ return runInspect(dockerCli, opts)
+ },
+ }
+
+ flags := cmd.Flags()
+ flags.Bool("help", false, "Print usage")
+ flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
+ flags.BoolVarP(&opts.pretty, "pretty", "p", false, "Print the information in a human friendly format.")
+ return cmd
+}
+
+func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
+ client := dockerCli.Client()
+ getRef := func(ref string) (interface{}, []byte, error) {
+ ctx := context.Background()
@vdemeester
vdemeester Jun 9, 2016 Member

hum, should ctx declared in the upper block (alongside client) ?

@dnephin
dnephin Jun 9, 2016 Member

yup, fixed

@vdemeester vdemeester commented on an outdated diff Jun 9, 2016
api/client/node/list.go
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runList(dockerCli, opts)
+ },
+ }
+ flags := cmd.Flags()
+ flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
+ flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
+
+ return cmd
+}
+
+func runList(dockerCli *client.DockerCli, opts listOptions) error {
+ client := dockerCli.Client()
+
+ nodes, err := client.NodeList(
+ context.Background(),
@vdemeester
vdemeester Jun 9, 2016 Member

The context should be shared here :

ctx := context.Background()

nodes, err := client.NodeList(ctx, …)
// […]
info, err := client.Info(ctx)
// […]
@vdemeester vdemeester commented on an outdated diff Jun 9, 2016
api/client/node/remove.go
+func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command {
+ return &cobra.Command{
+ Use: "rm NODE [NODE...]",
+ Aliases: []string{"remove"},
+ Short: "Remove a node from the swarm",
+ Args: cli.RequiresMinArgs(1),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runRemove(dockerCli, args)
+ },
+ }
+}
+
+func runRemove(dockerCli *client.DockerCli, args []string) error {
+ client := dockerCli.Client()
+ for _, nodeID := range args {
+ err := client.NodeRemove(context.Background(), nodeID)
@vdemeester
vdemeester Jun 9, 2016 Member

Here too, context should be shared.

ctx := context.Background()
for _, nodeID := range args {
    err := client.NodeRemove(ctx, …)
    // […]
}
@dnephin
Member
dnephin commented Jun 9, 2016

Ok, those issues should be fixed.

@chanwit chanwit commented on an outdated diff Jun 10, 2016
api/client/node/promote.go
+import (
+ "fmt"
+
+ "github.com/docker/docker/api/client"
+ "github.com/docker/docker/cli"
+ "github.com/docker/engine-api/types/swarm"
+ "github.com/spf13/cobra"
+ "github.com/spf13/pflag"
+)
+
+func newPromoteCommand(dockerCli *client.DockerCli) *cobra.Command {
+ var flags *pflag.FlagSet
+
+ cmd := &cobra.Command{
+ Use: "promote NODE [NODE...]",
+ Short: "Promote a node as manager in the swarm",
@chanwit
chanwit Jun 10, 2016

Probably, "Promote a node to manager in the swarm"?

@chanwit chanwit commented on an outdated diff Jun 10, 2016
api/client/node/demote.go
+import (
+ "fmt"
+
+ "github.com/docker/docker/api/client"
+ "github.com/docker/docker/cli"
+ "github.com/docker/engine-api/types/swarm"
+ "github.com/spf13/cobra"
+ "github.com/spf13/pflag"
+)
+
+func newDemoteCommand(dockerCli *client.DockerCli) *cobra.Command {
+ var flags *pflag.FlagSet
+
+ cmd := &cobra.Command{
+ Use: "demote NODE [NODE...]",
+ Short: "Demote a node as manager in the swarm",
@chanwit
chanwit Jun 10, 2016

Shoud it be "Demote a node from manager in the swarm" ?

@vdemeester
Member

win2lin error is weird :

04:14:18 # github.com/docker/swarmkit/identity
04:14:18 vendor\src\github.com\docker\swarmkit\identity\randomid.go:54: nn.Text undefined (type big.Int has no field or method Text)
@thaJeztah
Member

@vdemeester it's because that CI is still on Go 1.5.4

@chanwit
chanwit commented Jun 12, 2016

Just let you know, I did a rebase on master with a small conflict at:
cli/usage.go.

Other than that it's just fine.

dnephin and others added some commits Jun 7, 2016
@dnephin @tonistiigi dnephin Add Swarm management CLI commands
As described in our ROADMAP.md, introduce new Swarm management commands
to call to the corresponding API endpoints.

This PR is fully backward compatible (joining a Swarm is an optional
feature of the Engine, and existing commands are not impacted).

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Victor Vieux <vieux@docker.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
bdcd802
@amitshukla @tonistiigi amitshukla CLI docs
Signed-off-by: Amit Shukla <amit.shukla@docker.com>
1cac395
@icecrime @tonistiigi icecrime Shorten `docker service` restart policy flags
Rename `--restart-policy-*` flags to `--restart-*` (e.g.,
`--restart-policy-delay` becomes `--restart-delay`).

Signed-off-by: Arnaud Porterie (icecrime) <arnaud.porterie@docker.com>
ab06a5b
@icecrime @tonistiigi icecrime Clarify services update policies
Rename `--updateconfig-*` to `--update-*` and improve help messages.

Signed-off-by: Arnaud Porterie (icecrime) <arnaud.porterie@docker.com>
0c84337
@vieux @tonistiigi vieux use ID for '*'
Signed-off-by: Victor Vieux <vieux@docker.com>
b301d2c
@vieux @tonistiigi vieux add CACertHash: cli
Signed-off-by: Victor Vieux <vieux@docker.com>
ddb578c
@tonistiigi tonistiigi Fix accept policy initialization
- Set secret when using default policy
- Always initialize policy for all roles

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
89a5556
@tonistiigi tonistiigi Update join command message
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
c5c1fc5
@dnephin @tonistiigi dnephin Fix CLI side of volume problem.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
713cbd8
@vieux @tonistiigi vieux update to newest engine-api (cli)
Signed-off-by: Victor Vieux <vieux@docker.com>
412aa1e
@icecrime @tonistiigi icecrime Rename `--port` to `--publish` in `docker service`
Rename `--port` to `--publish` for consistency between `docker service`
and `docker run`.

Signed-off-by: Arnaud Porterie (icecrime) <arnaud.porterie@docker.com>
d5745c8
@tonistiigi tonistiigi Fix RenameCheckNames test
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
6d35ce7
@dnephin @tonistiigi dnephin Fixes #273 - set command line args in args not command
Signed-off-by: Daniel Nephin <dnephin@docker.com>
f798f43
@dnephin @tonistiigi dnephin backport fixes from docker/docker PR comments.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
bc81ad5
@vieux @tonistiigi vieux upadate engine-api: cli
Signed-off-by: Victor Vieux <vieux@docker.com>
f6dd2a5
@icecrime @tonistiigi icecrime Pretty print strings on human-readable outputs
Capitalize first letter in output meant for human consumptions (e.g.,
`docker service ls`, or `docker node inspect --pretty`).

Signed-off-by: Arnaud Porterie (icecrime) <arnaud.porterie@docker.com>
fb33899
@icecrime @tonistiigi icecrime Fix incorrect `docker service inspect` help message
Signed-off-by: Arnaud Porterie (icecrime) <arnaud.porterie@docker.com>
5bd2b91
@vieux @tonistiigi vieux fix docker swarm inspect output on error
Signed-off-by: Victor Vieux <vieux@docker.com>
bee98b5
@vieux @tonistiigi vieux git rm reject.go
Signed-off-by: Victor Vieux <vieux@docker.com>
740a118
@vieux @tonistiigi vieux add -h back to inspect
Signed-off-by: Victor Vieux <vieux@docker.com>
2dac952
@vieux @tonistiigi vieux cli
Signed-off-by: Victor Vieux <vieux@docker.com>
3d7b63a
@vieux @tonistiigi vieux api
Signed-off-by: Victor Vieux <vieux@docker.com>
654bf01
@mavenugo @tonistiigi mavenugo swarm managed networks should me marked as "swarm" scoped (cli)
Signed-off-by: Madhu Venugopal <madhu@docker.com>
484b556
@icecrime @tonistiigi icecrime Add `docker service scale` command
Signed-off-by: Arnaud Porterie (icecrime) <arnaud.porterie@docker.com>
b3eefed
@mrjana @tonistiigi mrjana Vendoring libnetwork @892e1b9 (cli)
Adds overlay datapath security enhancement
Adds netlink performance enhancements
Bug fixes

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
8ae22c0
@dongluochen @tonistiigi dongluochen Upate auto-accept help text.
Signed-off-by: Dong Chen <dongluo.chen@docker.com>
b4ba9c6
@dnephin @tonistiigi dnephin Small UX improvements to 'docker service scale'
Signed-off-by: Daniel Nephin <dnephin@docker.com>
5d07eb3
@icecrime @tonistiigi icecrime Add missing newline
Signed-off-by: Arnaud Porterie (icecrime) <arnaud.porterie@docker.com>
9571a23
@cpuguy83 @tonistiigi cpuguy83 Fix scale pointer value in service inspect -p
Before this change, pretty output shows `859533555312` instead of `1`.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
5259aa0
@dperny @tonistiigi dperny Fix command not displaying in service ls.
Closes #396.

Signed-off-by: Drew Erny <drew.erny@docker.com>
dc0b20d
@dnephin @tonistiigi dnephin New format for setting mounts on a service.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
068354d
@dnephin @tonistiigi dnephin Upate from PR review.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
53c7216
@vieux @tonistiigi vieux fix rebase
Signed-off-by: Victor Vieux <vieux@docker.com>
6f5d29f
@icecrime
Member
icecrime commented Jun 14, 2016 edited

LGTM 💯

@vieux
Member
vieux commented Jun 14, 2016

LGTM 💯

@tiborvass
Contributor

LGTM

@icecrime
Member

CLI reference and docs will be completed in a followup 👍

@icecrime icecrime merged commit 229b279 into swarm-backend Jun 14, 2016

5 of 8 checks passed

documentation fail
Details
experimental Jenkins build Docker-PRs-experimental 19899 has failed
Details
gccgo Jenkins build Docker-PRs-gccgo 6766 is running
Details
docker/dco-signed All commits signed
Details
janky Jenkins build Docker-PRs 28693 has succeeded
Details
userns Jenkins build Docker-PRs-userns 10855 has succeeded
Details
win2lin Jenkins build Docker-PRs-Win2Lin 27279 has succeeded
Details
windowsTP5 Jenkins build Docker-PRs-WoW-TP5 3184 has succeeded
Details
@chanwit
chanwit commented Jun 14, 2016 edited

🎉 🎉

I love the new scale command.
Thank you guys. This is super awesome!!

@thaJeztah
Member

🐝 🐝 🎉

@runcom runcom deleted the swarm-cli branch Jun 15, 2016
@albers
Contributor
albers commented Jun 17, 2016

@thaJeztah This PR added reference pages for the swarm and node commands. But there are none for service yet. Is there some WIP?

@thaJeztah
Member

@albers correct, there's an issue for tracking this here; #23598

@albers
Contributor
albers commented Jun 17, 2016

@thaJeztah cool, thanks. I already dropped a note there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment