-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
hide --detach
for docker < 17.05
#219
Conversation
Here is the current behavior:
When adding the flag as suggested:
|
ping @thaJeztah |
Codecov Report
@@ Coverage Diff @@
## master #219 +/- ##
==========================================
+ Coverage 46.81% 46.85% +0.03%
==========================================
Files 172 172
Lines 11686 11689 +3
==========================================
+ Hits 5471 5477 +6
+ Misses 5903 5900 -3
Partials 312 312 |
cli/command/service/scale.go
Outdated
|
||
if options.detach { | ||
if !flags.Changed("detach") && versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.29") { | ||
fmt.Fprintln(dockerCli.Err(), "Since --detach=false was not specified, tasks will be scaled in the background.\n"+ |
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.
Should we add a global definition of this error somewhere?
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.
Hm; also (this is gonna be tricky); the warning should no longer be printed if the client talks to docker 17.09 (or whichever version changes the default)
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.
This sentence is slightly different from the create one: "scaled" vs "updated" :d
I agree 17.09 is probably a good time to do the switch. I'll work on a config file key for it in the meantime.
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.
Instead of defining the error in a global we should make this a function and pass in the different string as an arg.
func warnDetachDefault(dockerCli command.Cli, flags pflag.FlatSet, msg string) { ... }
We can use that function from all 3 locations, and it would be easy to test.
cli/command/service/scale.go
Outdated
) | ||
|
||
func newScaleCommand(dockerCli *command.DockerCli) *cobra.Command { | ||
return &cobra.Command{ | ||
options := newServiceOptions() |
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.
This shouldn't use service options (which is a huge struct).
We should create a new scaleOptions
struct which would include just detach
for now.
cli/command/service/scale.go
Outdated
|
||
if options.detach { | ||
if !flags.Changed("detach") && versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.29") { | ||
fmt.Fprintln(dockerCli.Err(), "Since --detach=false was not specified, tasks will be scaled in the background.\n"+ |
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.
Instead of defining the error in a global we should make this a function and pass in the different string as an arg.
func warnDetachDefault(dockerCli command.Cli, flags pflag.FlatSet, msg string) { ... }
We can use that function from all 3 locations, and it would be easy to test.
cli/command/service/scale.go
Outdated
|
||
flags := cmd.Flags() | ||
flags.BoolVarP(&options.detach, "detach", "d", true, "Exit immediately instead of waiting for the service to converge") | ||
flags.SetAnnotation("detach", "version", []string{"1.29"}) |
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 could move these two lines to an addDetachFlag()
function and call it from addServiceFlags()
(and here).
We should also create a constant flagDetach
like we have for a bunch of the other flags in service/opts.go
|
||
Scale one or multiple replicated services | ||
|
||
Options: | ||
-d, --detach Exit immediately instead of waiting for the service to converge (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.
Can you also add it to the completion scripts, or want someone to take care of that in a follow-up?
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 wouldn't worry about the rest of the test coverage for this change. The coverage should come when unit tests are written for the service commands.
cli/command/service/scale.go
Outdated
@@ -59,6 +68,15 @@ func runScale(dockerCli *command.DockerCli, args []string) error { | |||
if err := runServiceScale(dockerCli, serviceID, scale); err != nil { |
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.
runServiceScale
should accept this new ctx
, so we don't create another one
cli/command/service/opts.go
Outdated
@@ -453,6 +453,10 @@ func convertExtraHostsToSwarmHosts(extraHosts []string) []string { | |||
return hosts | |||
} | |||
|
|||
type scaleOptions struct { | |||
detach bool | |||
} |
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.
minor, but this struct should go in scale.go
since it's only used in that one file. serviceOptions
is a rare case where there are a lot of options shared between multiple commands.
cli/command/service/helpers_test.go
Outdated
for _, test := range tests { | ||
out := new(bytes.Buffer) | ||
cli.SetErr(out) | ||
detach = test.detach |
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 don't think this is triggering flags.Changed()
. You can use flags.Lookup(flagDetach).Changed = ...
There's one more test case here, isn't there? {true, "1.29", false)
, which I think will fail until ^ is fixed
--detach
to docker service scale
and fix 17.05 -> 17.03--detach
for docker < 17.05
split the PR in two, here is the bugfix/refactor, new feature in #243 |
Signed-off-by: Victor Vieux <[email protected]>
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.
LGTM
LGTM |
1st I added
--detach
todocker service scale
then while testing I realized that using docker 17.05 with a 17.03 client doesn't work with
--detach=true
since it's using an unknown filter to 17.03. so I hid the flag (as it should have been)