-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Uses both binded HostIP and HostPort when useBindPortIP=true #3638
Conversation
provider/docker/config.go
Outdated
@@ -322,22 +311,49 @@ func getPort(container dockerData) string { | |||
return "" | |||
} | |||
|
|||
func (p *Provider) getPortBinding(container dockerData) (nat.PortBinding, error) { |
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.
could you return a pointer (*nat.PortBinding
) instead of a struct?
provider/docker/config.go
Outdated
} | ||
} | ||
|
||
return nat.PortBinding{HostIP: "", HostPort: ""}, fmt.Errorf("Unable to find the external IP:Port for the container %q", container.Name) |
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.
return nil.
https://github.com/golang/go/wiki/CodeReviewComments#error-strings
fmt.Errorf("unable to find the external IP:Port for the container %q", container.Name)
provider/docker/config.go
Outdated
portBinding, err := p.getPortBinding(container) | ||
if err != nil { | ||
log.Warnf("Unable to find a binding for the container %q: ignoring server", container.Name) | ||
continue |
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.
could you create a function that returns an error to replace the continue
provider/docker/config.go
Outdated
log.Warnf("Unable to find a binding for the container %q: ignoring server", container.Name) | ||
continue | ||
} | ||
if portBinding.HostIP != "0.0.0.0" { |
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.
fail fast: could you invert the condition:
if portBinding.HostIP == "0.0.0.0" {
// ...
}
// ...
The else
is not needed.
provider/docker/config.go
Outdated
@@ -347,6 +363,9 @@ func (p *Provider) getServers(containers []dockerData) map[string]types.Server { | |||
continue | |||
} | |||
|
|||
if servers == nil { | |||
servers = make(map[string]types.Server) |
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.
the map initialization must be done before.
provider/docker/deprecated_config.go
Outdated
"getPort": getPortV1, | ||
"getWeight": getFuncIntLabelV1(label.TraefikWeight, label.DefaultWeight), | ||
"getProtocol": getFuncStringLabelV1(label.TraefikProtocol, label.DefaultProtocol), | ||
"getDeprecatedIPAddress": p.getDeprecatedIPAddress, |
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.
Should be "getIPAddress"
instead of "getDeprecatedIPAddress"
provider/docker/config.go
Outdated
"getBuffering": label.GetBuffering, | ||
"getCircuitBreaker": label.GetCircuitBreaker, | ||
"getLoadBalancer": label.GetLoadBalancer, | ||
"getDeprecatedIPAddress": p.getDeprecatedIPAddress, // TODO: Should we expose getIPPort instead? |
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.
Should be "getIPAddress"
instead of "getDeprecatedIPAddress"
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.
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.
LGTM 🐳 👏
What does this PR do?
Context: docker provider with usebindportip
Currently:
traefik.port
is specified, it is used both for selecting the binding and in the routeThis PR:
traefik.port
is used to select the binding (which enables the use of segments)To sum it up:
traefik.port
not setIP_E1:P_E1:P_I1
IP_E1:P_E1
traefik.port
not setP_E1:P_I1
0.0.0.0
)traefik.port
not settraefik.port=P_I1
IP_E1:P_E1:P_I1
IP_E1:P_E1
traefik.port=P_I2
IP_E1:P_E1:P_I1
XX:XX:P_I2
)traefik.port=P_I2
IP_E1:P_E1:P_I1
&IP_E2:P_E2:P_I2
IP_E2:P_E2
traefik.port=P_I1
Motivation
Fixes #3622
(kudos to @systemmonkey42 for the awesome description in the issue)
More
Examples
docker-compose.yml
traefik/api