Return error for incorrect argument of service update --publish-rm#25860
Return error for incorrect argument of service update --publish-rm#25860thaJeztah merged 1 commit intomoby:masterfrom
service update --publish-rm#25860Conversation
|
I'm not very familiar with these options, but my thinking is that it's best for Are there any obstacles to supporting |
|
When I raised #1396 I didn't mean to suggest adding a validation, but allowing I vote the same as @aaronlehmann (to fix that behaviour). |
|
Currently the Technically it is possible to extend the |
api/client/service/update.go
Outdated
There was a problem hiding this comment.
Are you sure this is necessary?
I believe swarm always returns a spec that includes the protocol, even if one wasn't specified on the command line.
There was a problem hiding this comment.
Thanks @dnephin! You are right. I was misled by one of the unit tests where the protocol was not specified.
The pull request has been updated to only do a validation of the --publish-rm. Please let me know if there are any issues.
23d4308 to
37c4904
Compare
api/client/service/update_test.go
Outdated
There was a problem hiding this comment.
I think we're missing an important test case here for 80:80. We should make sure to give a helpful error in that case.
There was a problem hiding this comment.
Thanks @dnephin. The pull request has been updated with additional test cases.
37c4904 to
69a94c6
Compare
|
LGTM |
api/client/service/update.go
Outdated
There was a problem hiding this comment.
This is pretty gross.
Can we instead do do a newListOptVarWithValidator or something?
Or maybe better newListOptVar().WithValidator(validatePort)
There was a problem hiding this comment.
It's gross because everything is passing a nil except for one opt.
There was a problem hiding this comment.
Thanks @cpuguy83. The pull request has been updated. Please let me know if there are any issues.
69a94c6 to
298cebc
Compare
api/client/service/update.go
Outdated
There was a problem hiding this comment.
Why wouldn't nat.ParsePort pick this up?
Also seems a little weird to check for only one thing instead of using a regex to match a specific pattern(s)
|
Not 100% sure I understand this, because I'd think I'd be able to use the full port spec to remove... e.g. |
|
@cpuguy83 The current (1.12) behavior for So However, in 1.12 there is no error output and the invalid input There are some related discussions: This pull request is to return an error message (not changing 1.12 behavior) so it is easy for end user to understand. We could change the behavior to accept |
298cebc to
8032cad
Compare
8032cad to
200fb6f
Compare
200fb6f to
28fc27f
Compare
|
Ping for additional feedback for the PR (rebased). |
|
ping @aboch |
cli/command/service/update.go
Outdated
There was a problem hiding this comment.
I would add to the name of this function some notion that is for port removal only.
Otherwise as it stands now, it gives the impression it can be reused to validate ports for any service cli.
|
@yongtang And I have a question just for my understanding: Why isn't the validation being done in the in the swarmkit code instead, which owns the feature, so that it takes care of validating the remote API. |
@aboch correct; the daemon has no option to "remove" or "add" an option; the client sends the full spec after applying the changes |
28fc27f to
0da7148
Compare
|
Thanks @aboch for the review. The As was mentioned by @thaJeztah, the swarmkit will only take a desired state of the service spec, so add or remove checking has to be done at the client side. |
|
Thanks @thaJeztah and @yongtang for the explanation. Changes look good to me. |
|
Ping. Any additional issues need to address? |
|
LGTM but needs a rebase. |
|
Design wise this looks good. |
…TargetPort>` Currently `--publish-rm` only accepts `<TargetPort>` or `<TargetPort>[/Protocol]` though there are some confusions. Since `--publish-add` accepts `<PublishedPort>:<TargetPort>[/Protocol]`, some user may provide `--publish-rm 80:80`. However, there is no error checking so the incorrect provided argument is ignored silently. This fix adds the check to make sure `--publish-rm` only accepts `<TargetPort>[/Protocol]` and returns error if the format is invalid. The `--publish-rm` itself may needs to be revisited to have a better UI/UX experience, see discussions on: moby/swarmkit#1396 moby#25200 (comment) moby#25338 (comment) This fix is short term measure so that end users are not misled by the silently ignored error of `--publish-rm`. This fix is related to (but is not a complete fix): moby/swarmkit#1396 Signed-off-by: Yong Tang <[email protected]>
0da7148 to
c4d773c
Compare
|
Thanks all for the review. The PR has been rebased. |
|
hm, doing some more testing, this does catch the invalid format ( Basically, the Some examples; With the service below; Using source-port does not produce an error; $ docker service update --publish-rm 8080 web
webUsing source-port/protocol does not produce an error; docker service update --publish-rm 8080/udp web
webUsing a non-existing port also doesn't produce an error; docker service update --publish-rm 1234 web
webPerhaps it's not a blocker for this PR, because it does catch the incorrect format just wondering if we should change that behavior. |
|
discussing this in the maintainers meeting, and we can keep it for a separate discussion. |
…sh-rm Return error for incorrect argument of `service update --publish-rm`
- What I did
Currently
--publish-rmonly accepts<TargetPort>or<TargetPort>[/Protocol]though there are some confusions.Since
--publish-addaccepts<PublishedPort>:<TargetPort>[/Protocol], some user may provide--publish-rm 80:80. However, there is no error checking so the incorrectly provided argument is ignored silently.This fix is an attempt to address this issue.
- How I did it
This fix adds the check to make sure
--publish-rmonly accepts<TargetPort>[/Protocol]and returns error if the format is invalid.This fix also fixes an issue in the
equalPort()so that iftcpis not present inPortConfig, the equal check is still valid (i.e.,80/tcp==80).- How to verify it
Additional unit tests have been added.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
The
--publish-rmitself may needs to be revisited to have a better UI/UX experience,see discussions on:
moby/swarmkit#1396
#25200 (comment)
#25338 (comment)
This fix is short term measure so that end users are not misled by the silently ignored error
of
--publish-rm.This fix is related to (but is not a complete fix):
moby/swarmkit#1396
Signed-off-by: Yong Tang [email protected]