Error on cluster spec name change.#2436
Conversation
manager/controlapi/cluster.go
Outdated
| } | ||
|
|
||
| if spec.Annotations.Name != store.DefaultClusterName { | ||
| return grpc.Errorf(codes.PermissionDenied, "Modification of cluster name is node allowed") |
There was a problem hiding this comment.
s/node/not/ 😉
Also can you lowercase Modification?
There was a problem hiding this comment.
Also wondering;
- is this validation done on create / init as well? (probably should, but in that case the error message may need some tweaking; e.g. "custom cluster names are not supported")
- should "empty" values be updated to
store.DefaultClusterName? (as is done in cluster: Refuse swarm spec not named "default" moby#28914)
There was a problem hiding this comment.
is this validation done on create / init as well?
Creation name is hardcoded, so I don't think a validation is needed there.
should "empty" values be updated to store.DefaultClusterName
Not sure what the motivation behind this is, but its probably better to be explicit and fail if it changes. I believe clients are expected to perform a read-modify-write ?
I guess setting the default would have been much cleaner if there was a way to specify the default value during init (e.g. inline init or in the constructor).
|
Copying here as well (re: moby/moby currently doesn't validate on update) #2435 (comment);
|
I agree that the validation should probably be moved to swarmkit since adding this dependency to moby is exposing internal details best kept inside swarmkit IMO. I can make this change if there are no objections @nishanttotla @aaronlehmann |
Codecov Report
@@ Coverage Diff @@
## master #2436 +/- ##
==========================================
- Coverage 63.89% 60.62% -3.28%
==========================================
Files 64 128 +64
Lines 11788 26410 +14622
==========================================
+ Hits 7532 16011 +8479
- Misses 3649 9005 +5356
- Partials 607 1394 +787 |
nishanttotla
left a comment
There was a problem hiding this comment.
I agree that this should be on SwarmKit. As far as cluster names go, I believe the motivation was to be able to support multiple cluster objects?
cc @aluzzardi
|
@anshulpundir are you going to add tests? |
|
@nishanttotla @thaJeztah init cluster from moby/moby calls UpdateCluster(). So the check in UpdateCluster() should do the trick and we can remove the check from moby/moby. Also, updated tests latest patch @marcusmartins |
manager/controlapi/cluster.go
Outdated
| } | ||
|
|
||
| if spec.Annotations.Name != store.DefaultClusterName { | ||
| return grpc.Errorf(codes.PermissionDenied, "modification of cluster name is not allowed") |
There was a problem hiding this comment.
codes.InvalidArgument perhaps?
There was a problem hiding this comment.
hm, feels a bit odd, because caller has access to this endpoint, but passed an invalid argument (The value was not accepted, because the only valid value here is "default"). I don't think it's any different than the other validations performed in this function (e.g. you cannot set any value other than "bcrypt" here; https://github.com/anshulpundir/swarmkit/blob/21e99c146ef0fce96ee89befb950bc75f3f73e68/manager/controlapi/cluster.go#L44
There was a problem hiding this comment.
Not sure I follow. Why do you think having access to an endpoint but passing invalid arg is odd ? @thaJeztah
There was a problem hiding this comment.
That's not odd, but returning a permission denied instead of invalid argument (like for all the other validation check in this function) feels odd.
There was a problem hiding this comment.
agreed. I already changed it to invalid argument. LMK if this looks good @thaJeztah @nishanttotla
There was a problem hiding this comment.
I agree with using codes.InvalidArgument.
ef8fe59 to
e8a48fc
Compare
|
I did a bit of digging in the code, and my concern with this change is that this patch will effectively disable the possibility to have multiple swarms. I realize this functionality is not supported by Docker, but it is part of the SwarmKit design / functionality. This may also be the reason the initial validation was added in the moby/moby repository, instead of in SwarmKit. Digging through the code (sorry, not too familiar with the whole SwarmKit codebase);
So:
For that reason, I think this validation should be moved to moby/moby, where we can:
The bug at hand here is that Moby only validates when "initializing" the cluster, but not when updating the cluster (#2435 (comment)). With the above information, this should be an easy fix there. |
|
Was working on moby/moby#35464 - but failed to reproduce the "empty name" problem locally, so perhaps it's not correct 😅 |
|
@thaJeztah it might be part of the design but it doesn't seem to be fully implemented in swarmkit itself based on @aaronlehmann comment on moby/moby@9dba9e3:
My take is that independent of the swarmkit design if swarmkit cannot handle different names at the moment it should guard against that instead of relying on the caller. And that limitation can be removed once swarmkit fixes that behavior. |
|
cc @aluzzardi |
|
I couldn't have said it better @marcusmartins I'd like to get this in sooner than later. Please LMK if there are any other concerns. |
| }, | ||
| }, | ||
| c: codes.InvalidArgument, | ||
| }, |
There was a problem hiding this comment.
Can you add one case that uses a non-empty invalid name?
Signed-off-by: Anshul Pundir <anshul.pundir@docker.com>
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM as it addresses the problem
it doesn't seem to be fully implemented in swarmkit itself based on @aaronlehmann comment on moby/moby@9dba9e3:
The situation described is matching my earlier analysis: Docker does not explicitly create a new cluster (only uses the one that's implicitly created by manager.becomeLeader()). So any action performed by Docker against SwarmKit should use the "default" one.
I suspect there may still be a bug in UpdateCluster() as that function's documentation mentions Returns ErrNotExist if the cluster doesn't exist., but the code only seems to check for a conflicting cluster (existing != nil), and will continue with tx.update() if the cluster was not found.
|
Any reason we can't support renaming of the cluster? The only challenge seems to be that of self-identification, but I think most of the code just assumes there is a single cluster. |
|
Also, looks like https://github.com/docker/swarmkit/blob/master/manager/keymanager/keymanager.go#L190 needs a fix. This should probably not query by name, but just get all and the result should be checked. Leaving that section as is creates a possible panic situation for the future. |
Yea, identification seems to be the main challenge. Also, as is, I can't think of a (important) use-case to support cluster rename, in which case I don't see the need to support it. |
Although the assumption in swarmkit is to expect a cluster by the name "default", I think this is a fair point. I don't mind making that change. |
|
@anshulpundir Supporting cluster renaming is just about being able to have multiple clusters report together. Imagine a UI which manages several clusters. How do you tell the difference between each cluster? The code to support it here isn't much more than is already present and may expose problems with the existing model that could crop up in the future. |
|
I see your point. I'm not sure its worthwhile supporting/testing that functionality right now since only a single cluster is supported (at least externally). I completely agree about supporting cluster rename when multiple clusters are supported @stevvooe |
aaronlehmann
left a comment
There was a problem hiding this comment.
FWIW this looks good to me. I'm fine with the idea of removing the dependence on the name "default", but that could be a future enhancement.
Currently, the cluster name is hardcoded and is expected to not change for the swarmkit to function. Enforcing that by returning an error if cluster name change is attempted.
Signed-off-by: Anshul Pundir anshul.pundir@docker.com