Skip to content

Remove --port and update --publish for services to support syntaxes#28943

Merged
thaJeztah merged 2 commits intomoby:masterfrom
vdemeester:publish-long-short-syntax
Dec 14, 2016
Merged

Remove --port and update --publish for services to support syntaxes#28943
thaJeztah merged 2 commits intomoby:masterfrom
vdemeester:publish-long-short-syntax

Conversation

@vdemeester
Copy link
Member

@vdemeester vdemeester commented Nov 29, 2016

This is part of #28527 — "The newly introduced --port flag should likely disappear in favor of --publish, ensuring that the short form maps cleanly to the long form"

  • Removing --port, --port-add, --port-rm flags
  • Add support for simple and complex syntax on --publish flag (and --publish-add, --publish-rm), using PortOpt
  • Validate the changes on PortOpt with unit tests.
$ docker service create --name t1 --publish 81:81/tcp --publish target=80,published=80,protocol=tcp,mode=ingress busybox top
# […]
$ docker service update --publish-add 82 --publish-rm 80:80/tcp --publish-add target=83 --publish-rm target=80 t1
# […]
  • Probably need a small refactoring to share the short/long syntax detection
  • Add one integration test to validate it works (but not all possible cases, covered by unit tests)

/cc @thaJeztah @icecrime @dnephin @mavenugo

🐸

Signed-off-by: Vincent Demeester [email protected]

@icecrime
Copy link
Contributor

Cc @vieux: I'm not sure if you want to take this for 1.13.0.

Copy link
Member

Choose a reason for hiding this comment

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

No, --port was added in 1.13, and is not present in 1.12

Copy link
Member Author

Choose a reason for hiding this comment

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

@thaJeztah you are too quick for me 😅

@vdemeester vdemeester force-pushed the publish-long-short-syntax branch from f9ef9e5 to 395d3bf Compare November 30, 2016 09:23
@LK4D4
Copy link
Contributor

LK4D4 commented Nov 30, 2016

LGTM
ping @vieux

Copy link
Contributor

@mavenugo mavenugo left a comment

Choose a reason for hiding this comment

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

Thanks @vdemeester
minor comments on tests. I will try it out and give more comments if any.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good tests. Can you also pls include a "ingress" mode test ?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah you're rihgt, I thought there was one, my bad 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

added 👼

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to not check for other default states such as Protocol, PublishMode ?
I think it is important to make sure the default protocol (tcp) and publishmode (ingress) are parsed appropriately

Copy link
Member Author

Choose a reason for hiding this comment

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

I should have added comment. This one is just about the required field (target here). The default protocol and publish mode are handled server side so the client doesn't send them (that's why the Swarm.PortConfig is that plain).

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

Copy link
Member

Choose a reason for hiding this comment

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

This line is unnecessary now

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right 😅

@vdemeester vdemeester force-pushed the publish-long-short-syntax branch from 0e2bbdd to b7fe613 Compare December 8, 2016 10:16
@mavenugo
Copy link
Contributor

mavenugo commented Dec 8, 2016

Thanks @vdemeester

LGTM

@vdemeester
Copy link
Member Author

ah right 👼

@vdemeester vdemeester force-pushed the publish-long-short-syntax branch from b7fe613 to 6dda197 Compare December 8, 2016 13:32
@vdemeester
Copy link
Member Author

@thaJeztah updated 👼

@mavenugo
Copy link
Contributor

mavenugo commented Dec 8, 2016

@vdemeester rebase needed :(

@thaJeztah
Copy link
Member

Found one issue; if defaults are omitted during service update, the previous value is not changed;

publish on port 8080, "ingress" mode

docker service create --publish published=8080,target=80,protocol=tcp --name web nginx:alpine

docker service inspect --format '{{ json .Spec.EndpointSpec.Ports }}' web
[{"Protocol":"tcp","TargetPort":80,"PublishedPort":8080,"PublishMode":"ingress"}]

change to "host" mode

docker service update --publish-rm 80 --publish-add published=8080,target=80,protocol=tcp,mode=host web

docker service inspect --format '{{ json .Spec.EndpointSpec.Ports }}' web
[{"Protocol":"tcp","TargetPort":80,"PublishedPort":8080,"PublishMode":"host"}]

change back to "ingress" mode

docker service update --publish-rm 80 --publish-add published=8080,target=80,protocol=tcp web

docker service inspect --format '{{ json .Spec.EndpointSpec.Ports }}' web
[{"Protocol":"tcp","TargetPort":80,"PublishedPort":8080,"PublishMode":"host"}]

publish on port 8080, "tcp" (default)

docker service create --publish published=8080,target=80 --name web nginx:alpine

docker service inspect --format '{{ json .Spec.EndpointSpec.Ports }}' web
[{"Protocol":"tcp","TargetPort":80,"PublishedPort":8080,"PublishMode":"ingress"}]

change to "udp"

docker service update --publish-rm 80 --publish-add published=8080,target=80,protocol=udp web

docker service inspect --format '{{ json .Spec.EndpointSpec.Ports }}' web
[{"Protocol":"udp","TargetPort":80,"PublishedPort":8080,"PublishMode":"ingress"}]

change back to "tcp" (default)

docker service update --publish-rm 80 --publish-add published=8080,target=80 web

docker service inspect --format '{{ json .Spec.EndpointSpec.Ports }}' web
[{"Protocol":"udp","TargetPort":80,"PublishedPort":8080,"PublishMode":"ingress"}]

@vdemeester vdemeester force-pushed the publish-long-short-syntax branch from 6dda197 to a05fc7a Compare December 8, 2016 21:32
@vdemeester
Copy link
Member Author

So… this is conflicting with #25860 😅 I temporarly disabled the validation and added comment because I'm not sure about what to do…

@vdemeester
Copy link
Member Author

vdemeester commented Dec 8, 2016

Please look closely at 9d4aa36 (this fixes @thaJeztah's comment BUT changes a little bit the UX to something that feels more natural).

With that commit, --publish-add 8081:81 --publish-add 8082:82 --publish-rm 80 --publish-rm 81/tcp --publish-rm 82/ucp would thus result in 81 and 82 to be published (instead of only 82 currently).

/cc @dnephin @thaJeztah @icecrime @mavenugo @aaronlehmann @stevvooe

@vdemeester vdemeester force-pushed the publish-long-short-syntax branch 2 times, most recently from ed452c7 to 7332444 Compare December 9, 2016 20:18
Add support for simple and complex syntax to `--publish` through the
use of `PortOpt`.

Signed-off-by: Vincent Demeester <[email protected]>
`--publish-add 8081:81 --publish-add 8082:82 --publish-rm 80
--publish-rm 81/tcp --publish-rm 82/tcp` would thus result in 81 and
82 to be published.

Signed-off-by: Vincent Demeester <[email protected]>
@vdemeester vdemeester force-pushed the publish-long-short-syntax branch from 7332444 to 9d4aa36 Compare December 11, 2016 22:15
@vdemeester
Copy link
Member Author

Rebased 👼

@thaJeztah
Copy link
Member

Testing my previous examples, I ran into this; adding a port in mode "host" cannot be removed using the "simple" syntax

$ docker service create --publish published=8080,target=80,protocol=tcp,mode=host --name web nginx:alpine
oq5jnkhug6hjddtewift80dz9

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

$ docker service inspect --format '{{ json .Spec.EndpointSpec.Ports }}' web
[{"Protocol":"tcp","TargetPort":80,"PublishedPort":8080,"PublishMode":"host"}]

This worked;

$ docker service update --publish-rm target=80,mode=host web
web

$ docker service inspect --format '{{ json .Spec.EndpointSpec.Ports }}' web
null

@mavenugo
Copy link
Contributor

@thaJeztah @vdemeester @vieux we need this for 1.13.0 and I think @thaJeztah's UX observation is expected. Do we have any concerns with this PR still to be merged and cherry-picked ?

@thaJeztah
Copy link
Member

@mavenugo I'm good with this PR, just wanted confirmation that we agree on the change in behavior, i.e.;

  • previously, when having both --publish-rm, and --publish-add, --publish-rm would always be executed last. This meant that you could not "replace" a port in a single update.
  • the new change always performs --publish-rm first, then adds the new ports specified in --publish-add.

I think this was an oversight in the original implementation, and I cannot think of a practical use of adding a new port and removing it in the same update. Similarly, I cannot think of a case where this would be a real "breaking" change.

If we agree on this, I suggest we look at other -rm and -add flags, which currently may use the "wrong" behavior as well (at least secrets)

@mavenugo
Copy link
Contributor

@thaJeztah I agree. the current behaviour is more correct than the previous one.
This PR already has my LGTM.

@thaJeztah
Copy link
Member

ok, let's go for it 👍

@thaJeztah thaJeztah merged commit 2fe62f2 into moby:master Dec 14, 2016
@vdemeester vdemeester deleted the publish-long-short-syntax branch December 14, 2016 17:00
dnephin pushed a commit to dnephin/docker that referenced this pull request Apr 17, 2017
Remove --port and update --publish for services to support syntaxes
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.

8 participants