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

Add comma-separated --auto-accept support. #24146

Merged
merged 1 commit into from
Jul 12, 2016

Conversation

johnharris85
Copy link
Contributor

@johnharris85 johnharris85 commented Jun 29, 2016

Addresses #24143, simplifying --auto-accept syntax for a better UX.

Add support for comma-separated --auto-accept value.

$ docker swarm update --auto-accept worker,manager.

Signed-off-by: John Harris john@johnharris.io

@GordonTheTurtle GordonTheTurtle added status/0-triage dco/no Automatically set by a bot when one of the commits lacks proper signature labels Jun 29, 2016
@dnephin
Copy link
Member

dnephin commented Jun 29, 2016

If we're going to support all instead of --auto-accept worker --auto-accept manager I think we should make a much larger change to the AutoAcceptOption.

The logic of Set becomes a lot simpler if you can't set it more than once.

@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Jun 29, 2016
@johnharris85
Copy link
Contributor Author

I'm implementing the --auto-accept-add and --auto-accept-rm flags, but wondering how auto-acceptance should be handled on docker swarm init. Obviously add still works there but should rm error? Or just silently do nothing (as it looks like default behavior for init is going to be auto-accept = false for both anyway)?

@dnephin
Copy link
Member

dnephin commented Jul 3, 2016

I guess on init it should actually just use the current behaviour

@thaJeztah
Copy link
Member

I see the design discussion continued in the issue; #24143 (comment), so it looks like this PR needs to be updated

/cc @aaronlehmann @aluzzardi ?

@johnharris85
Copy link
Contributor Author

Ye @thaJeztah just waiting for the design stuff to be fleshed out over there before updating the PR.

@@ -112,6 +112,15 @@ func (o *AutoAcceptOption) Set(value string) error {
return fmt.Errorf("value NONE is incompatible with %s", value)
}
o.values[value] = true
case "ALL":
if accept, ok := o.values[WORKER]; ok && accept {
return fmt.Errorf("value NONE is incompatible with %s", WORKER)
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 just say value NONE is compatible with ALL

@johnharris85
Copy link
Contributor Author

Added support for comma-separated values --auto-accept worker,manager as well as all. Also backwards compatible with the current way of setting these flags. Added tests to reflect the changes.

@cpuguy83
Copy link
Member

cpuguy83 commented Jul 8, 2016

I don't think all is a good idea.
Today we accept manager, worker and it's ok, but in the future we may have other types (storage?) where it makes less sense to support all

@cpuguy83
Copy link
Member

cpuguy83 commented Jul 8, 2016

meh, on second thought it's probably fine.

@johnharris85
Copy link
Contributor Author

@cpuguy83 all is a UX feature for me. I think there is more refactoring to be done here (to make all future proof for example) but the current syntax --auto-accept worker --auto-accept manager is too long-hand IMO. The --auto-accept manager,worker syntax is not currently supported (this PR adds it).

all makes even more sense when considering the potential for future options. If I'm doing some local experiments / development and I need to type --auto-accept n where n is maybe 4 or 5 options. That's going to get old pretty quickly :p

@thaJeztah
Copy link
Member

all makes even more sense when considering the potential for future options.

I'm not sure we should develop for possible future options. What if the new future option is something that should be an "opt-in"? If someone set all (because: lazy), we could have a potential security issue. Better to keep it explicit, and have people update their config to allow the new type than to allow it without them knowing.

@johnharris85
Copy link
Contributor Author

Maybe just allowing a comma-separated syntax is better then, and removing all? Would give a better UX shorthand instead of multiple --auto-accept flags but also preserve the security aspect?

@aaronlehmann
Copy link
Contributor

@johnharris85: I think that's fine.

@thaJeztah
Copy link
Member

Thanks! We can always add all back in future if we think it's ok; removing it is more troublesome once it's there

@johnharris85
Copy link
Contributor Author

all removed and refactored some of the none checking logic to make it simpler. Tests amended.

@@ -18,6 +18,8 @@ const (
WORKER = "WORKER"
// MANAGER constant for manager name
MANAGER = "MANAGER"
// NONE constant
NONE = "NONE"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not strictly related to your change, but could you please change these constants to CamelCase? Identifiers should never be all-caps in Golang. I'm surprised golint doesn't complain about this.

https://golang.org/doc/effective_go.html#mixed-caps
https://github.com/golang/go/wiki/CodeReviewComments#mixed-caps

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, they should not be exported. And then we can drop the silly comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're being used in opts_test.go. So either they stay exported (but CamelCase) or we hard code the values into all the test cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

opts_test.go is in the same package, so they don't need to be exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, thanks.

@aaronlehmann
Copy link
Contributor

Can you please update the PR summary and description to reflect the changes from the review, and squash the commits?

switch value {
case "", NONE:
// NONE must stand alone, so if any non-NONE setting exists, conflict
if !o.values[NONE] && len(o.values) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest moving this check outside of the loop, with something like:

if o.values[NONE] && len(o.values) > 1 {
        ...
}

Among other things, this will give a more consistent error message that won't depend on the order of the values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually don't see the value in specifying the explicit conflict, can't any error (where there is none + n) return with something like "value NONE cannot be specified alongside other node types" ?

Error then consistent across all and simplifies this logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move to above line#105? Set is only called once though (and o.values is always empty until we set something in it) so that check will never eval to true right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, I don't see the value in specifying the conflict.

I was thinking this could move below the loop, so it inspects o.values after the map is populated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah OK I get it. Ye can do, but with the standardizing of the error now does this have any other main benefits? I guess you could argue that error is checking the flag set as a whole, or that it's part of the none case. No strong feeling either way really.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes most sense for it to be below the loop because otherwise you have to check for conflicts both in the none case (in case none comes after a different value) and in the other cases (in case they come after none). If the check is below the loop, only a single check is needed.

@johnharris85 johnharris85 force-pushed the fix-swarm-update-auto-accept branch 2 times, most recently from cde7bdd to f87ca41 Compare July 9, 2016 19:25
@johnharris85 johnharris85 changed the title Add 'all' option to swarm update --auto-accept. Add comma-separated --auto-accept support. Jul 9, 2016
for key, value := range o.values {
keys = append(keys, fmt.Sprintf("%s=%v", strings.ToLower(key), value))
for key := range o.values {
keys = append(keys, fmt.Sprintf("%s=%v", strings.ToLower(key), true))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed this: should this be a list of values, instead of x=true, y=true? There is no =false, so the =true seems redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ye I thought that too, maybe just for readability / clarity (for repr), although ye, not strictly required as it's true if it exists by default. Happy to change but think it's clearer to stay. No strong preference either way though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, if you decide to keep the current format, can you change the Sprintf call to fmt.Sprintf("%s=true", strings.ToLower(key))?

for _, value := range strings.Split(acceptValues, ",") {
value = strings.ToUpper(value)
switch value {
case "", none:
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, one final comment. I'm wondering it makes sense to treat "" the same as none. It would mean that worker,,manager is parsed as worker,none,manager. I guess the intent here is to treat --auto-accept "" as --auto-accept none. If that's the case, maybe it would be better to do it at the very beginning of this function:

if acceptValues == "" {
        o.values[none] = struct{}{}
} else {
        for _, value := range strings.Split(acceptValues, ",") {
                ...
        }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, but then worker,,manager would trigger the default case (and maybe it should)? Or in addition to the above change, should a case be added for an empty string inside the loop to just ignore it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure, but either sounds reasonable to me. Triggering an error in that case (by hitting the default case) is probably the safest approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And ye, I guess that was the original intent (that code existed before my PR) but I'm not sure whether I agree with it. I think a blank --auto-accept should error or pass silently, not set to none. That doesn't seem intuitive behaviour. Perhaps it was done for security reasons? In case someone set it accidentally but didn't pass anything, default to none. That may have made sense before, but aren't the defaults changing to false for both manager and worker anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

And ye, I guess that was the original intent (that code existed before my PR) but I'm not sure whether I agree with it. I think a blank --auto-accept should error or pass silently, not set to none.

Makes sense.

That doesn't seem intuitive behaviour. Perhaps it was done for security reasons? In case someone set it accidentally but didn't pass anything, default to none.

Not really sure that makes sense. It's hard to accidentally pass an empty string as an argument.

That may have made sense before, but aren't the defaults changing to false for both manager and worker anyway?

The autoaccept defaults aren't changing. What changed recently on master is that by default, a secret token is needed to join a swarm.

@aaronlehmann
Copy link
Contributor

Code LGTM

Can you please update the commit message and pull request description to summarize the final state of the changes?

This will also need updates to the docs before merging.

Thanks!

Signed-off-by: John Harris <john@johnharris.io>
@cpuguy83
Copy link
Member

LGTM

@cpuguy83
Copy link
Member

ping @thaJeztah

@thaJeztah
Copy link
Member

Thanks! docs LGTM

@thaJeztah thaJeztah merged commit 7da11b1 into moby:master Jul 12, 2016
@@ -66,6 +66,13 @@ For example, the following initializes a cluster with auto-acceptance of workers
$ docker swarm init --listen-addr 192.168.99.121:2377 --auto-accept worker
```

It is possible to pass a comma-separated list of node types. The following initializes a cluster
with auto-acceptance of both `worker` and `manager` nodes
Copy link
Contributor

Choose a reason for hiding this comment

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

I think none needs to be mentioned somewhere in the docs.

Copy link
Member

Choose a reason for hiding this comment

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

@aaronlehmann good point; just created #24552

@aluzzardi
Copy link
Member

Ping @icecrime

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.

None yet

9 participants