Skip to content

Return error for incorrect argument of service update --publish-rm#25860

Merged
thaJeztah merged 1 commit intomoby:masterfrom
yongtang:1396-service-update-publish-rm
Dec 8, 2016
Merged

Return error for incorrect argument of service update --publish-rm#25860
thaJeztah merged 1 commit intomoby:masterfrom
yongtang:1396-service-update-publish-rm

Conversation

@yongtang
Copy link
Member

- What I did

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 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-rm only accepts <TargetPort>[/Protocol] and returns error if the format is invalid.

This fix also fixes an issue in the equalPort() so that if tcp is not present in PortConfig, 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-rm itself 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]

@aaronlehmann
Copy link

I'm not very familiar with these options, but my thinking is that it's best for --publish-rm to support a syntax that's consistent with --publish-add. It seems like a common point of confusion that people can't use --publish-add 80:81 and then --publish-rm 80:81.

Are there any obstacles to supporting --publish-rm 80:81?

@sheerun
Copy link

sheerun commented Aug 19, 2016

When I raised #1396 I didn't mean to suggest adding a validation, but allowing --publish-rm to remove only one binding. Currently it's just not possible, and I want to remove only one binding, I need to remove all of them and re-add all the other ones.. what is not optimal?

I vote the same as @aaronlehmann (to fix that behaviour).

@yongtang
Copy link
Member Author

@aaronlehmann @sheerun

Currently the --publish-add takes the form of ip:published:target/proto, and in case of --publish-add 80 it represents ip:published:80/tcp so it matches the existing interpretation of --publish-rm target/proto.

Technically it is possible to extend the --publish-rm to take published port without breaking the backward-compatibility.

cc @thaJeztah @dnephin @dperny

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @dnephin. The pull request has been updated with additional test cases.

@yongtang yongtang force-pushed the 1396-service-update-publish-rm branch from 37c4904 to 69a94c6 Compare August 24, 2016 04:38
@dnephin
Copy link
Member

dnephin commented Aug 24, 2016

LGTM

Copy link
Member

Choose a reason for hiding this comment

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

This is pretty gross.
Can we instead do do a newListOptVarWithValidator or something?
Or maybe better newListOptVar().WithValidator(validatePort)

Copy link
Member

Choose a reason for hiding this comment

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

It's gross because everything is passing a nil except for one opt.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @cpuguy83. The pull request has been updated. Please let me know if there are any issues.

Copy link
Member

Choose a reason for hiding this comment

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

👍 Much better, thanks!

@yongtang yongtang force-pushed the 1396-service-update-publish-rm branch from 69a94c6 to 298cebc Compare August 24, 2016 17:48
Copy link
Member

Choose a reason for hiding this comment

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

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)

@cpuguy83
Copy link
Member

Not 100% sure I understand this, because I'd think I'd be able to use the full port spec to remove... e.g. 80:80/tcp, however it looks like from the test this would be rejected.

@yongtang
Copy link
Member Author

@cpuguy83 The current (1.12) behavior for --publish-rm is to only accept <TargetPort>/<Protocol> (No published port):

      --publish-rm value               Remove a published port by its target port (default [])

So --publish-rm 80:80/tcp will be considered as an invalid input.

However, in 1.12 there is no error output and the invalid input 80:80/tcp will be ignored silently (which caused confusion).

There are some related discussions:
moby/swarmkit#1396
#25200 (comment)
#25338 (comment)

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 --publish-rm 80:80/tcp if it is agreed.

@yongtang yongtang force-pushed the 1396-service-update-publish-rm branch from 298cebc to 8032cad Compare September 28, 2016 12:10
@yongtang yongtang force-pushed the 1396-service-update-publish-rm branch from 8032cad to 200fb6f Compare October 17, 2016 20:34
@yongtang yongtang force-pushed the 1396-service-update-publish-rm branch from 200fb6f to 28fc27f Compare November 2, 2016 16:13
@yongtang
Copy link
Member Author

yongtang commented Nov 2, 2016

Ping for additional feedback for the PR (rebased).

@cpuguy83
Copy link
Member

cpuguy83 commented Nov 2, 2016

ping @aboch

Copy link
Member

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

LGTM

@yongtang
Copy link
Member Author

yongtang commented Nov 7, 2016

Ping @mrjana @aboch.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@aboch
Copy link
Contributor

aboch commented Nov 8, 2016

@yongtang
I only have a minor comment on the function name. Up to you if you want to change it.

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.
Is it because there is no remote API counterpart to the --publish-add/--publish-rm cli options, so this is peculiar to the cli only ?
Thanks.

@thaJeztah
Copy link
Member

Is it because there is no remote API counterpart to the --publish-add/--publish-rm cli options, so this is peculiar to the cli only ?

@aboch correct; the daemon has no option to "remove" or "add" an option; the client sends the full spec after applying the changes

@yongtang yongtang force-pushed the 1396-service-update-publish-rm branch from 28fc27f to 0da7148 Compare November 8, 2016 14:10
@yongtang
Copy link
Member Author

yongtang commented Nov 8, 2016

Thanks @aboch for the review. The validatePort has been renamed to validatePublishRemove for better description.

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.

@aboch
Copy link
Contributor

aboch commented Nov 8, 2016

Thanks @thaJeztah and @yongtang for the explanation.

Changes look good to me.

@yongtang
Copy link
Member Author

yongtang commented Nov 9, 2016

Ping. Any additional issues need to address?

@cpuguy83
Copy link
Member

cpuguy83 commented Dec 1, 2016

LGTM but needs a rebase.

@tiborvass
Copy link
Contributor

Design wise this looks good.

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

…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]>
@yongtang yongtang force-pushed the 1396-service-update-publish-rm branch from 0da7148 to c4d773c Compare December 2, 2016 02:28
@yongtang
Copy link
Member Author

yongtang commented Dec 2, 2016

Thanks all for the review. The PR has been rebased.

@thaJeztah
Copy link
Member

hm, doing some more testing, this does catch the invalid format (1234:456/tcp), but I wonder if this will lead to the expectation that any incorrect value will produce an error.

Basically, the docker service update command is still using the "reconciliation" pattern; in other words; removing something that didn't exist, doesn't produce an error, because it didn't exist in the first place.

Some examples;

With the service below;

$docker service create --publish 8080:80/udp --name web nginx:alpine
86q0pdryba8xj9k6e7vbkhz1l

Using source-port does not produce an error;

$ docker service update --publish-rm 8080 web
web

Using source-port/protocol does not produce an error;

docker service update --publish-rm 8080/udp web
web

Using a non-existing port also doesn't produce an error;

docker service update --publish-rm 1234 web
web

Perhaps it's not a blocker for this PR, because it does catch the incorrect format

$ docker service update --publish-rm 8080:80/udp web
invalid argument "8080:80/udp" for --publish-rm: invalid port format: '8080:80', should be <TargetPort>[/<Protocol>] (e.g., 80, 80/tcp, 53/udp)
See 'docker service update --help'.

just wondering if we should change that behavior.

@thaJeztah
Copy link
Member

discussing this in the maintainers meeting, and we can keep it for a separate discussion.

@thaJeztah thaJeztah merged commit 032b5b2 into moby:master Dec 8, 2016
@GordonTheTurtle GordonTheTurtle added this to the 1.14.0 milestone Dec 8, 2016
@yongtang yongtang deleted the 1396-service-update-publish-rm branch December 8, 2016 19:26
dnephin pushed a commit to dnephin/docker that referenced this pull request Apr 17, 2017
…sh-rm

Return error for incorrect argument of `service update --publish-rm`
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.