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

hide --detach for docker < 17.05 #219

Merged
merged 1 commit into from
Jun 27, 2017
Merged

hide --detach for docker < 17.05 #219

merged 1 commit into from
Jun 27, 2017

Conversation

vieux
Copy link
Contributor

@vieux vieux commented Jun 21, 2017

1st I added --detach to docker 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)

@vieux
Copy link
Contributor Author

vieux commented Jun 21, 2017

Here is the current behavior:

$docker service update --replicas=8 test
test
Since --detach=false was not specified, tasks will be updated in the background.
In a future release, --detach=false will become the default.

When adding the flag as suggested:

$docker service update --detach=false --replicas=8 test
test
Error response from daemon: Invalid filter '_up-to-date'

@vieux
Copy link
Contributor Author

vieux commented Jun 21, 2017

ping @thaJeztah

@codecov-io
Copy link

codecov-io commented Jun 21, 2017

Codecov Report

Merging #219 into master will increase coverage by 0.03%.
The diff coverage is 55%.

@@            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


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"+
Copy link
Member

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?

Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

)

func newScaleCommand(dockerCli *command.DockerCli) *cobra.Command {
return &cobra.Command{
options := newServiceOptions()
Copy link
Contributor

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.


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"+
Copy link
Contributor

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.


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"})
Copy link
Contributor

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)
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 also add it to the completion scripts, or want someone to take care of that in a follow-up?

Copy link
Contributor

@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.

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.

@@ -59,6 +68,15 @@ func runScale(dockerCli *command.DockerCli, args []string) error {
if err := runServiceScale(dockerCli, serviceID, scale); err != nil {
Copy link
Contributor

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

@@ -453,6 +453,10 @@ func convertExtraHostsToSwarmHosts(extraHosts []string) []string {
return hosts
}

type scaleOptions struct {
detach bool
}
Copy link
Contributor

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.

for _, test := range tests {
out := new(bytes.Buffer)
cli.SetErr(out)
detach = test.detach
Copy link
Contributor

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

@vieux vieux changed the title add --detach to docker service scale and fix 17.05 -> 17.03 hide --detach for docker < 17.05 Jun 27, 2017
@vieux
Copy link
Contributor Author

vieux commented Jun 27, 2017

split the PR in two, here is the bugfix/refactor, new feature in #243

@docker docker deleted a comment from thaJeztah Jun 27, 2017
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

@tiborvass
Copy link
Collaborator

LGTM

@tiborvass tiborvass merged commit c3e5445 into docker:master Jun 27, 2017
@vieux vieux deleted the scale branch June 27, 2017 16:51
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.

6 participants