-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Add comma-separated --auto-accept support. #24146
Conversation
If we're going to support The logic of |
dca2659
to
083c78e
Compare
I'm implementing the |
I guess on |
I see the design discussion continued in the issue; #24143 (comment), so it looks like this PR needs to be updated /cc @aaronlehmann @aluzzardi ? |
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) |
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 should just say value NONE is compatible with ALL
083c78e
to
1f0ff67
Compare
Added support for comma-separated values |
I don't think |
meh, on second thought it's probably fine. |
@cpuguy83
|
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 |
Maybe just allowing a comma-separated syntax is better then, and removing all? Would give a better UX shorthand instead of multiple |
@johnharris85: I think that's fine. |
Thanks! We can always add |
1f0ff67
to
600f60d
Compare
|
@@ -18,6 +18,8 @@ const ( | |||
WORKER = "WORKER" | |||
// MANAGER constant for manager name | |||
MANAGER = "MANAGER" | |||
// NONE constant | |||
NONE = "NONE" |
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.
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
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.
Also, they should not be exported. And then we can drop the silly comments.
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.
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?
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.
opts_test.go
is in the same package, so they don't need to be exported.
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.
Right, thanks.
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 { |
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'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.
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 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.
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.
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?
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.
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.
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.
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.
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 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.
cde7bdd
to
f87ca41
Compare
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)) |
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.
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.
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.
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.
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.
Okay, if you decide to keep the current format, can you change the Sprintf call to fmt.Sprintf("%s=true", strings.ToLower(key))
?
f87ca41
to
c3d978a
Compare
for _, value := range strings.Split(acceptValues, ",") { | ||
value = strings.ToUpper(value) | ||
switch value { | ||
case "", none: |
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.
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, ",") {
...
}
}
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.
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?
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'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.
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.
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?
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.
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.
c3d978a
to
de0d213
Compare
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! |
de0d213
to
ad57cf3
Compare
Signed-off-by: John Harris <john@johnharris.io>
ad57cf3
to
8e14882
Compare
LGTM |
ping @thaJeztah |
Thanks! docs LGTM |
@@ -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 |
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 none
needs to be mentioned somewhere in the docs.
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.
@aaronlehmann good point; just created #24552
Ping @icecrime |
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