-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Allow multiple rules from docker labels containers with traefik.<servicename>.* properties #1257
Conversation
c5f7099
to
65d36ac
Compare
a5c29e6
to
6310fdc
Compare
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.
Looks really good, just one small comment 👼
provider/docker.go
Outdated
|
||
// Extract entrypoints from labels for a given service and a given docker container | ||
func (provider *Docker) getServiceEntryPoints(container dockerData, serviceName string) []string { | ||
if entryPoints, ok := extractServicesLabels(container.Labels)[serviceName]["frontend.entryPoints"]; ok { |
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 a huge fan of that notation ; would have prefered to pass serviceName
and the key (here frontend.entryPoints
) as arguments (and thus make it sure these function don't care how the label are extracted, using maps or something else).
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.
ok so you prefer something more generic ?
getServiceValue $container $serviceName $key ?
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.
yeah, I don't want to surface the fact that this is a map or something else 👼
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.
if entryPoints, ok := getContainerServiceLabel(container, serviceName, "frontend.entryPoints")
looks of for you ?
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.
looks perfect to me 👼 👍
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've updated to call getContainerServiceLabel
(this new function is delegating to extractServicesLabels
)
Let me know if it's ok or if you want to remove as well the intermediate extractServicesLabels
@@ -2271,3 +2271,613 @@ func TestSwarmTaskParsing(t *testing.T) { | |||
} | |||
} | |||
} | |||
|
|||
func TestDockerGetServiceProtocol(t *testing.T) { |
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'll have to work on these, because our unit tests are way too verbose (but it's orthogonal to this PR, just thinking outloud 🤔 ).
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 for sure they are verbose ^^
cd36713
to
ca74d6d
Compare
updated |
ca74d6d
to
368f929
Compare
@intelradoux you can use Host in the front-end rule. So AFAIK this is possible with this PR |
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.
LGTM 🐯
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.
@benoitf Really good job 😍
LGTM
Could you squash your commits before we merge it ?
600596e
to
d2df258
Compare
@emilevauge ok done |
- traefik.mycustomservice.port=443 - traefik.mycustomservice.frontend.rule=Path:/mycustomservice - traefik.anothercustomservice.port=8080 - traefik.anothercustomservice.frontend.rule=Path:/anotherservice all traffic to frontend /mycustomservice is redirected to the port 443 of the container while using /anotherservice will redirect to the port 8080 of the docker container More documentation in the docs/toml.md file Change-Id: Ifaa3bb00ef0a0f38aa189e0ca1586fde8c5ed862 Signed-off-by: Florent BENOIT <[email protected]>
d2df258
to
1158eba
Compare
Merci, @benoitf! Merged. 😃 |
thx. So it won't be in 1.2 ? |
@benoitf yeah, putting this in 1.3 milestone. |
ok :) |
I am testing your PR now. I created simple service as
While putting old school I am running image |
@dcrystalj if you run into problems, please create a new issue and / or get in touch with the Traefik community on Slack. Thanks! |
@benoitf - Does this support multiple services if they reside on same port ? What if I want to hit two different paths based on the Host header ? |
Thanks to Traefik 1.3 now we can use only traefik for separating normal Odoo requests from longpolling ones. See traefik/traefik#1257.
Hi! Any chance to get this working on ECS backend? |
@reflog yes it's in my todo list. |
@ldez - that's awesome! Is there any way to simulate this behavior right now? I am trying add these two rules (they worked in docker):
Any suggestion on how do this this in ECS? Basically, if user comes to / , redirect to /api , otherwise, all requests start with /api. Thanks in advance! |
@reflog It's not the good place for questions. Come to the Traefik community Slack |
Ignore this, already resolved! Thanks for this feature! |
Tested and using this feature now - thanks! for other finding this, here was my simple test... Labels in docker compose: Simple verification: |
It matches expectation of #444
If labels contain for example:
traefik.mycustomservice.port=443
traefik.mycustomservice.frontend.rule=Path:/mycustomservice
traefik.anothercustomservice.port=8080
traefik.anothercustomservice.frontend.rule=Path:/anotherservice
all traffic to frontend on path
/mycustomservice
is redirected to the port443
of the container defining the label while using path/anotherservice
will redirect to the port8080
of the docker container defining the labelAvailable properties are
traefik.<service-name>.port
traefik.<service-name>.weight
traefik.<service-name>.protocol
traefik.<service-name>.frontend.backend
traefik.<service-name>.frontend.entryPoints
traefik.<service-name>.frontend.rule
traefik.<service-name>.frontend.passHostHeader
traefik.<service-name>.frontend.priority
traefik.<service-name>.frontend.rule
Change-Id: Ifaa3bb00ef0a0f38aa189e0ca1586fde8c5ed862
Signed-off-by: Florent BENOIT [email protected]