Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack rm should accept multiple arguments #32110

Merged

Conversation

adshmh
Copy link
Contributor

@adshmh adshmh commented Mar 26, 2017

stack rm should accept multiple arguments (addresses item 2 from #30977).

Signed-off-by: Arash Deshmeh adeshmeh@ca.ibm.com

- What I did
Added the ability to supply multiple stack labels to the 'docker stack rm' command.

- How I did it
A loop is added to the stack rm code to go through the list of stacks specified as input. Unit tests were also added to cover the stack rm code.

- How to verify it

  1. Deploy multiple stacks, e.g.:

$ docker stack deploy -c ./stack.yml stack1
Creating network stack1_frontend
Creating network stack1_default
Creating service stack1_redis
Creating service stack1_lb
Creating service stack1_web

$ docker stack deploy -c ./stack.yml stack2
Creating network stack2_default
Creating network stack2_frontend
Creating service stack2_redis
Creating service stack2_lb
Creating service stack2_web

  1. Remove the stacks with a single command:

$ docker stack remove stack1 stack2
Removing service stack1_redis
Removing service stack1_web
Removing service stack1_lb
Removing network stack1_default
Removing network stack1_frontend
Removing service stack2_web
Removing service stack2_redis
Removing service stack2_lb
Removing network stack2_frontend
Removing network stack2_default

- Description for the changelog
'docker stack rm' command now accepts multiple stack labels as input.

- A picture of a cute animal (not mandatory but encouraged)

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design LGTM, just wonder if we should do the same as container rm or not ? (i.e. print errors at the end, but try to delete all namespace — if the first one fail, we keep the error, and return it at the end, but we still try to remove the 2nd one).

stack rm should accept multiple labels

stack rm should accept multiple arguments or stack rm should accept multiple namespaces. Label is not the right term here I feel.

/cc @thaJeztah @dnephin

@adshmh
Copy link
Contributor Author

adshmh commented Mar 26, 2017

If the design is acceptable, would it be a good idea if I submit separate PRs to add unit tests that cover more of the stack package?

@vdemeester
Copy link
Member

@adshmh ❤️ for more unit tests. I don't think there is too much need to create a separate PR, could just be in another commit, but it's not a strong opinion from my part (so feel free to do what you feel makes more sence 😉 ).


func namespaceFromFilters(filters filters.Args) string {
label := filters.Get("label")[0]
return strings.TrimPrefix(label, convert.LabelNamespace+"=")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use convert.Namespace().Descope() in cli/compose/convert/compose.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. Since getServices() adds convert.LabelNamespace to the filters, I need to trim it and then use Namespace().Descope() in belongToNamespace(). Would this be acceptable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right. Descope doesn't do what you want. It's good as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I left it as-is in the PR update.


func serviceFromName(name string) swarm.Service {
return swarm.Service{
ID: name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ID string is not going to be same as the name. To avoid tests that pass incorrectly maybe we should append pr prepend some other string (ID-) so that if we differentiate between the ID and the name.

@adshmh adshmh changed the title stack rm should accept multiple labels stack rm should accept multiple arguments Mar 27, 2017
@adshmh
Copy link
Contributor Author

adshmh commented Mar 27, 2017

Design LGTM, just wonder if we should do the same as container rm or not ? (i.e. print errors at the end, but try to delete all namespace — if the first one fail, we keep the error, and return it at the end, but we still try to remove the 2nd one).

Thanks, I will change the PR so it attempts to remove all specified namespaces.

@adshmh adshmh force-pushed the 30977-stack-rm-should-accept-multiple-labels branch 2 times, most recently from fdceedd to 9ba614f Compare March 28, 2017 06:49
@thaJeztah
Copy link
Member

Oh, looks like this needs a rebase now @adshmh 😢

@adshmh adshmh force-pushed the 30977-stack-rm-should-accept-multiple-labels branch from ad2cd5e to 8bf1f4e Compare March 28, 2017 16:07
@adshmh
Copy link
Contributor Author

adshmh commented Mar 28, 2017

The Windows build error does not seem to be due to the changes made by the PR:

16:08:37 re-exec error: exit status 1: output: time="2017-03-28T16:08:30Z" level=error msg="hcsshim::ImportLayer failed in Win32: There is not enough space on the disk. (0x70) layerId=\\?\D:\control\windowsfilter\93ab77eb1901ff76798674e483a2eef0930a5c5c1f0f1ecfc8e36a15ea5a38a8 flavour=1 folder=d:\temp\hcs746907439"
16:08:37 hcsshim::ImportLayer failed in Win32: There is not enough space on the disk. (0x70) layerId=\?\D:\control\windowsfilter\93ab77eb1901ff76798674e483a2eef0930a5c5c1f0f1ecfc8e36a15ea5a38a8 flavour=1 folder=d:\temp\hcs746907439
16:08:37
16:08:37
16:08:37 ERROR: Failed 'ERROR: Failed to build image from Dockerfile.windows' at 03/28/2017 16:08:37

@thaJeztah
Copy link
Member

Yup, that's not related, looks like a node was out of disk space. I restarted the build 👍

@thaJeztah
Copy link
Member

@vdemeester @dnephin ptal 👍

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐯

Copy link
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vdemeester
Copy link
Member

/cc @thaJeztah for docs review 👼

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I left some comments inline; it would also be good to have one or two examples added to the CLI docs; https://github.com/docker/docker/blob/master/docs/reference/commandline/stack_rm.md

The examples section should have its own header, you can use the rm.md page for inspiration 😄 https://github.com/docker/docker/blob/master/docs/reference/commandline/rm.md#examples

}

func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
var opts removeOptions

cmd := &cobra.Command{
Use: "rm STACK",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update the usage description to;

Use:   "rm STACK [STACK...]",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. I will update the PR.

}

func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
var opts removeOptions

cmd := &cobra.Command{
Use: "rm STACK",
Aliases: []string{"remove", "down"},
Short: "Remove the stack",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to;

Short:   "Remove one or more stacks",

to be consistent with other commands that accept multiple options

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I will change that line.
Perhaps I need to create a PR on docker/docker.github.io as well, after the changes to the CLI docs are approved?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the CLI reference documentation on docs.docker.com is generated from this output, in combination with the markdown in this repo (#32110 (review)), so perhaps no changes are needed, but you could check if there's other markdown files (here, and in the docs repo) that include the USAGE output

@thaJeztah
Copy link
Member

Also ping @albers @sdurrheimer (this may need an update to the completion scripts)

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
@adshmh adshmh force-pushed the 30977-stack-rm-should-accept-multiple-labels branch from 8bf1f4e to ff0899a Compare April 5, 2017 05:14
@adshmh
Copy link
Contributor Author

adshmh commented Apr 5, 2017

I have updated the PR with changes to the stack rm command's usage message and the CLI docs.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@MHBauer
Copy link
Contributor

MHBauer commented Apr 10, 2017

Wow, nice test, good docs update.

@vieux
Copy link
Contributor

vieux commented Apr 11, 2017

LGTM

@vieux vieux merged commit 3a9572c into moby:master Apr 11, 2017
@GordonTheTurtle GordonTheTurtle added this to the 17.05.0 milestone Apr 11, 2017
dnephin pushed a commit to dnephin/docker that referenced this pull request Apr 17, 2017
…t-multiple-labels

stack rm should accept multiple arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants