-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add support for --detach flag in stack rm #4259
Add support for --detach flag in stack rm #4259
Conversation
var numberedStates = map[swarm.TaskState]int64{ | ||
swarm.TaskStateNew: 1, | ||
swarm.TaskStateAllocated: 2, | ||
swarm.TaskStatePending: 3, | ||
swarm.TaskStateAssigned: 4, | ||
swarm.TaskStateAccepted: 5, | ||
swarm.TaskStatePreparing: 6, | ||
swarm.TaskStateReady: 7, | ||
swarm.TaskStateStarting: 8, | ||
swarm.TaskStateRunning: 9, | ||
swarm.TaskStateComplete: 10, | ||
swarm.TaskStateShutdown: 11, | ||
swarm.TaskStateFailed: 12, | ||
swarm.TaskStateRejected: 13, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rely on importing SwarmKit here instead of incorporating magic enums.
Also it's unclear if this logic even belongs on the client; this looks dangerously close to leaking concerns across layers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @neersighted, thanks a lot for getting back to me!
This map was inspired by the progress code for Service:
cli/cli/command/service/progress/progress.go
Lines 23 to 44 in 5be2139
var ( | |
numberedStates = map[swarm.TaskState]int64{ | |
swarm.TaskStateNew: 1, | |
swarm.TaskStateAllocated: 2, | |
swarm.TaskStatePending: 3, | |
swarm.TaskStateAssigned: 4, | |
swarm.TaskStateAccepted: 5, | |
swarm.TaskStatePreparing: 6, | |
swarm.TaskStateReady: 7, | |
swarm.TaskStateStarting: 8, | |
swarm.TaskStateRunning: 9, | |
// The following states are not actually shown in progress | |
// output, but are used internally for ordering. | |
swarm.TaskStateComplete: 10, | |
swarm.TaskStateShutdown: 11, | |
swarm.TaskStateFailed: 12, | |
swarm.TaskStateRejected: 13, | |
} | |
longestState int | |
) |
cli/cli/command/service/progress/progress.go
Lines 66 to 68 in 5be2139
func terminalState(state swarm.TaskState) bool { | |
return numberedStates[state] > numberedStates[swarm.TaskStateRunning] | |
} |
An alternative would be to create a set with all the terminal states and check against that instead.
By design, the server instantly acknowledges any changes (e.g. removing a stack) and then the action is asynchronous. Thus, I believe that this logic belongs to the client, as the client is the one that waits for the actions to complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason Swarm states are numbered like they are is so that intermediate states can be inserted at any time without disrupting the ordering of states committed to the object store already. If the code handling states isn't persistent, then there's no such concern. If we ever added an intermediate state, we can just renumber all of these harmlessly.
Looks fine to me. |
074f182
to
08204d8
Compare
Hey @thaJeztah and @neersighted Is there anything else I can do in order to move this forward? |
bda291b
to
153b2f3
Compare
cli/command/stack/remove.go
Outdated
@@ -27,5 +27,8 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command { | |||
return completeNames(dockerCli)(cmd, args, toComplete) | |||
}, | |||
} | |||
|
|||
flags := cmd.Flags() | |||
flags.BoolVarP(&opts.Detach, "detach", "d", true, "Exit immediately instead of waiting for the stack tasks to converge") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flags.BoolVarP(&opts.Detach, "detach", "d", true, "Exit immediately instead of waiting for the stack tasks to converge") | |
flags.BoolVarP(&opts.Detach, "detach", "d", true, "Do not wait for stack removal") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it in b040ca8!
153b2f3
to
b040ca8
Compare
It looks like this is changing the default behavior of |
Oh nevermind I see the default for the flag is 🤔 |
@cpuguy83 Thank you for your feedback! I see where you're coming from regarding the If the plan is to switch the default behavior of I hope this clears things up and takes us closer to also merging #4258 and closing #373 😄 /cc @thaJeztah |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #4259 +/- ##
==========================================
- Coverage 61.18% 61.13% -0.06%
==========================================
Files 287 287
Lines 20112 20136 +24
==========================================
+ Hits 12306 12310 +4
- Misses 6912 6933 +21
+ Partials 894 893 -1 |
|
||
| Name | Type | Default | Description | | ||
|:-----------------|:-----|:--------|:------------------------------| | ||
| `-d`, `--detach` | | | Do not wait for stack removal | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting; for some reason it doesn't show the default here 🤔
--help
shows the correct output, but the markdown generator doesn't 🤔 Any ideas @crazy-max ?
./build/docker stack rm --help
Usage: docker stack rm [OPTIONS] STACK [STACK...]
Remove one or more stacks
Aliases:
docker stack rm, docker stack remove, docker stack down
Options:
-d, --detach Do not wait for stack removal (default true)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to not show default as this is a bool flag anyway? (like --pull
or --push
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my bad this is true by default so opt-out flag right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@crazy-max Yes, it's true by default and the user can use --detach=false
if they want to wait for stack removal to complete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same for service create/update
where we already have implemented this flag
cli/docs/reference/commandline/service_create.md
Lines 6 to 16 in 79fa65e
### Options | |
| Name | Type | Default | Description | | |
|:----------------------------------------------------|:------------------|:-------------|:----------------------------------------------------------------------------------------------------| | |
| `--cap-add` | `list` | | Add Linux capabilities | | |
| `--cap-drop` | `list` | | Drop Linux capabilities | | |
| [`--config`](#config) | `config` | | Specify configurations to expose to the service | | |
| [`--constraint`](#constraint) | `list` | | Placement constraints | | |
| `--container-label` | `list` | | Container labels | | |
| `--credential-spec` | `credential-spec` | | Credential spec for managed service account (Windows only) | | |
| `-d`, `--detach` | | | Exit immediately instead of waiting for the service to converge | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crazy thought, how about "--wait"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the intent here is to (like docker service create
) flip the default at some point, so make stack deploy
act the same as docker compose up
.
I don't think the markdown here is a real blocker for the PR (we can fix in "post"), but I noticed it, and was curious what went wrong here (looks like a bug in the markdown generator potentially?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we can investigate further in a separate issue, as it seems like a generalized bug in the markdown generator.
Is there anything else left to be done in this PR?
b040ca8
to
23e079d
Compare
Is there anything left to be done in this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM/agreed that we can worry about the markdown later, given this is no more broken then other commands.
@neersighted We have fixed the markdown issue in docker/cli-docs-tool#48 ✌️ |
Added --detach/-d to stack rm. Setting --detach=false waits until all of the stack tasks have reached a terminal state. Co-authored-by: Sebastiaan van Stijn <[email protected]> Signed-off-by: George Margaritis <[email protected]>
23e079d
to
238d659
Compare
Did a quick rebase and re-generated the markdown as we updated the diff --git a/docs/reference/commandline/stack_rm.md b/docs/reference/commandline/stack_rm.md
index 8dd872b7c..5cfbfaab1 100644
--- a/docs/reference/commandline/stack_rm.md
+++ b/docs/reference/commandline/stack_rm.md
@@ -9,9 +9,9 @@ Remove one or more stacks
### Options
-| Name | Type | Default | Description |
-|:-----------------|:-----|:--------|:------------------------------|
-| `-d`, `--detach` | | | Do not wait for stack removal |
+| Name | Type | Default | Description |
+|:-----------------|:-------|:--------|:------------------------------|
+| `-d`, `--detach` | `bool` | `true` | Do not wait for stack removal | I also opened a tracking ticket to look at follow-up improvements discussed above; #4907 |
Part of #373 along with #4258
Added --detach to stack rm. Setting --detach=false waits until all of the stack tasks have reached a terminal state.