Factorize labels

* refactor(accesslog): factorize file name.
* traefik.frontend.rule
* traefik.frontend.value
* traefik.backend.circuitbreaker.expression
* traefik.enable
* traefik.backend.loadbalancer.method
* traefik.backend.loadbalancer.sticky
* traefik.backend.maxconn.amount
* traefik.backend.maxconn.extractorfunc
* traefik.port
* traefik.tags
* traefik.backend
* traefik.weight
* traefik.domain
* traefik.protocol
* traefik.frontend.passHostHeader
* traefik.frontend.whitelistSourceRange
* traefik.frontend.priority
* traefik.frontend.entryPoints
* traefik.frontend.auth.basic
* traefik.backend.id
* traefik.backend.circuitbreaker
* traefik.frontend.rule.type
* traefik.portIndex
* refactor(docker): specific labels
* refactor(rancher): specific labels
* traefik.backend.healthcheck.*
* refactor(providers): factorize labels.
This commit is contained in:
Ludovic Fernandez 2017-07-10 16:58:12 +02:00 committed by SALLEYRON Julien
parent 2e84b1e556
commit d653a348b1
20 changed files with 390 additions and 330 deletions

View file

@ -16,13 +16,18 @@ import (
checker "github.com/vdemeester/shakers" checker "github.com/vdemeester/shakers"
) )
const (
traefikTestLogFile = "traefik.log"
traefikTestAccessLogFile = "access.log"
)
// AccessLogSuite // AccessLogSuite
type AccessLogSuite struct{ BaseSuite } type AccessLogSuite struct{ BaseSuite }
func (s *AccessLogSuite) TestAccessLog(c *check.C) { func (s *AccessLogSuite) TestAccessLog(c *check.C) {
// Ensure working directory is clean // Ensure working directory is clean
os.Remove("access.log") os.Remove(traefikTestAccessLogFile)
os.Remove("traefik.log") os.Remove(traefikTestLogFile)
// Start Traefik // Start Traefik
cmd, _ := s.cmdTraefik(withConfigFile("fixtures/access_log_config.toml")) cmd, _ := s.cmdTraefik(withConfigFile("fixtures/access_log_config.toml"))
@ -30,11 +35,11 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
defer os.Remove("access.log") defer os.Remove(traefikTestAccessLogFile)
defer os.Remove("traefik.log") defer os.Remove(traefikTestLogFile)
err = try.Do(1*time.Second, func() error { err = try.Do(1*time.Second, func() error {
if _, err := os.Stat("traefik.log"); err != nil { if _, err := os.Stat(traefikTestLogFile); err != nil {
return fmt.Errorf("could not get stats for log file: %s", err) return fmt.Errorf("could not get stats for log file: %s", err)
} }
return nil return nil
@ -42,7 +47,7 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify Traefik started OK // Verify Traefik started OK
traefikLog, err := ioutil.ReadFile("traefik.log") traefikLog, err := ioutil.ReadFile(traefikTestLogFile)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
if len(traefikLog) > 0 { if len(traefikLog) > 0 {
fmt.Printf("%s\n", string(traefikLog)) fmt.Printf("%s\n", string(traefikLog))
@ -66,7 +71,7 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
// Verify access.log output as expected // Verify access.log output as expected
accessLog, err := ioutil.ReadFile("access.log") accessLog, err := ioutil.ReadFile(traefikTestAccessLogFile)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
lines := strings.Split(string(accessLog), "\n") lines := strings.Split(string(accessLog), "\n")
count := 0 count := 0
@ -86,7 +91,7 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
c.Assert(count, checker.GreaterOrEqualThan, 3) c.Assert(count, checker.GreaterOrEqualThan, 3)
// Verify no other Traefik problems // Verify no other Traefik problems
traefikLog, err = ioutil.ReadFile("traefik.log") traefikLog, err = ioutil.ReadFile(traefikTestLogFile)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
if len(traefikLog) > 0 { if len(traefikLog) > 0 {
fmt.Printf("%s\n", string(traefikLog)) fmt.Printf("%s\n", string(traefikLog))

View file

@ -10,9 +10,9 @@ import (
"time" "time"
"github.com/containous/traefik/integration/try" "github.com/containous/traefik/integration/try"
"github.com/containous/traefik/types"
"github.com/docker/docker/pkg/namesgenerator" "github.com/docker/docker/pkg/namesgenerator"
"github.com/go-check/check" "github.com/go-check/check"
d "github.com/libkermit/docker" d "github.com/libkermit/docker"
docker "github.com/libkermit/docker-check" docker "github.com/libkermit/docker-check"
checker "github.com/vdemeester/shakers" checker "github.com/vdemeester/shakers"
@ -123,7 +123,7 @@ func (s *DockerSuite) TestDockerContainersWithLabels(c *check.C) {
defer os.Remove(file) defer os.Remove(file)
// Start a container with some labels // Start a container with some labels
labels := map[string]string{ labels := map[string]string{
"traefik.frontend.rule": "Host:my.super.host", types.LabelFrontendRule: "Host:my.super.host",
} }
s.startContainerWithLabels(c, "swarm:1.0.0", labels, "manage", "token://blabla") s.startContainerWithLabels(c, "swarm:1.0.0", labels, "manage", "token://blabla")
@ -155,7 +155,7 @@ func (s *DockerSuite) TestDockerContainersWithOneMissingLabels(c *check.C) {
defer os.Remove(file) defer os.Remove(file)
// Start a container with some labels // Start a container with some labels
labels := map[string]string{ labels := map[string]string{
"traefik.frontend.value": "my.super.host", types.LabelTraefikFrontendValue: "my.super.host",
} }
s.startContainerWithLabels(c, "swarm:1.0.0", labels, "manage", "token://blabla") s.startContainerWithLabels(c, "swarm:1.0.0", labels, "manage", "token://blabla")

View file

@ -35,6 +35,11 @@ const (
SwarmAPIVersion string = "1.24" SwarmAPIVersion string = "1.24"
// SwarmDefaultWatchTime is the duration of the interval when polling docker // SwarmDefaultWatchTime is the duration of the interval when polling docker
SwarmDefaultWatchTime = 15 * time.Second SwarmDefaultWatchTime = 15 * time.Second
labelDockerNetwork = "traefik.docker.network"
labelBackendLoadbalancerSwarm = "traefik.backend.loadbalancer.swarm"
labelDockerComposeProject = "com.docker.compose.project"
labelDockerComposeService = "com.docker.compose.service"
) )
var _ provider.Provider = (*Provider)(nil) var _ provider.Provider = (*Provider)(nil)
@ -319,7 +324,7 @@ func (p *Provider) loadDockerConfig(containersInspected []dockerData) *types.Con
} }
func (p *Provider) hasCircuitBreakerLabel(container dockerData) bool { func (p *Provider) hasCircuitBreakerLabel(container dockerData) bool {
if _, err := getLabel(container, "traefik.backend.circuitbreaker.expression"); err != nil { if _, err := getLabel(container, types.LabelBackendCircuitbreakerExpression); err != nil {
return false return false
} }
return true return true
@ -455,8 +460,8 @@ func (p *Provider) getServiceProtocol(container dockerData, serviceName string)
} }
func (p *Provider) hasLoadBalancerLabel(container dockerData) bool { func (p *Provider) hasLoadBalancerLabel(container dockerData) bool {
_, errMethod := getLabel(container, "traefik.backend.loadbalancer.method") _, errMethod := getLabel(container, types.LabelBackendLoadbalancerMethod)
_, errSticky := getLabel(container, "traefik.backend.loadbalancer.sticky") _, errSticky := getLabel(container, types.LabelBackendLoadbalancerSticky)
if errMethod != nil && errSticky != nil { if errMethod != nil && errSticky != nil {
return false return false
} }
@ -464,31 +469,31 @@ func (p *Provider) hasLoadBalancerLabel(container dockerData) bool {
} }
func (p *Provider) hasMaxConnLabels(container dockerData) bool { func (p *Provider) hasMaxConnLabels(container dockerData) bool {
if _, err := getLabel(container, "traefik.backend.maxconn.amount"); err != nil { if _, err := getLabel(container, types.LabelBackendMaxconnAmount); err != nil {
return false return false
} }
if _, err := getLabel(container, "traefik.backend.maxconn.extractorfunc"); err != nil { if _, err := getLabel(container, types.LabelBackendMaxconnExtractorfunc); err != nil {
return false return false
} }
return true return true
} }
func (p *Provider) getCircuitBreakerExpression(container dockerData) string { func (p *Provider) getCircuitBreakerExpression(container dockerData) string {
if label, err := getLabel(container, "traefik.backend.circuitbreaker.expression"); err == nil { if label, err := getLabel(container, types.LabelBackendCircuitbreakerExpression); err == nil {
return label return label
} }
return "NetworkErrorRatio() > 1" return "NetworkErrorRatio() > 1"
} }
func (p *Provider) getLoadBalancerMethod(container dockerData) string { func (p *Provider) getLoadBalancerMethod(container dockerData) string {
if label, err := getLabel(container, "traefik.backend.loadbalancer.method"); err == nil { if label, err := getLabel(container, types.LabelBackendLoadbalancerMethod); err == nil {
return label return label
} }
return "wrr" return "wrr"
} }
func (p *Provider) getMaxConnAmount(container dockerData) int64 { func (p *Provider) getMaxConnAmount(container dockerData) int64 {
if label, err := getLabel(container, "traefik.backend.maxconn.amount"); err == nil { if label, err := getLabel(container, types.LabelBackendMaxconnAmount); err == nil {
i, errConv := strconv.ParseInt(label, 10, 64) i, errConv := strconv.ParseInt(label, 10, 64)
if errConv != nil { if errConv != nil {
log.Errorf("Unable to parse traefik.backend.maxconn.amount %s", label) log.Errorf("Unable to parse traefik.backend.maxconn.amount %s", label)
@ -500,14 +505,14 @@ func (p *Provider) getMaxConnAmount(container dockerData) int64 {
} }
func (p *Provider) getMaxConnExtractorFunc(container dockerData) string { func (p *Provider) getMaxConnExtractorFunc(container dockerData) string {
if label, err := getLabel(container, "traefik.backend.maxconn.extractorfunc"); err == nil { if label, err := getLabel(container, types.LabelBackendMaxconnExtractorfunc); err == nil {
return label return label
} }
return "request.host" return "request.host"
} }
func (p *Provider) containerFilter(container dockerData) bool { func (p *Provider) containerFilter(container dockerData) bool {
_, err := strconv.Atoi(container.Labels["traefik.port"]) _, err := strconv.Atoi(container.Labels[types.LabelPort])
if len(container.NetworkSettings.Ports) == 0 && err != nil { if len(container.NetworkSettings.Ports) == 0 && err != nil {
log.Debugf("Filtering container without port and no traefik.port label %s", container.Name) log.Debugf("Filtering container without port and no traefik.port label %s", container.Name)
return false return false
@ -518,7 +523,7 @@ func (p *Provider) containerFilter(container dockerData) bool {
return false return false
} }
constraintTags := strings.Split(container.Labels["traefik.tags"], ",") constraintTags := strings.Split(container.Labels[types.LabelTags], ",")
if ok, failingConstraint := p.MatchConstraints(constraintTags); !ok { if ok, failingConstraint := p.MatchConstraints(constraintTags); !ok {
if failingConstraint != nil { if failingConstraint != nil {
log.Debugf("Container %v pruned by '%v' constraint", container.Name, failingConstraint.String()) log.Debugf("Container %v pruned by '%v' constraint", container.Name, failingConstraint.String())
@ -547,11 +552,11 @@ func (p *Provider) getFrontendName(container dockerData) string {
// GetFrontendRule returns the frontend rule for the specified container, using // GetFrontendRule returns the frontend rule for the specified container, using
// it's label. It returns a default one (Host) if the label is not present. // it's label. It returns a default one (Host) if the label is not present.
func (p *Provider) getFrontendRule(container dockerData) string { func (p *Provider) getFrontendRule(container dockerData) string {
if label, err := getLabel(container, "traefik.frontend.rule"); err == nil { if label, err := getLabel(container, types.LabelFrontendRule); err == nil {
return label return label
} }
if labels, err := getLabels(container, []string{"com.docker.compose.project", "com.docker.compose.service"}); err == nil { if labels, err := getLabels(container, []string{labelDockerComposeProject, labelDockerComposeService}); err == nil {
return "Host:" + p.getSubDomain(labels["com.docker.compose.service"]+"."+labels["com.docker.compose.project"]) + "." + p.Domain return "Host:" + p.getSubDomain(labels[labelDockerComposeService]+"."+labels[labelDockerComposeProject]) + "." + p.Domain
} }
if len(p.Domain) > 0 { if len(p.Domain) > 0 {
return "Host:" + p.getSubDomain(container.ServiceName) + "." + p.Domain return "Host:" + p.getSubDomain(container.ServiceName) + "." + p.Domain
@ -560,17 +565,17 @@ func (p *Provider) getFrontendRule(container dockerData) string {
} }
func (p *Provider) getBackend(container dockerData) string { func (p *Provider) getBackend(container dockerData) string {
if label, err := getLabel(container, "traefik.backend"); err == nil { if label, err := getLabel(container, types.LabelBackend); err == nil {
return provider.Normalize(label) return provider.Normalize(label)
} }
if labels, err := getLabels(container, []string{"com.docker.compose.project", "com.docker.compose.service"}); err == nil { if labels, err := getLabels(container, []string{labelDockerComposeProject, labelDockerComposeService}); err == nil {
return provider.Normalize(labels["com.docker.compose.service"] + "_" + labels["com.docker.compose.project"]) return provider.Normalize(labels[labelDockerComposeService] + "_" + labels[labelDockerComposeProject])
} }
return provider.Normalize(container.ServiceName) return provider.Normalize(container.ServiceName)
} }
func (p *Provider) getIPAddress(container dockerData) string { func (p *Provider) getIPAddress(container dockerData) string {
if label, err := getLabel(container, "traefik.docker.network"); err == nil && label != "" { if label, err := getLabel(container, labelDockerNetwork); err == nil && label != "" {
networkSettings := container.NetworkSettings networkSettings := container.NetworkSettings
if networkSettings.Networks != nil { if networkSettings.Networks != nil {
network := networkSettings.Networks[label] network := networkSettings.Networks[label]
@ -606,7 +611,7 @@ func (p *Provider) getIPAddress(container dockerData) string {
} }
func (p *Provider) getPort(container dockerData) string { func (p *Provider) getPort(container dockerData) string {
if label, err := getLabel(container, "traefik.port"); err == nil { if label, err := getLabel(container, types.LabelPort); err == nil {
return label return label
} }
@ -630,42 +635,42 @@ func (p *Provider) getPort(container dockerData) string {
} }
func (p *Provider) getWeight(container dockerData) string { func (p *Provider) getWeight(container dockerData) string {
if label, err := getLabel(container, "traefik.weight"); err == nil { if label, err := getLabel(container, types.LabelWeight); err == nil {
return label return label
} }
return "0" return "0"
} }
func (p *Provider) getSticky(container dockerData) string { func (p *Provider) getSticky(container dockerData) string {
if label, err := getLabel(container, "traefik.backend.loadbalancer.sticky"); err == nil { if label, err := getLabel(container, types.LabelBackendLoadbalancerSticky); err == nil {
return label return label
} }
return "false" return "false"
} }
func (p *Provider) getIsBackendLBSwarm(container dockerData) string { func (p *Provider) getIsBackendLBSwarm(container dockerData) string {
if label, err := getLabel(container, "traefik.backend.loadbalancer.swarm"); err == nil { if label, err := getLabel(container, labelBackendLoadbalancerSwarm); err == nil {
return label return label
} }
return "false" return "false"
} }
func (p *Provider) getDomain(container dockerData) string { func (p *Provider) getDomain(container dockerData) string {
if label, err := getLabel(container, "traefik.domain"); err == nil { if label, err := getLabel(container, types.LabelDomain); err == nil {
return label return label
} }
return p.Domain return p.Domain
} }
func (p *Provider) getProtocol(container dockerData) string { func (p *Provider) getProtocol(container dockerData) string {
if label, err := getLabel(container, "traefik.protocol"); err == nil { if label, err := getLabel(container, types.LabelProtocol); err == nil {
return label return label
} }
return "http" return "http"
} }
func (p *Provider) getPassHostHeader(container dockerData) string { func (p *Provider) getPassHostHeader(container dockerData) string {
if passHostHeader, err := getLabel(container, "traefik.frontend.passHostHeader"); err == nil { if passHostHeader, err := getLabel(container, types.LabelFrontendPassHostHeader); err == nil {
return passHostHeader return passHostHeader
} }
return "true" return "true"
@ -674,28 +679,28 @@ func (p *Provider) getPassHostHeader(container dockerData) string {
func (p *Provider) getWhitelistSourceRange(container dockerData) []string { func (p *Provider) getWhitelistSourceRange(container dockerData) []string {
var whitelistSourceRange []string var whitelistSourceRange []string
if whitelistSourceRangeLabel, err := getLabel(container, "traefik.frontend.whitelistSourceRange"); err == nil { if whitelistSourceRangeLabel, err := getLabel(container, types.LabelTraefikFrontendWhitelistSourceRange); err == nil {
whitelistSourceRange = provider.SplitAndTrimString(whitelistSourceRangeLabel) whitelistSourceRange = provider.SplitAndTrimString(whitelistSourceRangeLabel)
} }
return whitelistSourceRange return whitelistSourceRange
} }
func (p *Provider) getPriority(container dockerData) string { func (p *Provider) getPriority(container dockerData) string {
if priority, err := getLabel(container, "traefik.frontend.priority"); err == nil { if priority, err := getLabel(container, types.LabelFrontendPriority); err == nil {
return priority return priority
} }
return "0" return "0"
} }
func (p *Provider) getEntryPoints(container dockerData) []string { func (p *Provider) getEntryPoints(container dockerData) []string {
if entryPoints, err := getLabel(container, "traefik.frontend.entryPoints"); err == nil { if entryPoints, err := getLabel(container, types.LabelFrontendEntryPoints); err == nil {
return strings.Split(entryPoints, ",") return strings.Split(entryPoints, ",")
} }
return []string{} return []string{}
} }
func (p *Provider) getBasicAuth(container dockerData) []string { func (p *Provider) getBasicAuth(container dockerData) []string {
if basicAuth, err := getLabel(container, "traefik.frontend.auth.basic"); err == nil { if basicAuth, err := getLabel(container, types.LabelFrontendAuthBasic); err == nil {
return strings.Split(basicAuth, ",") return strings.Split(basicAuth, ",")
} }
@ -703,7 +708,7 @@ func (p *Provider) getBasicAuth(container dockerData) []string {
} }
func isContainerEnabled(container dockerData, exposedByDefault bool) bool { func isContainerEnabled(container dockerData, exposedByDefault bool) bool {
return exposedByDefault && container.Labels["traefik.enable"] != "false" || container.Labels["traefik.enable"] == "true" return exposedByDefault && container.Labels[types.LabelEnable] != "false" || container.Labels[types.LabelEnable] == "true"
} }
func getLabel(container dockerData, label string) (string, error) { func getLabel(container dockerData, label string) (string, error) {

View file

@ -23,7 +23,7 @@ func TestDockerGetFrontendName(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.rule": "Headers:User-Agent,bat/0.1.0", types.LabelFrontendRule: "Headers:User-Agent,bat/0.1.0",
})), })),
expected: "Headers-User-Agent-bat-0-1-0", expected: "Headers-User-Agent-bat-0-1-0",
}, },
@ -36,19 +36,19 @@ func TestDockerGetFrontendName(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
})), })),
expected: "Host-foo-bar", expected: "Host-foo-bar",
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.rule": "Path:/test", types.LabelFrontendRule: "Path:/test",
})), })),
expected: "Path-test", expected: "Path-test",
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.rule": "PathPrefix:/test2", types.LabelFrontendRule: "PathPrefix:/test2",
})), })),
expected: "PathPrefix-test2", expected: "PathPrefix-test2",
}, },
@ -85,7 +85,7 @@ func TestDockerGetFrontendRule(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
})), })),
expected: "Host:foo.bar", expected: "Host:foo.bar",
}, { }, {
@ -97,7 +97,7 @@ func TestDockerGetFrontendRule(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.rule": "Path:/test", types.LabelFrontendRule: "Path:/test",
})), })),
expected: "Path:/test", expected: "Path:/test",
}, },
@ -134,7 +134,7 @@ func TestDockerGetBackend(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.backend": "foobar", types.LabelBackend: "foobar",
})), })),
expected: "foobar", expected: "foobar",
}, },
@ -173,7 +173,7 @@ func TestDockerGetIPAddress(t *testing.T) {
{ {
container: containerJSON( container: containerJSON(
labels(map[string]string{ labels(map[string]string{
"traefik.docker.network": "testnet", labelDockerNetwork: "testnet",
}), }),
withNetwork("testnet", ipv4("10.11.12.13")), withNetwork("testnet", ipv4("10.11.12.13")),
), ),
@ -182,7 +182,7 @@ func TestDockerGetIPAddress(t *testing.T) {
{ {
container: containerJSON( container: containerJSON(
labels(map[string]string{ labels(map[string]string{
"traefik.docker.network": "testnet2", labelDockerNetwork: "testnet2",
}), }),
withNetwork("testnet", ipv4("10.11.12.13")), withNetwork("testnet", ipv4("10.11.12.13")),
withNetwork("testnet2", ipv4("10.11.12.14")), withNetwork("testnet2", ipv4("10.11.12.14")),
@ -237,13 +237,13 @@ func TestDockerGetPort(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.port": "8080", types.LabelPort: "8080",
})), })),
expected: "8080", expected: "8080",
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.port": "8080", types.LabelPort: "8080",
}), ports(nat.PortMap{ }), ports(nat.PortMap{
"80/tcp": {}, "80/tcp": {},
})), })),
@ -251,7 +251,7 @@ func TestDockerGetPort(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.port": "8080", types.LabelPort: "8080",
}), ports(nat.PortMap{ }), ports(nat.PortMap{
"8080/tcp": {}, "8080/tcp": {},
"80/tcp": {}, "80/tcp": {},
@ -285,7 +285,7 @@ func TestDockerGetWeight(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.weight": "10", types.LabelWeight: "10",
})), })),
expected: "10", expected: "10",
}, },
@ -316,7 +316,7 @@ func TestDockerGetDomain(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.domain": "foo.bar", types.LabelDomain: "foo.bar",
})), })),
expected: "foo.bar", expected: "foo.bar",
}, },
@ -349,7 +349,7 @@ func TestDockerGetProtocol(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.protocol": "https", types.LabelProtocol: "https",
})), })),
expected: "https", expected: "https",
}, },
@ -380,7 +380,7 @@ func TestDockerGetPassHostHeader(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.passHostHeader": "false", types.LabelFrontendPassHostHeader: "false",
})), })),
expected: "false", expected: "false",
}, },
@ -414,14 +414,14 @@ func TestDockerGetWhitelistSourceRange(t *testing.T) {
{ {
desc: "whitelist-label with empty string", desc: "whitelist-label with empty string",
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.whitelistSourceRange": "", types.LabelTraefikFrontendWhitelistSourceRange: "",
})), })),
expected: nil, expected: nil,
}, },
{ {
desc: "whitelist-label with IPv4 mask", desc: "whitelist-label with IPv4 mask",
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.whitelistSourceRange": "1.2.3.4/16", types.LabelTraefikFrontendWhitelistSourceRange: "1.2.3.4/16",
})), })),
expected: []string{ expected: []string{
"1.2.3.4/16", "1.2.3.4/16",
@ -430,7 +430,7 @@ func TestDockerGetWhitelistSourceRange(t *testing.T) {
{ {
desc: "whitelist-label with IPv6 mask", desc: "whitelist-label with IPv6 mask",
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.whitelistSourceRange": "fe80::/16", types.LabelTraefikFrontendWhitelistSourceRange: "fe80::/16",
})), })),
expected: []string{ expected: []string{
"fe80::/16", "fe80::/16",
@ -439,7 +439,7 @@ func TestDockerGetWhitelistSourceRange(t *testing.T) {
{ {
desc: "whitelist-label with multiple masks", desc: "whitelist-label with multiple masks",
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.whitelistSourceRange": "1.1.1.1/24, 1234:abcd::42/32", types.LabelTraefikFrontendWhitelistSourceRange: "1.1.1.1/24, 1234:abcd::42/32",
})), })),
expected: []string{ expected: []string{
"1.1.1.1/24", "1.1.1.1/24",
@ -576,7 +576,7 @@ func TestDockerTraefikFilter(t *testing.T) {
}, },
Config: &container.Config{ Config: &container.Config{
Labels: map[string]string{ Labels: map[string]string{
"traefik.enable": "false", types.LabelEnable: "false",
}, },
}, },
NetworkSettings: &docker.NetworkSettings{ NetworkSettings: &docker.NetworkSettings{
@ -600,7 +600,7 @@ func TestDockerTraefikFilter(t *testing.T) {
}, },
Config: &container.Config{ Config: &container.Config{
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
}, },
}, },
NetworkSettings: &docker.NetworkSettings{ NetworkSettings: &docker.NetworkSettings{
@ -665,7 +665,7 @@ func TestDockerTraefikFilter(t *testing.T) {
}, },
Config: &container.Config{ Config: &container.Config{
Labels: map[string]string{ Labels: map[string]string{
"traefik.port": "80", types.LabelPort: "80",
}, },
}, },
NetworkSettings: &docker.NetworkSettings{ NetworkSettings: &docker.NetworkSettings{
@ -690,7 +690,7 @@ func TestDockerTraefikFilter(t *testing.T) {
}, },
Config: &container.Config{ Config: &container.Config{
Labels: map[string]string{ Labels: map[string]string{
"traefik.enable": "true", types.LabelEnable: "true",
}, },
}, },
NetworkSettings: &docker.NetworkSettings{ NetworkSettings: &docker.NetworkSettings{
@ -714,7 +714,7 @@ func TestDockerTraefikFilter(t *testing.T) {
}, },
Config: &container.Config{ Config: &container.Config{
Labels: map[string]string{ Labels: map[string]string{
"traefik.enable": "anything", types.LabelEnable: "anything",
}, },
}, },
NetworkSettings: &docker.NetworkSettings{ NetworkSettings: &docker.NetworkSettings{
@ -738,7 +738,7 @@ func TestDockerTraefikFilter(t *testing.T) {
}, },
Config: &container.Config{ Config: &container.Config{
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
}, },
}, },
NetworkSettings: &docker.NetworkSettings{ NetworkSettings: &docker.NetworkSettings{
@ -782,7 +782,7 @@ func TestDockerTraefikFilter(t *testing.T) {
}, },
Config: &container.Config{ Config: &container.Config{
Labels: map[string]string{ Labels: map[string]string{
"traefik.enable": "true", types.LabelEnable: "true",
}, },
}, },
NetworkSettings: &docker.NetworkSettings{ NetworkSettings: &docker.NetworkSettings{
@ -806,7 +806,7 @@ func TestDockerTraefikFilter(t *testing.T) {
}, },
Config: &container.Config{ Config: &container.Config{
Labels: map[string]string{ Labels: map[string]string{
"traefik.enable": "true", types.LabelEnable: "true",
}, },
}, },
NetworkSettings: &docker.NetworkSettings{ NetworkSettings: &docker.NetworkSettings{
@ -829,8 +829,8 @@ func TestDockerTraefikFilter(t *testing.T) {
}, },
Config: &container.Config{ Config: &container.Config{
Labels: map[string]string{ Labels: map[string]string{
"traefik.enable": "true", types.LabelEnable: "true",
"traefik.frontend.rule": "Host:i.love.this.host", types.LabelFrontendRule: "Host:i.love.this.host",
}, },
}, },
NetworkSettings: &docker.NetworkSettings{ NetworkSettings: &docker.NetworkSettings{
@ -912,9 +912,9 @@ func TestDockerLoadDockerConfig(t *testing.T) {
containerJSON( containerJSON(
name("test1"), name("test1"),
labels(map[string]string{ labels(map[string]string{
"traefik.backend": "foobar", types.LabelBackend: "foobar",
"traefik.frontend.entryPoints": "http,https", types.LabelFrontendEntryPoints: "http,https",
"traefik.frontend.auth.basic": "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0", types.LabelFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
}), }),
ports(nat.PortMap{ ports(nat.PortMap{
"80/tcp": {}, "80/tcp": {},
@ -924,7 +924,7 @@ func TestDockerLoadDockerConfig(t *testing.T) {
containerJSON( containerJSON(
name("test2"), name("test2"),
labels(map[string]string{ labels(map[string]string{
"traefik.backend": "foobar", types.LabelBackend: "foobar",
}), }),
ports(nat.PortMap{ ports(nat.PortMap{
"80/tcp": {}, "80/tcp": {},
@ -977,12 +977,12 @@ func TestDockerLoadDockerConfig(t *testing.T) {
containerJSON( containerJSON(
name("test1"), name("test1"),
labels(map[string]string{ labels(map[string]string{
"traefik.backend": "foobar", types.LabelBackend: "foobar",
"traefik.frontend.entryPoints": "http,https", types.LabelFrontendEntryPoints: "http,https",
"traefik.backend.maxconn.amount": "1000", types.LabelBackendMaxconnAmount: "1000",
"traefik.backend.maxconn.extractorfunc": "somethingelse", types.LabelBackendMaxconnExtractorfunc: "somethingelse",
"traefik.backend.loadbalancer.method": "drr", types.LabelBackendLoadbalancerMethod: "drr",
"traefik.backend.circuitbreaker.expression": "NetworkErrorRatio() > 0.5", types.LabelBackendCircuitbreakerExpression: "NetworkErrorRatio() > 0.5",
}), }),
ports(nat.PortMap{ ports(nat.PortMap{
"80/tcp": {}, "80/tcp": {},

View file

@ -23,7 +23,7 @@ func TestDockerGetServiceProtocol(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.protocol": "https", types.LabelProtocol: "https",
})), })),
expected: "https", expected: "https",
}, },
@ -61,7 +61,7 @@ func TestDockerGetServiceWeight(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.weight": "200", types.LabelWeight: "200",
})), })),
expected: "200", expected: "200",
}, },
@ -99,7 +99,7 @@ func TestDockerGetServicePort(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.port": "2500", types.LabelPort: "2500",
})), })),
expected: "2500", expected: "2500",
}, },
@ -137,7 +137,7 @@ func TestDockerGetServiceFrontendRule(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.rule": "Path:/helloworld", types.LabelFrontendRule: "Path:/helloworld",
})), })),
expected: "Path:/helloworld", expected: "Path:/helloworld",
}, },
@ -175,7 +175,7 @@ func TestDockerGetServiceBackend(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.backend": "another-backend", types.LabelBackend: "another-backend",
})), })),
expected: "another-backend-myservice", expected: "another-backend-myservice",
}, },
@ -213,7 +213,7 @@ func TestDockerGetServicePriority(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.priority": "33", types.LabelFrontendPriority: "33",
})), })),
expected: "33", expected: "33",
}, },
@ -251,7 +251,7 @@ func TestDockerGetServicePassHostHeader(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.passHostHeader": "false", types.LabelFrontendPassHostHeader: "false",
})), })),
expected: "false", expected: "false",
}, },
@ -289,7 +289,7 @@ func TestDockerGetServiceEntryPoints(t *testing.T) {
}, },
{ {
container: containerJSON(labels(map[string]string{ container: containerJSON(labels(map[string]string{
"traefik.frontend.entryPoints": "http,https", types.LabelFrontendEntryPoints: "http,https",
})), })),
expected: []string{"http", "https"}, expected: []string{"http", "https"},
}, },

View file

@ -28,21 +28,21 @@ func TestSwarmGetFrontendName(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.frontend.rule": "Headers:User-Agent,bat/0.1.0", types.LabelFrontendRule: "Headers:User-Agent,bat/0.1.0",
})), })),
expected: "Headers-User-Agent-bat-0-1-0", expected: "Headers-User-Agent-bat-0-1-0",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
})), })),
expected: "Host-foo-bar", expected: "Host-foo-bar",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.frontend.rule": "Path:/test", types.LabelFrontendRule: "Path:/test",
})), })),
expected: "Path-test", expected: "Path-test",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -51,7 +51,7 @@ func TestSwarmGetFrontendName(t *testing.T) {
service: swarmService( service: swarmService(
serviceName("test"), serviceName("test"),
serviceLabels(map[string]string{ serviceLabels(map[string]string{
"traefik.frontend.rule": "PathPrefix:/test2", types.LabelFrontendRule: "PathPrefix:/test2",
}), }),
), ),
expected: "PathPrefix-test2", expected: "PathPrefix-test2",
@ -94,14 +94,14 @@ func TestSwarmGetFrontendRule(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
})), })),
expected: "Host:foo.bar", expected: "Host:foo.bar",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.frontend.rule": "Path:/test", types.LabelFrontendRule: "Path:/test",
})), })),
expected: "Path:/test", expected: "Path:/test",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -143,7 +143,7 @@ func TestSwarmGetBackend(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.backend": "foobar", types.LabelBackend: "foobar",
})), })),
expected: "foobar", expected: "foobar",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -192,7 +192,7 @@ func TestSwarmGetIPAddress(t *testing.T) {
{ {
service: swarmService( service: swarmService(
serviceLabels(map[string]string{ serviceLabels(map[string]string{
"traefik.docker.network": "barnet", labelDockerNetwork: "barnet",
}), }),
withEndpointSpec(modeVIP), withEndpointSpec(modeVIP),
withEndpoint( withEndpoint(
@ -237,7 +237,7 @@ func TestSwarmGetPort(t *testing.T) {
{ {
service: swarmService( service: swarmService(
serviceLabels(map[string]string{ serviceLabels(map[string]string{
"traefik.port": "8080", types.LabelPort: "8080",
}), }),
withEndpointSpec(modeDNSSR), withEndpointSpec(modeDNSSR),
), ),
@ -275,7 +275,7 @@ func TestSwarmGetWeight(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.weight": "10", types.LabelWeight: "10",
})), })),
expected: "10", expected: "10",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -311,7 +311,7 @@ func TestSwarmGetDomain(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.domain": "foo.bar", types.LabelDomain: "foo.bar",
})), })),
expected: "foo.bar", expected: "foo.bar",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -348,7 +348,7 @@ func TestSwarmGetProtocol(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.protocol": "https", types.LabelProtocol: "https",
})), })),
expected: "https", expected: "https",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -384,7 +384,7 @@ func TestSwarmGetPassHostHeader(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.frontend.passHostHeader": "false", types.LabelFrontendPassHostHeader: "false",
})), })),
expected: "false", expected: "false",
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -520,8 +520,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.enable": "false", types.LabelEnable: "false",
"traefik.port": "80", types.LabelPort: "80",
})), })),
expected: false, expected: false,
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -533,8 +533,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
"traefik.port": "80", types.LabelPort: "80",
})), })),
expected: true, expected: true,
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -546,7 +546,7 @@ func TestSwarmTraefikFilter(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.port": "80", types.LabelPort: "80",
})), })),
expected: true, expected: true,
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -558,8 +558,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.enable": "true", types.LabelEnable: "true",
"traefik.port": "80", types.LabelPort: "80",
})), })),
expected: true, expected: true,
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -571,8 +571,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.enable": "anything", types.LabelEnable: "anything",
"traefik.port": "80", types.LabelPort: "80",
})), })),
expected: true, expected: true,
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -584,8 +584,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
"traefik.port": "80", types.LabelPort: "80",
})), })),
expected: true, expected: true,
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -597,7 +597,7 @@ func TestSwarmTraefikFilter(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.port": "80", types.LabelPort: "80",
})), })),
expected: false, expected: false,
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -609,8 +609,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
}, },
{ {
service: swarmService(serviceLabels(map[string]string{ service: swarmService(serviceLabels(map[string]string{
"traefik.enable": "true", types.LabelEnable: "true",
"traefik.port": "80", types.LabelPort: "80",
})), })),
expected: true, expected: true,
networks: map[string]*docker.NetworkResource{}, networks: map[string]*docker.NetworkResource{},
@ -653,7 +653,7 @@ func TestSwarmLoadDockerConfig(t *testing.T) {
swarmService( swarmService(
serviceName("test"), serviceName("test"),
serviceLabels(map[string]string{ serviceLabels(map[string]string{
"traefik.port": "80", types.LabelPort: "80",
}), }),
withEndpointSpec(modeVIP), withEndpointSpec(modeVIP),
withEndpoint(virtualIP("1", "127.0.0.1/24")), withEndpoint(virtualIP("1", "127.0.0.1/24")),
@ -695,10 +695,10 @@ func TestSwarmLoadDockerConfig(t *testing.T) {
swarmService( swarmService(
serviceName("test1"), serviceName("test1"),
serviceLabels(map[string]string{ serviceLabels(map[string]string{
"traefik.port": "80", types.LabelPort: "80",
"traefik.backend": "foobar", types.LabelBackend: "foobar",
"traefik.frontend.entryPoints": "http,https", types.LabelFrontendEntryPoints: "http,https",
"traefik.frontend.auth.basic": "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0", types.LabelFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
}), }),
withEndpointSpec(modeVIP), withEndpointSpec(modeVIP),
withEndpoint(virtualIP("1", "127.0.0.1/24")), withEndpoint(virtualIP("1", "127.0.0.1/24")),
@ -706,8 +706,8 @@ func TestSwarmLoadDockerConfig(t *testing.T) {
swarmService( swarmService(
serviceName("test2"), serviceName("test2"),
serviceLabels(map[string]string{ serviceLabels(map[string]string{
"traefik.port": "80", types.LabelPort: "80",
"traefik.backend": "foobar", types.LabelBackend: "foobar",
}), }),
withEndpointSpec(modeVIP), withEndpointSpec(modeVIP),
withEndpoint(virtualIP("1", "127.0.0.1/24")), withEndpoint(virtualIP("1", "127.0.0.1/24")),

View file

@ -390,7 +390,7 @@ func (p *Provider) filterInstance(i ecsInstance) bool {
return false return false
} }
label := i.label("traefik.enable") label := i.label(types.LabelEnable)
enabled := p.ExposedByDefault && label != "false" || label == "true" enabled := p.ExposedByDefault && label != "false" || label == "true"
if !enabled { if !enabled {
log.Debugf("Filtering disabled ecs instance %s (%s) (traefik.enabled = '%s')", i.Name, i.ID, label) log.Debugf("Filtering disabled ecs instance %s (%s) (traefik.enabled = '%s')", i.Name, i.ID, label)
@ -414,7 +414,7 @@ func (p *Provider) filterFrontends(instances []ecsInstance) []ecsInstance {
} }
func (p *Provider) getFrontendRule(i ecsInstance) string { func (p *Provider) getFrontendRule(i ecsInstance) string {
if label := i.label("traefik.frontend.rule"); label != "" { if label := i.label(types.LabelFrontendRule); label != "" {
return label return label
} }
return "Host:" + strings.ToLower(strings.Replace(i.Name, "_", "-", -1)) + "." + p.Domain return "Host:" + strings.ToLower(strings.Replace(i.Name, "_", "-", -1)) + "." + p.Domain
@ -437,7 +437,7 @@ func (p *Provider) chunkedTaskArns(tasks []*string) [][]*string {
} }
func (i ecsInstance) Protocol() string { func (i ecsInstance) Protocol() string {
if label := i.label("traefik.protocol"); label != "" { if label := i.label(types.LabelProtocol); label != "" {
return label return label
} }
return "http" return "http"
@ -452,28 +452,28 @@ func (i ecsInstance) Port() string {
} }
func (i ecsInstance) Weight() string { func (i ecsInstance) Weight() string {
if label := i.label("traefik.weight"); label != "" { if label := i.label(types.LabelWeight); label != "" {
return label return label
} }
return "0" return "0"
} }
func (i ecsInstance) PassHostHeader() string { func (i ecsInstance) PassHostHeader() string {
if label := i.label("traefik.frontend.passHostHeader"); label != "" { if label := i.label(types.LabelFrontendPassHostHeader); label != "" {
return label return label
} }
return "true" return "true"
} }
func (i ecsInstance) Priority() string { func (i ecsInstance) Priority() string {
if label := i.label("traefik.frontend.priority"); label != "" { if label := i.label(types.LabelFrontendPriority); label != "" {
return label return label
} }
return "0" return "0"
} }
func (i ecsInstance) EntryPoints() []string { func (i ecsInstance) EntryPoints() []string {
if label := i.label("traefik.frontend.entryPoints"); label != "" { if label := i.label(types.LabelFrontendEntryPoints); label != "" {
return strings.Split(label, ",") return strings.Split(label, ",")
} }
return []string{} return []string{}

View file

@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ecs" "github.com/aws/aws-sdk-go/service/ecs"
"github.com/containous/traefik/types"
) )
func makeEcsInstance(containerDef *ecs.ContainerDefinition) ecsInstance { func makeEcsInstance(containerDef *ecs.ContainerDefinition) ecsInstance {
@ -68,7 +69,7 @@ func TestEcsProtocol(t *testing.T) {
{ {
expected: "https", expected: "https",
instanceInfo: simpleEcsInstance(map[string]*string{ instanceInfo: simpleEcsInstance(map[string]*string{
"traefik.protocol": aws.String("https"), types.LabelProtocol: aws.String("https"),
}), }),
}, },
} }
@ -131,7 +132,7 @@ func TestEcsWeight(t *testing.T) {
{ {
expected: "10", expected: "10",
instanceInfo: simpleEcsInstance(map[string]*string{ instanceInfo: simpleEcsInstance(map[string]*string{
"traefik.weight": aws.String("10"), types.LabelWeight: aws.String("10"),
}), }),
}, },
} }
@ -156,7 +157,7 @@ func TestEcsPassHostHeader(t *testing.T) {
{ {
expected: "false", expected: "false",
instanceInfo: simpleEcsInstance(map[string]*string{ instanceInfo: simpleEcsInstance(map[string]*string{
"traefik.frontend.passHostHeader": aws.String("false"), types.LabelFrontendPassHostHeader: aws.String("false"),
}), }),
}, },
} }
@ -181,7 +182,7 @@ func TestEcsPriority(t *testing.T) {
{ {
expected: "10", expected: "10",
instanceInfo: simpleEcsInstance(map[string]*string{ instanceInfo: simpleEcsInstance(map[string]*string{
"traefik.frontend.priority": aws.String("10"), types.LabelFrontendPriority: aws.String("10"),
}), }),
}, },
} }
@ -206,13 +207,13 @@ func TestEcsEntryPoints(t *testing.T) {
{ {
expected: []string{"http"}, expected: []string{"http"},
instanceInfo: simpleEcsInstance(map[string]*string{ instanceInfo: simpleEcsInstance(map[string]*string{
"traefik.frontend.entryPoints": aws.String("http"), types.LabelFrontendEntryPoints: aws.String("http"),
}), }),
}, },
{ {
expected: []string{"http", "https"}, expected: []string{"http", "https"},
instanceInfo: simpleEcsInstance(map[string]*string{ instanceInfo: simpleEcsInstance(map[string]*string{
"traefik.frontend.entryPoints": aws.String("http,https"), types.LabelFrontendEntryPoints: aws.String("http,https"),
}), }),
}, },
} }
@ -261,14 +262,14 @@ func TestFilterInstance(t *testing.T) {
expected: false, expected: false,
exposedByDefault: true, exposedByDefault: true,
instanceInfo: simpleEcsInstance(map[string]*string{ instanceInfo: simpleEcsInstance(map[string]*string{
"traefik.enable": aws.String("false"), types.LabelEnable: aws.String("false"),
}), }),
}, },
{ {
expected: true, expected: true,
exposedByDefault: false, exposedByDefault: false,
instanceInfo: simpleEcsInstance(map[string]*string{ instanceInfo: simpleEcsInstance(map[string]*string{
"traefik.enable": aws.String("true"), types.LabelEnable: aws.String("true"),
}), }),
}, },
{ {

View file

@ -131,14 +131,14 @@ func (p *Provider) getProtocol(instance eureka.InstanceInfo) string {
} }
func (p *Provider) getWeight(instance eureka.InstanceInfo) string { func (p *Provider) getWeight(instance eureka.InstanceInfo) string {
if val, ok := instance.Metadata.Map["traefik.weight"]; ok { if val, ok := instance.Metadata.Map[types.LabelWeight]; ok {
return val return val
} }
return "0" return "0"
} }
func (p *Provider) getInstanceID(instance eureka.InstanceInfo) string { func (p *Provider) getInstanceID(instance eureka.InstanceInfo) string {
if val, ok := instance.Metadata.Map["traefik.backend.id"]; ok { if val, ok := instance.Metadata.Map[types.LabelBackendID]; ok {
return val return val
} }
return strings.Replace(instance.IpAddr, ".", "-", -1) + "-" + p.getPort(instance) return strings.Replace(instance.IpAddr, ".", "-", -1) + "-" + p.getPort(instance)

View file

@ -4,6 +4,7 @@ import (
"testing" "testing"
"github.com/ArthurHlt/go-eureka-client/eureka" "github.com/ArthurHlt/go-eureka-client/eureka"
"github.com/containous/traefik/types"
) )
func TestEurekaGetPort(t *testing.T) { func TestEurekaGetPort(t *testing.T) {
@ -106,7 +107,7 @@ func TestEurekaGetWeight(t *testing.T) {
}, },
Metadata: &eureka.MetaData{ Metadata: &eureka.MetaData{
Map: map[string]string{ Map: map[string]string{
"traefik.weight": "10", types.LabelWeight: "10",
}, },
}, },
}, },
@ -139,7 +140,7 @@ func TestEurekaGetInstanceId(t *testing.T) {
}, },
Metadata: &eureka.MetaData{ Metadata: &eureka.MetaData{
Map: map[string]string{ Map: map[string]string{
"traefik.backend.id": "MyInstanceId", types.LabelBackendID: "MyInstanceId",
}, },
}, },
}, },

View file

@ -27,9 +27,8 @@ import (
var _ provider.Provider = (*Provider)(nil) var _ provider.Provider = (*Provider)(nil)
const ( const (
annotationFrontendRuleType = "traefik.frontend.rule.type" ruleTypePathPrefix = "PathPrefix"
ruleTypePathPrefix = "PathPrefix" ruleTypeReplacePath = "ReplacePath"
ruleTypeReplacePath = "ReplacePath"
annotationKubernetesIngressClass = "kubernetes.io/ingress.class" annotationKubernetesIngressClass = "kubernetes.io/ingress.class"
annotationKubernetesAuthRealm = "ingress.kubernetes.io/auth-realm" annotationKubernetesAuthRealm = "ingress.kubernetes.io/auth-realm"
@ -169,7 +168,7 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
PassHostHeader := p.getPassHostHeader() PassHostHeader := p.getPassHostHeader()
passHostHeaderAnnotation, ok := i.Annotations["traefik.frontend.passHostHeader"] passHostHeaderAnnotation, ok := i.Annotations[types.LabelFrontendPassHostHeader]
switch { switch {
case !ok: case !ok:
// No op. // No op.
@ -178,7 +177,7 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
case passHostHeaderAnnotation == "true": case passHostHeaderAnnotation == "true":
PassHostHeader = true PassHostHeader = true
default: default:
log.Warnf("Unknown value '%s' for traefik.frontend.passHostHeader, falling back to %s", passHostHeaderAnnotation, PassHostHeader) log.Warnf("Unknown value '%s' for %s, falling back to %s", passHostHeaderAnnotation, types.LabelFrontendPassHostHeader, PassHostHeader)
} }
if realm := i.Annotations[annotationKubernetesAuthRealm]; realm != "" && realm != traefikDefaultRealm { if realm := i.Annotations[annotationKubernetesAuthRealm]; realm != "" && realm != traefikDefaultRealm {
return nil, errors.New("no realm customization supported") return nil, errors.New("no realm customization supported")
@ -235,17 +234,17 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
continue continue
} }
if expression := service.Annotations["traefik.backend.circuitbreaker"]; expression != "" { if expression := service.Annotations[types.LabelTraefikBackendCircuitbreaker]; expression != "" {
templateObjects.Backends[r.Host+pa.Path].CircuitBreaker = &types.CircuitBreaker{ templateObjects.Backends[r.Host+pa.Path].CircuitBreaker = &types.CircuitBreaker{
Expression: expression, Expression: expression,
} }
} }
if service.Annotations["traefik.backend.loadbalancer.method"] == "drr" { if service.Annotations[types.LabelBackendLoadbalancerMethod] == "drr" {
templateObjects.Backends[r.Host+pa.Path].LoadBalancer.Method = "drr" templateObjects.Backends[r.Host+pa.Path].LoadBalancer.Method = "drr"
} }
if service.Annotations["traefik.backend.loadbalancer.sticky"] == "true" { if service.Annotations[types.LabelBackendLoadbalancerSticky] == "true" {
templateObjects.Backends[r.Host+pa.Path].LoadBalancer.Sticky = true templateObjects.Backends[r.Host+pa.Path].LoadBalancer.Sticky = true
} }
@ -309,7 +308,7 @@ func getRuleForPath(pa v1beta1.HTTPIngressPath, i *v1beta1.Ingress) string {
return "" return ""
} }
ruleType := i.Annotations[annotationFrontendRuleType] ruleType := i.Annotations[types.LabelFrontendRuleType]
if ruleType == "" { if ruleType == "" {
ruleType = ruleTypePathPrefix ruleType = ruleTypePathPrefix
} }

View file

@ -383,7 +383,7 @@ func TestRuleType(t *testing.T) {
if test.ingressRuleType != "" { if test.ingressRuleType != "" {
ingress.ObjectMeta.Annotations = map[string]string{ ingress.ObjectMeta.Annotations = map[string]string{
annotationFrontendRuleType: test.ingressRuleType, types.LabelFrontendRuleType: test.ingressRuleType,
} }
} }
@ -1224,8 +1224,8 @@ func TestServiceAnnotations(t *testing.T) {
UID: "1", UID: "1",
Namespace: "testing", Namespace: "testing",
Annotations: map[string]string{ Annotations: map[string]string{
"traefik.backend.circuitbreaker": "NetworkErrorRatio() > 0.5", types.LabelTraefikBackendCircuitbreaker: "NetworkErrorRatio() > 0.5",
"traefik.backend.loadbalancer.method": "drr", types.LabelBackendLoadbalancerMethod: "drr",
}, },
}, },
Spec: v1.ServiceSpec{ Spec: v1.ServiceSpec{
@ -1243,8 +1243,8 @@ func TestServiceAnnotations(t *testing.T) {
UID: "2", UID: "2",
Namespace: "testing", Namespace: "testing",
Annotations: map[string]string{ Annotations: map[string]string{
"traefik.backend.circuitbreaker": "", types.LabelTraefikBackendCircuitbreaker: "",
"traefik.backend.loadbalancer.sticky": "true", types.LabelBackendLoadbalancerSticky: "true",
}, },
}, },
Spec: v1.ServiceSpec{ Spec: v1.ServiceSpec{
@ -1418,7 +1418,7 @@ func TestIngressAnnotations(t *testing.T) {
ObjectMeta: v1.ObjectMeta{ ObjectMeta: v1.ObjectMeta{
Namespace: "testing", Namespace: "testing",
Annotations: map[string]string{ Annotations: map[string]string{
"traefik.frontend.passHostHeader": "false", types.LabelFrontendPassHostHeader: "false",
}, },
}, },
Spec: v1beta1.IngressSpec{ Spec: v1beta1.IngressSpec{
@ -1447,7 +1447,7 @@ func TestIngressAnnotations(t *testing.T) {
Namespace: "testing", Namespace: "testing",
Annotations: map[string]string{ Annotations: map[string]string{
"kubernetes.io/ingress.class": "traefik", "kubernetes.io/ingress.class": "traefik",
"traefik.frontend.passHostHeader": "true", types.LabelFrontendPassHostHeader: "true",
}, },
}, },
Spec: v1beta1.IngressSpec{ Spec: v1beta1.IngressSpec{
@ -1784,7 +1784,7 @@ func TestInvalidPassHostHeaderValue(t *testing.T) {
ObjectMeta: v1.ObjectMeta{ ObjectMeta: v1.ObjectMeta{
Namespace: "testing", Namespace: "testing",
Annotations: map[string]string{ Annotations: map[string]string{
"traefik.frontend.passHostHeader": "herpderp", types.LabelFrontendPassHostHeader: "herpderp",
}, },
}, },
Spec: v1beta1.IngressSpec{ Spec: v1beta1.IngressSpec{

View file

@ -25,11 +25,7 @@ import (
) )
const ( const (
labelPort = "traefik.port" traceMaxScanTokenSize = 1024 * 1024
labelPortIndex = "traefik.portIndex"
labelBackendHealthCheckPath = "traefik.backend.healthcheck.path"
labelBackendHealthCheckInterval = "traefik.backend.healthcheck.interval"
traceMaxScanTokenSize = 1024 * 1024
) )
var _ provider.Provider = (*Provider)(nil) var _ provider.Provider = (*Provider)(nil)
@ -222,15 +218,15 @@ func (p *Provider) taskFilter(task marathon.Task, applications *marathon.Applica
} }
// Filter illegal port label specification. // Filter illegal port label specification.
_, hasPortIndexLabel := p.getLabel(application, labelPortIndex) _, hasPortIndexLabel := p.getLabel(application, types.LabelPortIndex)
_, hasPortLabel := p.getLabel(application, labelPort) _, hasPortLabel := p.getLabel(application, types.LabelPort)
if hasPortIndexLabel && hasPortLabel { if hasPortIndexLabel && hasPortLabel {
log.Debugf("Filtering Marathon task %s from application %s specifying both traefik.portIndex and traefik.port labels", task.ID, application.ID) log.Debugf("Filtering Marathon task %s from application %s specifying both traefik.portIndex and traefik.port labels", task.ID, application.ID)
return false return false
} }
// Filter by constraints. // Filter by constraints.
label, _ := p.getLabel(application, "traefik.tags") label, _ := p.getLabel(application, types.LabelTags)
constraintTags := strings.Split(label, ",") constraintTags := strings.Split(label, ",")
if p.MarathonLBCompatibility { if p.MarathonLBCompatibility {
if label, ok := p.getLabel(application, "HAPROXY_GROUP"); ok { if label, ok := p.getLabel(application, "HAPROXY_GROUP"); ok {
@ -266,7 +262,7 @@ func (p *Provider) taskFilter(task marathon.Task, applications *marathon.Applica
} }
func (p *Provider) applicationFilter(app marathon.Application, filteredTasks []marathon.Task) bool { func (p *Provider) applicationFilter(app marathon.Application, filteredTasks []marathon.Task) bool {
label, _ := p.getLabel(app, "traefik.tags") label, _ := p.getLabel(app, types.LabelTags)
constraintTags := strings.Split(label, ",") constraintTags := strings.Split(label, ",")
if p.MarathonLBCompatibility { if p.MarathonLBCompatibility {
if label, ok := p.getLabel(app, "HAPROXY_GROUP"); ok { if label, ok := p.getLabel(app, "HAPROXY_GROUP"); ok {
@ -295,7 +291,7 @@ func getApplication(task marathon.Task, apps []marathon.Application) (marathon.A
} }
func isApplicationEnabled(application marathon.Application, exposedByDefault bool) bool { func isApplicationEnabled(application marathon.Application, exposedByDefault bool) bool {
return exposedByDefault && (*application.Labels)["traefik.enable"] != "false" || (*application.Labels)["traefik.enable"] == "true" return exposedByDefault && (*application.Labels)[types.LabelEnable] != "false" || (*application.Labels)[types.LabelEnable] == "true"
} }
func (p *Provider) getLabel(application marathon.Application, label string) (string, bool) { func (p *Provider) getLabel(application marathon.Application, label string) (string, bool) {
@ -328,14 +324,14 @@ func (p *Provider) getWeight(task marathon.Task, applications []marathon.Applica
log.Errorf("Unable to get marathon application from task %s", task.AppID) log.Errorf("Unable to get marathon application from task %s", task.AppID)
return "0" return "0"
} }
if label, ok := p.getLabel(application, "traefik.weight"); ok { if label, ok := p.getLabel(application, types.LabelWeight); ok {
return label return label
} }
return "0" return "0"
} }
func (p *Provider) getDomain(application marathon.Application) string { func (p *Provider) getDomain(application marathon.Application) string {
if label, ok := p.getLabel(application, "traefik.domain"); ok { if label, ok := p.getLabel(application, types.LabelDomain); ok {
return label return label
} }
return p.Domain return p.Domain
@ -347,35 +343,35 @@ func (p *Provider) getProtocol(task marathon.Task, applications []marathon.Appli
log.Errorf("Unable to get marathon application from task %s", task.AppID) log.Errorf("Unable to get marathon application from task %s", task.AppID)
return "http" return "http"
} }
if label, ok := p.getLabel(application, "traefik.protocol"); ok { if label, ok := p.getLabel(application, types.LabelProtocol); ok {
return label return label
} }
return "http" return "http"
} }
func (p *Provider) getSticky(application marathon.Application) string { func (p *Provider) getSticky(application marathon.Application) string {
if sticky, ok := p.getLabel(application, "traefik.backend.loadbalancer.sticky"); ok { if sticky, ok := p.getLabel(application, types.LabelBackendLoadbalancerSticky); ok {
return sticky return sticky
} }
return "false" return "false"
} }
func (p *Provider) getPassHostHeader(application marathon.Application) string { func (p *Provider) getPassHostHeader(application marathon.Application) string {
if passHostHeader, ok := p.getLabel(application, "traefik.frontend.passHostHeader"); ok { if passHostHeader, ok := p.getLabel(application, types.LabelFrontendPassHostHeader); ok {
return passHostHeader return passHostHeader
} }
return "true" return "true"
} }
func (p *Provider) getPriority(application marathon.Application) string { func (p *Provider) getPriority(application marathon.Application) string {
if priority, ok := p.getLabel(application, "traefik.frontend.priority"); ok { if priority, ok := p.getLabel(application, types.LabelFrontendPriority); ok {
return priority return priority
} }
return "0" return "0"
} }
func (p *Provider) getEntryPoints(application marathon.Application) []string { func (p *Provider) getEntryPoints(application marathon.Application) []string {
if entryPoints, ok := p.getLabel(application, "traefik.frontend.entryPoints"); ok { if entryPoints, ok := p.getLabel(application, types.LabelFrontendEntryPoints); ok {
return strings.Split(entryPoints, ",") return strings.Split(entryPoints, ",")
} }
return []string{} return []string{}
@ -384,7 +380,7 @@ func (p *Provider) getEntryPoints(application marathon.Application) []string {
// getFrontendRule returns the frontend rule for the specified application, using // getFrontendRule returns the frontend rule for the specified application, using
// it's label. It returns a default one (Host) if the label is not present. // it's label. It returns a default one (Host) if the label is not present.
func (p *Provider) getFrontendRule(application marathon.Application) string { func (p *Provider) getFrontendRule(application marathon.Application) string {
if label, ok := p.getLabel(application, "traefik.frontend.rule"); ok { if label, ok := p.getLabel(application, types.LabelFrontendRule); ok {
return label return label
} }
if p.MarathonLBCompatibility { if p.MarathonLBCompatibility {
@ -405,7 +401,7 @@ func (p *Provider) getBackend(task marathon.Task, applications []marathon.Applic
} }
func (p *Provider) getFrontendBackend(application marathon.Application) string { func (p *Provider) getFrontendBackend(application marathon.Application) string {
if label, ok := p.getLabel(application, "traefik.backend"); ok { if label, ok := p.getLabel(application, types.LabelBackend); ok {
return label return label
} }
return provider.Replace("/", "-", application.ID) return provider.Replace("/", "-", application.ID)
@ -422,26 +418,26 @@ func (p *Provider) getSubDomain(name string) string {
} }
func (p *Provider) hasCircuitBreakerLabels(application marathon.Application) bool { func (p *Provider) hasCircuitBreakerLabels(application marathon.Application) bool {
_, ok := p.getLabel(application, "traefik.backend.circuitbreaker.expression") _, ok := p.getLabel(application, types.LabelBackendCircuitbreakerExpression)
return ok return ok
} }
func (p *Provider) hasLoadBalancerLabels(application marathon.Application) bool { func (p *Provider) hasLoadBalancerLabels(application marathon.Application) bool {
_, errMethod := p.getLabel(application, "traefik.backend.loadbalancer.method") _, errMethod := p.getLabel(application, types.LabelBackendLoadbalancerMethod)
_, errSticky := p.getLabel(application, "traefik.backend.loadbalancer.sticky") _, errSticky := p.getLabel(application, types.LabelBackendLoadbalancerSticky)
return errMethod || errSticky return errMethod || errSticky
} }
func (p *Provider) hasMaxConnLabels(application marathon.Application) bool { func (p *Provider) hasMaxConnLabels(application marathon.Application) bool {
if _, ok := p.getLabel(application, "traefik.backend.maxconn.amount"); !ok { if _, ok := p.getLabel(application, types.LabelBackendMaxconnAmount); !ok {
return false return false
} }
_, ok := p.getLabel(application, "traefik.backend.maxconn.extractorfunc") _, ok := p.getLabel(application, types.LabelBackendMaxconnExtractorfunc)
return ok return ok
} }
func (p *Provider) getMaxConnAmount(application marathon.Application) int64 { func (p *Provider) getMaxConnAmount(application marathon.Application) int64 {
if label, ok := p.getLabel(application, "traefik.backend.maxconn.amount"); ok { if label, ok := p.getLabel(application, types.LabelBackendMaxconnAmount); ok {
i, errConv := strconv.ParseInt(label, 10, 64) i, errConv := strconv.ParseInt(label, 10, 64)
if errConv != nil { if errConv != nil {
log.Errorf("Unable to parse traefik.backend.maxconn.amount %s", label) log.Errorf("Unable to parse traefik.backend.maxconn.amount %s", label)
@ -453,21 +449,21 @@ func (p *Provider) getMaxConnAmount(application marathon.Application) int64 {
} }
func (p *Provider) getMaxConnExtractorFunc(application marathon.Application) string { func (p *Provider) getMaxConnExtractorFunc(application marathon.Application) string {
if label, ok := p.getLabel(application, "traefik.backend.maxconn.extractorfunc"); ok { if label, ok := p.getLabel(application, types.LabelBackendMaxconnExtractorfunc); ok {
return label return label
} }
return "request.host" return "request.host"
} }
func (p *Provider) getLoadBalancerMethod(application marathon.Application) string { func (p *Provider) getLoadBalancerMethod(application marathon.Application) string {
if label, ok := p.getLabel(application, "traefik.backend.loadbalancer.method"); ok { if label, ok := p.getLabel(application, types.LabelBackendLoadbalancerMethod); ok {
return label return label
} }
return "wrr" return "wrr"
} }
func (p *Provider) getCircuitBreakerExpression(application marathon.Application) string { func (p *Provider) getCircuitBreakerExpression(application marathon.Application) string {
if label, ok := p.getLabel(application, "traefik.backend.circuitbreaker.expression"); ok { if label, ok := p.getLabel(application, types.LabelBackendCircuitbreakerExpression); ok {
return label return label
} }
return "NetworkErrorRatio() > 1" return "NetworkErrorRatio() > 1"
@ -478,21 +474,21 @@ func (p *Provider) hasHealthCheckLabels(application marathon.Application) bool {
} }
func (p *Provider) getHealthCheckPath(application marathon.Application) string { func (p *Provider) getHealthCheckPath(application marathon.Application) string {
if label, ok := p.getLabel(application, labelBackendHealthCheckPath); ok { if label, ok := p.getLabel(application, types.LabelBackendHealthcheckPath); ok {
return label return label
} }
return "" return ""
} }
func (p *Provider) getHealthCheckInterval(application marathon.Application) string { func (p *Provider) getHealthCheckInterval(application marathon.Application) string {
if label, ok := p.getLabel(application, labelBackendHealthCheckInterval); ok { if label, ok := p.getLabel(application, types.LabelBackendHealthcheckInterval); ok {
return label return label
} }
return "" return ""
} }
func (p *Provider) getBasicAuth(application marathon.Application) []string { func (p *Provider) getBasicAuth(application marathon.Application) []string {
if basicAuth, ok := p.getLabel(application, "traefik.frontend.auth.basic"); ok { if basicAuth, ok := p.getLabel(application, types.LabelFrontendAuthBasic); ok {
return strings.Split(basicAuth, ",") return strings.Split(basicAuth, ",")
} }
@ -500,7 +496,7 @@ func (p *Provider) getBasicAuth(application marathon.Application) []string {
} }
func processPorts(application marathon.Application, task marathon.Task) (int, error) { func processPorts(application marathon.Application, task marathon.Task) (int, error) {
if portLabel, ok := (*application.Labels)[labelPort]; ok { if portLabel, ok := (*application.Labels)[types.LabelPort]; ok {
port, err := strconv.Atoi(portLabel) port, err := strconv.Atoi(portLabel)
switch { switch {
case err != nil: case err != nil:
@ -517,7 +513,7 @@ func processPorts(application marathon.Application, task marathon.Task) (int, er
} }
portIndex := 0 portIndex := 0
portIndexLabel, ok := (*application.Labels)[labelPortIndex] portIndexLabel, ok := (*application.Labels)[types.LabelPortIndex]
if ok { if ok {
var err error var err error
portIndex, err = parseIndex(portIndexLabel, len(ports)) portIndex, err = parseIndex(portIndexLabel, len(ports))

View file

@ -126,8 +126,8 @@ func TestMarathonLoadConfig(t *testing.T) {
ID: "/testLoadBalancerAndCircuitBreaker.dot", ID: "/testLoadBalancerAndCircuitBreaker.dot",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.backend.loadbalancer.method": "drr", types.LabelBackendLoadbalancerMethod: "drr",
"traefik.backend.circuitbreaker.expression": "NetworkErrorRatio() > 0.5", types.LabelBackendCircuitbreakerExpression: "NetworkErrorRatio() > 0.5",
}, },
}, },
}, },
@ -185,8 +185,8 @@ func TestMarathonLoadConfig(t *testing.T) {
ID: "/testMaxConn", ID: "/testMaxConn",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.backend.maxconn.amount": "1000", types.LabelBackendMaxconnAmount: "1000",
"traefik.backend.maxconn.extractorfunc": "client.ip", types.LabelBackendMaxconnExtractorfunc: "client.ip",
}, },
}, },
}, },
@ -242,7 +242,7 @@ func TestMarathonLoadConfig(t *testing.T) {
ID: "/testMaxConnOnlySpecifyAmount", ID: "/testMaxConnOnlySpecifyAmount",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.backend.maxconn.amount": "1000", types.LabelBackendMaxconnAmount: "1000",
}, },
}, },
}, },
@ -295,7 +295,7 @@ func TestMarathonLoadConfig(t *testing.T) {
ID: "/testMaxConnOnlyExtractorFunc", ID: "/testMaxConnOnlyExtractorFunc",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.backend.maxconn.extractorfunc": "client.ip", types.LabelBackendMaxconnExtractorfunc: "client.ip",
}, },
}, },
}, },
@ -348,8 +348,8 @@ func TestMarathonLoadConfig(t *testing.T) {
ID: "/testHealthCheck", ID: "/testHealthCheck",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{ Labels: &map[string]string{
labelBackendHealthCheckPath: "/path", types.LabelBackendHealthcheckPath: "/path",
labelBackendHealthCheckInterval: "5m", types.LabelBackendHealthcheckInterval: "5m",
}, },
}, },
}, },
@ -513,7 +513,7 @@ func TestMarathonTaskFilter(t *testing.T) {
ID: "disable", ID: "disable",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.enable": "false", types.LabelEnable: "false",
}, },
}, },
}, },
@ -532,8 +532,8 @@ func TestMarathonTaskFilter(t *testing.T) {
ID: "specify-both-port-index-and-number", ID: "specify-both-port-index-and-number",
Ports: []int{80, 443}, Ports: []int{80, 443},
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.port": "443", types.LabelPort: "443",
"traefik.portIndex": "1", types.LabelPortIndex: "1",
}, },
}, },
}, },
@ -667,7 +667,7 @@ func TestMarathonTaskFilter(t *testing.T) {
ID: "disable-default-expose-disable-in-label", ID: "disable-default-expose-disable-in-label",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.enable": "false", types.LabelEnable: "false",
}, },
}, },
}, },
@ -686,7 +686,7 @@ func TestMarathonTaskFilter(t *testing.T) {
ID: "disable-default-expose-enable-in-label", ID: "disable-default-expose-enable-in-label",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.enable": "true", types.LabelEnable: "true",
}, },
}, },
}, },
@ -729,7 +729,7 @@ func TestMarathonAppConstraints(t *testing.T) {
application: marathon.Application{ application: marathon.Application{
ID: "foo2", ID: "foo2",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.tags": "valid", types.LabelTags: "valid",
}, },
}, },
filteredTasks: []marathon.Task{ filteredTasks: []marathon.Task{
@ -745,7 +745,7 @@ func TestMarathonAppConstraints(t *testing.T) {
ID: "foo3", ID: "foo3",
Labels: &map[string]string{ Labels: &map[string]string{
"HAPROXY_GROUP": "valid", "HAPROXY_GROUP": "valid",
"traefik.tags": "notvalid", types.LabelTags: "notvalid",
}, },
}, },
filteredTasks: []marathon.Task{ filteredTasks: []marathon.Task{
@ -786,7 +786,7 @@ func TestMarathonTaskConstraints(t *testing.T) {
}, { }, {
ID: "foo1", ID: "foo1",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.tags": "other", types.LabelTags: "other",
}, },
}, },
}, },
@ -802,7 +802,7 @@ func TestMarathonTaskConstraints(t *testing.T) {
{ {
ID: "foo2", ID: "foo2",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.tags": "valid", types.LabelTags: "valid",
}, },
}, },
}, },
@ -819,13 +819,13 @@ func TestMarathonTaskConstraints(t *testing.T) {
ID: "foo3", ID: "foo3",
Labels: &map[string]string{ Labels: &map[string]string{
"HAPROXY_GROUP": "valid", "HAPROXY_GROUP": "valid",
"traefik.tags": "notvalid", types.LabelTags: "notvalid",
}, },
}, { }, {
ID: "foo4", ID: "foo4",
Labels: &map[string]string{ Labels: &map[string]string{
"HAPROXY_GROUP": "notvalid", "HAPROXY_GROUP": "notvalid",
"traefik.tags": "valid", types.LabelTags: "valid",
}, },
}, },
}, },
@ -961,7 +961,7 @@ func TestMarathonGetPort(t *testing.T) {
{ {
ID: "app", ID: "app",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.port": "80", types.LabelPort: "80",
}, },
}, },
}, },
@ -977,7 +977,7 @@ func TestMarathonGetPort(t *testing.T) {
{ {
ID: "app", ID: "app",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.port": "foobar", types.LabelPort: "foobar",
}, },
}, },
}, },
@ -993,7 +993,7 @@ func TestMarathonGetPort(t *testing.T) {
{ {
ID: "app", ID: "app",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.port": "-1", types.LabelPort: "-1",
}, },
}, },
}, },
@ -1102,7 +1102,7 @@ func TestMarathonGetPort(t *testing.T) {
{ {
ID: "app", ID: "app",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.portIndex": "1", types.LabelPortIndex: "1",
}, },
}, },
}, },
@ -1118,7 +1118,7 @@ func TestMarathonGetPort(t *testing.T) {
{ {
ID: "app", ID: "app",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.portIndex": "foobar", types.LabelPortIndex: "foobar",
}, },
}, },
}, },
@ -1175,7 +1175,7 @@ func TestMarathonGetWeight(t *testing.T) {
{ {
ID: "test1", ID: "test1",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.weight": "10", types.LabelWeight: "10",
}, },
}, },
}, },
@ -1203,7 +1203,7 @@ func TestMarathonGetWeight(t *testing.T) {
{ {
ID: "test", ID: "test",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.weight": "10", types.LabelWeight: "10",
}, },
}, },
}, },
@ -1239,7 +1239,7 @@ func TestMarathonGetDomain(t *testing.T) {
{ {
application: marathon.Application{ application: marathon.Application{
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.domain": "foo.bar", types.LabelDomain: "foo.bar",
}, },
}, },
expected: "foo.bar", expected: "foo.bar",
@ -1272,7 +1272,7 @@ func TestMarathonGetProtocol(t *testing.T) {
{ {
ID: "test1", ID: "test1",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.protocol": "https", types.LabelProtocol: "https",
}, },
}, },
}, },
@ -1300,7 +1300,7 @@ func TestMarathonGetProtocol(t *testing.T) {
{ {
ID: "test", ID: "test",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.protocol": "https", types.LabelProtocol: "https",
}, },
}, },
}, },
@ -1334,7 +1334,7 @@ func TestMarathonGetPassHostHeader(t *testing.T) {
{ {
application: marathon.Application{ application: marathon.Application{
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.frontend.passHostHeader": "false", types.LabelFrontendPassHostHeader: "false",
}, },
}, },
expected: "false", expected: "false",
@ -1364,7 +1364,7 @@ func TestMarathonGetEntryPoints(t *testing.T) {
{ {
application: marathon.Application{ application: marathon.Application{
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.frontend.entryPoints": "http,https", types.LabelFrontendEntryPoints: "http,https",
}, },
}, },
expected: []string{"http", "https"}, expected: []string{"http", "https"},
@ -1405,7 +1405,7 @@ func TestMarathonGetFrontendRule(t *testing.T) {
{ {
application: marathon.Application{ application: marathon.Application{
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
"HAPROXY_0_VHOST": "notvalid", "HAPROXY_0_VHOST": "notvalid",
}, },
}, },
@ -1446,7 +1446,7 @@ func TestMarathonGetBackend(t *testing.T) {
application: marathon.Application{ application: marathon.Application{
ID: "foo", ID: "foo",
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.backend": "bar", types.LabelBackend: "bar",
}, },
}, },
expected: "bar", expected: "bar",
@ -1522,7 +1522,7 @@ func TestMarathonHasHealthCheckLabels(t *testing.T) {
Labels: &map[string]string{}, Labels: &map[string]string{},
} }
if test.value != nil { if test.value != nil {
app.AddLabel(labelBackendHealthCheckPath, *test.value) app.AddLabel(types.LabelBackendHealthcheckPath, *test.value)
} }
prov := &Provider{} prov := &Provider{}
got := prov.hasHealthCheckLabels(app) got := prov.hasHealthCheckLabels(app)
@ -1558,7 +1558,7 @@ func TestMarathonGetHealthCheckPath(t *testing.T) {
app := marathon.Application{} app := marathon.Application{}
app.EmptyLabels() app.EmptyLabels()
if test.value != nil { if test.value != nil {
app.AddLabel(labelBackendHealthCheckPath, *test.value) app.AddLabel(types.LabelBackendHealthcheckPath, *test.value)
} }
prov := &Provider{} prov := &Provider{}
got := prov.getHealthCheckPath(app) got := prov.getHealthCheckPath(app)
@ -1595,7 +1595,7 @@ func TestMarathonGetHealthCheckInterval(t *testing.T) {
Labels: &map[string]string{}, Labels: &map[string]string{},
} }
if test.value != nil { if test.value != nil {
app.AddLabel(labelBackendHealthCheckInterval, *test.value) app.AddLabel(types.LabelBackendHealthcheckInterval, *test.value)
} }
prov := &Provider{} prov := &Provider{}
got := prov.getHealthCheckInterval(app) got := prov.getHealthCheckInterval(app)
@ -1825,7 +1825,7 @@ func TestMarathonGetBasicAuth(t *testing.T) {
desc: "basic auth label is set with user:password", desc: "basic auth label is set with user:password",
application: marathon.Application{ application: marathon.Application{
Labels: &map[string]string{ Labels: &map[string]string{
"traefik.frontend.auth.basic": "user:password", types.LabelFrontendAuthBasic: "user:password",
}, },
}, },
expected: []string{"user:password"}, expected: []string{"user:password"},

View file

@ -206,21 +206,21 @@ func mesosTaskFilter(task state.Task, exposedByDefaultFlag bool) bool {
} }
//filter indeterminable task port //filter indeterminable task port
portIndexLabel := labels(task, "traefik.portIndex") portIndexLabel := labels(task, types.LabelPortIndex)
portValueLabel := labels(task, "traefik.port") portValueLabel := labels(task, types.LabelPort)
if portIndexLabel != "" && portValueLabel != "" { if portIndexLabel != "" && portValueLabel != "" {
log.Debugf("Filtering Mesos task %s specifying both traefik.portIndex and traefik.port labels", task.Name) log.Debugf("Filtering Mesos task %s specifying both traefik.portIndex and traefik.port labels", task.Name)
return false return false
} }
if portIndexLabel != "" { if portIndexLabel != "" {
index, err := strconv.Atoi(labels(task, "traefik.portIndex")) index, err := strconv.Atoi(labels(task, types.LabelPortIndex))
if err != nil || index < 0 || index > len(task.DiscoveryInfo.Ports.DiscoveryPorts)-1 { if err != nil || index < 0 || index > len(task.DiscoveryInfo.Ports.DiscoveryPorts)-1 {
log.Debugf("Filtering Mesos task %s with unexpected value for traefik.portIndex label", task.Name) log.Debugf("Filtering Mesos task %s with unexpected value for traefik.portIndex label", task.Name)
return false return false
} }
} }
if portValueLabel != "" { if portValueLabel != "" {
port, err := strconv.Atoi(labels(task, "traefik.port")) port, err := strconv.Atoi(labels(task, types.LabelPort))
if err != nil { if err != nil {
log.Debugf("Filtering Mesos task %s with unexpected value for traefik.port label", task.Name) log.Debugf("Filtering Mesos task %s with unexpected value for traefik.port label", task.Name)
return false return false
@ -259,7 +259,7 @@ func getMesos(task state.Task, apps []state.Task) (state.Task, error) {
} }
func isMesosApplicationEnabled(task state.Task, exposedByDefault bool) bool { func isMesosApplicationEnabled(task state.Task, exposedByDefault bool) bool {
return exposedByDefault && labels(task, "traefik.enable") != "false" || labels(task, "traefik.enable") == "true" return exposedByDefault && labels(task, types.LabelEnable) != "false" || labels(task, types.LabelEnable) == "true"
} }
func (p *Provider) getLabel(task state.Task, label string) (string, error) { func (p *Provider) getLabel(task state.Task, label string) (string, error) {
@ -278,12 +278,12 @@ func (p *Provider) getPort(task state.Task, applications []state.Task) string {
return "" return ""
} }
if portIndexLabel, err := p.getLabel(application, "traefik.portIndex"); err == nil { if portIndexLabel, err := p.getLabel(application, types.LabelPortIndex); err == nil {
if index, err := strconv.Atoi(portIndexLabel); err == nil { if index, err := strconv.Atoi(portIndexLabel); err == nil {
return strconv.Itoa(task.DiscoveryInfo.Ports.DiscoveryPorts[index].Number) return strconv.Itoa(task.DiscoveryInfo.Ports.DiscoveryPorts[index].Number)
} }
} }
if portValueLabel, err := p.getLabel(application, "traefik.port"); err == nil { if portValueLabel, err := p.getLabel(application, types.LabelPort); err == nil {
return portValueLabel return portValueLabel
} }
@ -300,14 +300,14 @@ func (p *Provider) getWeight(task state.Task, applications []state.Task) string
return "0" return "0"
} }
if label, err := p.getLabel(application, "traefik.weight"); err == nil { if label, err := p.getLabel(application, types.LabelWeight); err == nil {
return label return label
} }
return "0" return "0"
} }
func (p *Provider) getDomain(task state.Task) string { func (p *Provider) getDomain(task state.Task) string {
if label, err := p.getLabel(task, "traefik.domain"); err == nil { if label, err := p.getLabel(task, types.LabelDomain); err == nil {
return label return label
} }
return p.Domain return p.Domain
@ -319,28 +319,28 @@ func (p *Provider) getProtocol(task state.Task, applications []state.Task) strin
log.Errorf("Unable to get Mesos application from task %s", task.DiscoveryInfo.Name) log.Errorf("Unable to get Mesos application from task %s", task.DiscoveryInfo.Name)
return "http" return "http"
} }
if label, err := p.getLabel(application, "traefik.protocol"); err == nil { if label, err := p.getLabel(application, types.LabelProtocol); err == nil {
return label return label
} }
return "http" return "http"
} }
func (p *Provider) getPassHostHeader(task state.Task) string { func (p *Provider) getPassHostHeader(task state.Task) string {
if passHostHeader, err := p.getLabel(task, "traefik.frontend.passHostHeader"); err == nil { if passHostHeader, err := p.getLabel(task, types.LabelFrontendPassHostHeader); err == nil {
return passHostHeader return passHostHeader
} }
return "false" return "false"
} }
func (p *Provider) getPriority(task state.Task) string { func (p *Provider) getPriority(task state.Task) string {
if priority, err := p.getLabel(task, "traefik.frontend.priority"); err == nil { if priority, err := p.getLabel(task, types.LabelFrontendPriority); err == nil {
return priority return priority
} }
return "0" return "0"
} }
func (p *Provider) getEntryPoints(task state.Task) []string { func (p *Provider) getEntryPoints(task state.Task) []string {
if entryPoints, err := p.getLabel(task, "traefik.frontend.entryPoints"); err == nil { if entryPoints, err := p.getLabel(task, types.LabelFrontendEntryPoints); err == nil {
return strings.Split(entryPoints, ",") return strings.Split(entryPoints, ",")
} }
return []string{} return []string{}
@ -349,7 +349,7 @@ func (p *Provider) getEntryPoints(task state.Task) []string {
// getFrontendRule returns the frontend rule for the specified application, using // getFrontendRule returns the frontend rule for the specified application, using
// it's label. It returns a default one (Host) if the label is not present. // it's label. It returns a default one (Host) if the label is not present.
func (p *Provider) getFrontendRule(task state.Task) string { func (p *Provider) getFrontendRule(task state.Task) string {
if label, err := p.getLabel(task, "traefik.frontend.rule"); err == nil { if label, err := p.getLabel(task, types.LabelFrontendRule); err == nil {
return label return label
} }
return "Host:" + strings.ToLower(strings.Replace(p.getSubDomain(task.DiscoveryInfo.Name), "_", "-", -1)) + "." + p.Domain return "Host:" + strings.ToLower(strings.Replace(p.getSubDomain(task.DiscoveryInfo.Name), "_", "-", -1)) + "." + p.Domain
@ -365,7 +365,7 @@ func (p *Provider) getBackend(task state.Task, applications []state.Task) string
} }
func (p *Provider) getFrontendBackend(task state.Task) string { func (p *Provider) getFrontendBackend(task state.Task) string {
if label, err := p.getLabel(task, "traefik.backend"); err == nil { if label, err := p.getLabel(task, types.LabelBackend); err == nil {
return label return label
} }
return "-" + cleanupSpecialChars(task.DiscoveryInfo.Name) return "-" + cleanupSpecialChars(task.DiscoveryInfo.Name)

View file

@ -30,7 +30,7 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "false"), setLabels(types.LabelEnable, "false"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: false, // because label traefik.enable = false expected: false, // because label traefik.enable = false
@ -40,7 +40,7 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true"), setLabels(types.LabelEnable, "true"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: true, expected: true,
@ -50,7 +50,7 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true"), setLabels(types.LabelEnable, "true"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: true, expected: true,
@ -60,7 +60,7 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "false"), setLabels(types.LabelEnable, "false"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: false, // because label traefik.enable = false (even wherek exposedByDefault = true) expected: false, // because label traefik.enable = false (even wherek exposedByDefault = true)
@ -70,9 +70,9 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true", setLabels(types.LabelEnable, "true",
"traefik.portIndex", "1", types.LabelPortIndex, "1",
"traefik.port", "80"), types.LabelPort, "80"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: false, // traefik.portIndex & traefik.port cannot be set both expected: false, // traefik.portIndex & traefik.port cannot be set both
@ -82,8 +82,8 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true", setLabels(types.LabelEnable, "true",
"traefik.portIndex", "1"), types.LabelPortIndex, "1"),
discovery(setDiscoveryPorts("TCP", 80, "WEB HTTP", "TCP", 443, "WEB HTTPS")), discovery(setDiscoveryPorts("TCP", 80, "WEB HTTP", "TCP", 443, "WEB HTTPS")),
), ),
expected: true, expected: true,
@ -93,7 +93,7 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true"), setLabels(types.LabelEnable, "true"),
discovery(setDiscoveryPorts("TCP", 80, "WEB HTTP", "TCP", 443, "WEB HTTPS")), discovery(setDiscoveryPorts("TCP", 80, "WEB HTTP", "TCP", 443, "WEB HTTPS")),
), ),
expected: true, // Default to first index expected: true, // Default to first index
@ -103,8 +103,8 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true", setLabels(types.LabelEnable, "true",
"traefik.portIndex", "1"), types.LabelPortIndex, "1"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: false, // traefik.portIndex and discoveryPorts don't correspond expected: false, // traefik.portIndex and discoveryPorts don't correspond
@ -113,8 +113,8 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true", setLabels(types.LabelEnable, "true",
"traefik.portIndex", "0"), types.LabelPortIndex, "0"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: true, // traefik.portIndex and discoveryPorts correspond expected: true, // traefik.portIndex and discoveryPorts correspond
@ -123,8 +123,8 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true", setLabels(types.LabelEnable, "true",
"traefik.port", "TRAEFIK"), types.LabelPort, "TRAEFIK"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: false, // traefik.port is not an integer expected: false, // traefik.port is not an integer
@ -133,8 +133,8 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true", setLabels(types.LabelEnable, "true",
"traefik.port", "443"), types.LabelPort, "443"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: false, // traefik.port is not the same as discovery.port expected: false, // traefik.port is not the same as discovery.port
@ -143,8 +143,8 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(true))), setHealthy(true))),
setLabels("traefik.enable", "true", setLabels(types.LabelEnable, "true",
"traefik.port", "80"), types.LabelPort, "80"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: true, // traefik.port is the same as discovery.port expected: true, // traefik.port is the same as discovery.port
@ -152,8 +152,8 @@ func TestMesosTaskFilter(t *testing.T) {
}, { }, {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"))), setState("TASK_RUNNING"))),
setLabels("traefik.enable", "true", setLabels(types.LabelEnable, "true",
"traefik.port", "80"), types.LabelPort, "80"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: true, // No healthCheck expected: true, // No healthCheck
@ -162,8 +162,8 @@ func TestMesosTaskFilter(t *testing.T) {
mesosTask: task(statuses(status( mesosTask: task(statuses(status(
setState("TASK_RUNNING"), setState("TASK_RUNNING"),
setHealthy(false))), setHealthy(false))),
setLabels("traefik.enable", "true", setLabels(types.LabelEnable, "true",
"traefik.port", "80"), types.LabelPort, "80"),
discovery(setDiscoveryPort("TCP", 80, "WEB")), discovery(setDiscoveryPort("TCP", 80, "WEB")),
), ),
expected: false, // HealthCheck at false expected: false, // HealthCheck at false

View file

@ -10,13 +10,12 @@ import (
"github.com/containous/traefik/log" "github.com/containous/traefik/log"
"github.com/containous/traefik/safe" "github.com/containous/traefik/safe"
"github.com/containous/traefik/types" "github.com/containous/traefik/types"
rancher "github.com/rancher/go-rancher/client" rancher "github.com/rancher/go-rancher/client"
) )
var ( const labelRancheStackServiceName = "io.rancher.stack_service.name"
withoutPagination *rancher.ListOpts
) var withoutPagination *rancher.ListOpts
// APIConfiguration contains configuration properties specific to the Rancher // APIConfiguration contains configuration properties specific to the Rancher
// API provider. // API provider.
@ -221,7 +220,7 @@ func parseAPISourcedRancherData(environments []*rancher.Project, services []*ran
} }
for _, container := range containers { for _, container := range containers {
if container.Labels["io.rancher.stack_service.name"] == rancherData.Name && if container.Labels[labelRancheStackServiceName] == rancherData.Name &&
containerFilter(container.Name, container.HealthState, container.State) { containerFilter(container.Name, container.HealthState, container.State) {
rancherData.Containers = append(rancherData.Containers, container.PrimaryIpAddress) rancherData.Containers = append(rancherData.Containers, container.PrimaryIpAddress)
} }

View file

@ -42,35 +42,35 @@ func (r rancherData) String() string {
// Frontend Labels // Frontend Labels
func (p *Provider) getPassHostHeader(service rancherData) string { func (p *Provider) getPassHostHeader(service rancherData) string {
if passHostHeader, err := getServiceLabel(service, "traefik.frontend.passHostHeader"); err == nil { if passHostHeader, err := getServiceLabel(service, types.LabelFrontendPassHostHeader); err == nil {
return passHostHeader return passHostHeader
} }
return "true" return "true"
} }
func (p *Provider) getPriority(service rancherData) string { func (p *Provider) getPriority(service rancherData) string {
if priority, err := getServiceLabel(service, "traefik.frontend.priority"); err == nil { if priority, err := getServiceLabel(service, types.LabelFrontendPriority); err == nil {
return priority return priority
} }
return "0" return "0"
} }
func (p *Provider) getEntryPoints(service rancherData) []string { func (p *Provider) getEntryPoints(service rancherData) []string {
if entryPoints, err := getServiceLabel(service, "traefik.frontend.entryPoints"); err == nil { if entryPoints, err := getServiceLabel(service, types.LabelFrontendEntryPoints); err == nil {
return strings.Split(entryPoints, ",") return strings.Split(entryPoints, ",")
} }
return []string{} return []string{}
} }
func (p *Provider) getFrontendRule(service rancherData) string { func (p *Provider) getFrontendRule(service rancherData) string {
if label, err := getServiceLabel(service, "traefik.frontend.rule"); err == nil { if label, err := getServiceLabel(service, types.LabelFrontendRule); err == nil {
return label return label
} }
return "Host:" + strings.ToLower(strings.Replace(service.Name, "/", ".", -1)) + "." + p.Domain return "Host:" + strings.ToLower(strings.Replace(service.Name, "/", ".", -1)) + "." + p.Domain
} }
func (p *Provider) getBasicAuth(service rancherData) []string { func (p *Provider) getBasicAuth(service rancherData) []string {
if basicAuth, err := getServiceLabel(service, "traefik.frontend.auth.basic"); err == nil { if basicAuth, err := getServiceLabel(service, types.LabelFrontendAuthBasic); err == nil {
return strings.Split(basicAuth, ",") return strings.Split(basicAuth, ",")
} }
return []string{} return []string{}
@ -83,15 +83,15 @@ func (p *Provider) getFrontendName(service rancherData) string {
// Backend Labels // Backend Labels
func (p *Provider) getLoadBalancerMethod(service rancherData) string { func (p *Provider) getLoadBalancerMethod(service rancherData) string {
if label, err := getServiceLabel(service, "traefik.backend.loadbalancer.method"); err == nil { if label, err := getServiceLabel(service, types.LabelBackendLoadbalancerMethod); err == nil {
return label return label
} }
return "wrr" return "wrr"
} }
func (p *Provider) hasLoadBalancerLabel(service rancherData) bool { func (p *Provider) hasLoadBalancerLabel(service rancherData) bool {
_, errMethod := getServiceLabel(service, "traefik.backend.loadbalancer.method") _, errMethod := getServiceLabel(service, types.LabelBackendLoadbalancerMethod)
_, errSticky := getServiceLabel(service, "traefik.backend.loadbalancer.sticky") _, errSticky := getServiceLabel(service, types.LabelBackendLoadbalancerSticky)
if errMethod != nil && errSticky != nil { if errMethod != nil && errSticky != nil {
return false return false
} }
@ -99,28 +99,28 @@ func (p *Provider) hasLoadBalancerLabel(service rancherData) bool {
} }
func (p *Provider) hasCircuitBreakerLabel(service rancherData) bool { func (p *Provider) hasCircuitBreakerLabel(service rancherData) bool {
if _, err := getServiceLabel(service, "traefik.backend.circuitbreaker.expression"); err != nil { if _, err := getServiceLabel(service, types.LabelBackendCircuitbreakerExpression); err != nil {
return false return false
} }
return true return true
} }
func (p *Provider) getCircuitBreakerExpression(service rancherData) string { func (p *Provider) getCircuitBreakerExpression(service rancherData) string {
if label, err := getServiceLabel(service, "traefik.backend.circuitbreaker.expression"); err == nil { if label, err := getServiceLabel(service, types.LabelBackendCircuitbreakerExpression); err == nil {
return label return label
} }
return "NetworkErrorRatio() > 1" return "NetworkErrorRatio() > 1"
} }
func (p *Provider) getSticky(service rancherData) string { func (p *Provider) getSticky(service rancherData) string {
if _, err := getServiceLabel(service, "traefik.backend.loadbalancer.sticky"); err == nil { if _, err := getServiceLabel(service, types.LabelBackendLoadbalancerSticky); err == nil {
return "true" return "true"
} }
return "false" return "false"
} }
func (p *Provider) getBackend(service rancherData) string { func (p *Provider) getBackend(service rancherData) string {
if label, err := getServiceLabel(service, "traefik.backend"); err == nil { if label, err := getServiceLabel(service, types.LabelBackend); err == nil {
return provider.Normalize(label) return provider.Normalize(label)
} }
return provider.Normalize(service.Name) return provider.Normalize(service.Name)
@ -128,48 +128,48 @@ func (p *Provider) getBackend(service rancherData) string {
// General Application Stuff // General Application Stuff
func (p *Provider) getPort(service rancherData) string { func (p *Provider) getPort(service rancherData) string {
if label, err := getServiceLabel(service, "traefik.port"); err == nil { if label, err := getServiceLabel(service, types.LabelPort); err == nil {
return label return label
} }
return "" return ""
} }
func (p *Provider) getProtocol(service rancherData) string { func (p *Provider) getProtocol(service rancherData) string {
if label, err := getServiceLabel(service, "traefik.protocol"); err == nil { if label, err := getServiceLabel(service, types.LabelProtocol); err == nil {
return label return label
} }
return "http" return "http"
} }
func (p *Provider) getWeight(service rancherData) string { func (p *Provider) getWeight(service rancherData) string {
if label, err := getServiceLabel(service, "traefik.weight"); err == nil { if label, err := getServiceLabel(service, types.LabelWeight); err == nil {
return label return label
} }
return "0" return "0"
} }
func (p *Provider) getDomain(service rancherData) string { func (p *Provider) getDomain(service rancherData) string {
if label, err := getServiceLabel(service, "traefik.domain"); err == nil { if label, err := getServiceLabel(service, types.LabelDomain); err == nil {
return label return label
} }
return p.Domain return p.Domain
} }
func (p *Provider) hasMaxConnLabels(service rancherData) bool { func (p *Provider) hasMaxConnLabels(service rancherData) bool {
if _, err := getServiceLabel(service, "traefik.backend.maxconn.amount"); err != nil { if _, err := getServiceLabel(service, types.LabelBackendMaxconnAmount); err != nil {
return false return false
} }
if _, err := getServiceLabel(service, "traefik.backend.maxconn.extractorfunc"); err != nil { if _, err := getServiceLabel(service, types.LabelBackendMaxconnExtractorfunc); err != nil {
return false return false
} }
return true return true
} }
func (p *Provider) getMaxConnAmount(service rancherData) int64 { func (p *Provider) getMaxConnAmount(service rancherData) int64 {
if label, err := getServiceLabel(service, "traefik.backend.maxconn.amount"); err == nil { if label, err := getServiceLabel(service, types.LabelBackendMaxconnAmount); err == nil {
i, errConv := strconv.ParseInt(label, 10, 64) i, errConv := strconv.ParseInt(label, 10, 64)
if errConv != nil { if errConv != nil {
log.Errorf("Unable to parse traefik.backend.maxconn.amount %s", label) log.Errorf("Unable to parse %s %s", types.LabelBackendMaxconnAmount, label)
return math.MaxInt64 return math.MaxInt64
} }
return i return i
@ -178,7 +178,7 @@ func (p *Provider) getMaxConnAmount(service rancherData) int64 {
} }
func (p *Provider) getMaxConnExtractorFunc(service rancherData) string { func (p *Provider) getMaxConnExtractorFunc(service rancherData) string {
if label, err := getServiceLabel(service, "traefik.backend.maxconn.extractorfunc"); err == nil { if label, err := getServiceLabel(service, types.LabelBackendMaxconnExtractorfunc); err == nil {
return label return label
} }
return "request.host" return "request.host"
@ -274,7 +274,7 @@ func containerFilter(name, healthState, state string) bool {
func (p *Provider) serviceFilter(service rancherData) bool { func (p *Provider) serviceFilter(service rancherData) bool {
if service.Labels["traefik.port"] == "" { if service.Labels[types.LabelPort] == "" {
log.Debugf("Filtering service %s without traefik.port label", service.Name) log.Debugf("Filtering service %s without traefik.port label", service.Name)
return false return false
} }
@ -284,7 +284,7 @@ func (p *Provider) serviceFilter(service rancherData) bool {
return false return false
} }
constraintTags := strings.Split(service.Labels["traefik.tags"], ",") constraintTags := strings.Split(service.Labels[types.LabelTags], ",")
if ok, failingConstraint := p.MatchConstraints(constraintTags); !ok { if ok, failingConstraint := p.MatchConstraints(constraintTags); !ok {
if failingConstraint != nil { if failingConstraint != nil {
log.Debugf("Filtering service %s with constraint %s", service.Name, failingConstraint.String()) log.Debugf("Filtering service %s with constraint %s", service.Name, failingConstraint.String())
@ -311,8 +311,8 @@ func (p *Provider) serviceFilter(service rancherData) bool {
func isServiceEnabled(service rancherData, exposedByDefault bool) bool { func isServiceEnabled(service rancherData, exposedByDefault bool) bool {
if service.Labels["traefik.enable"] != "" { if service.Labels[types.LabelEnable] != "" {
var v = service.Labels["traefik.enable"] var v = service.Labels[types.LabelEnable]
return exposedByDefault && v != "false" || v == "true" return exposedByDefault && v != "false" || v == "true"
} }
return exposedByDefault return exposedByDefault

View file

@ -24,7 +24,7 @@ func TestRancherServiceFilter(t *testing.T) {
{ {
service: rancherData{ service: rancherData{
Labels: map[string]string{ Labels: map[string]string{
"traefik.enable": "true", types.LabelEnable: "true",
}, },
Health: "healthy", Health: "healthy",
State: "active", State: "active",
@ -34,8 +34,8 @@ func TestRancherServiceFilter(t *testing.T) {
{ {
service: rancherData{ service: rancherData{
Labels: map[string]string{ Labels: map[string]string{
"traefik.port": "80", types.LabelPort: "80",
"traefik.enable": "false", types.LabelEnable: "false",
}, },
Health: "healthy", Health: "healthy",
State: "active", State: "active",
@ -45,8 +45,8 @@ func TestRancherServiceFilter(t *testing.T) {
{ {
service: rancherData{ service: rancherData{
Labels: map[string]string{ Labels: map[string]string{
"traefik.port": "80", types.LabelPort: "80",
"traefik.enable": "true", types.LabelEnable: "true",
}, },
Health: "unhealthy", Health: "unhealthy",
State: "active", State: "active",
@ -56,9 +56,9 @@ func TestRancherServiceFilter(t *testing.T) {
{ {
service: rancherData{ service: rancherData{
Labels: map[string]string{ Labels: map[string]string{
"traefik.tags": "not-cheesy", types.LabelTags: "not-cheesy",
"traefik.port": "80", types.LabelPort: "80",
"traefik.enable": "true", types.LabelEnable: "true",
}, },
Health: "healthy", Health: "healthy",
State: "inactive", State: "inactive",
@ -68,9 +68,9 @@ func TestRancherServiceFilter(t *testing.T) {
{ {
service: rancherData{ service: rancherData{
Labels: map[string]string{ Labels: map[string]string{
"traefik.tags": "cheese", types.LabelTags: "cheese",
"traefik.port": "80", types.LabelPort: "80",
"traefik.enable": "true", types.LabelEnable: "true",
}, },
Health: "healthy", Health: "healthy",
State: "active", State: "active",
@ -80,9 +80,9 @@ func TestRancherServiceFilter(t *testing.T) {
{ {
service: rancherData{ service: rancherData{
Labels: map[string]string{ Labels: map[string]string{
"traefik.tags": "cheeeeese", types.LabelTags: "cheeeeese",
"traefik.port": "80", types.LabelPort: "80",
"traefik.enable": "true", types.LabelEnable: "true",
}, },
Health: "healthy", Health: "healthy",
State: "upgraded", State: "upgraded",
@ -92,9 +92,9 @@ func TestRancherServiceFilter(t *testing.T) {
{ {
service: rancherData{ service: rancherData{
Labels: map[string]string{ Labels: map[string]string{
"traefik.tags": "chose", types.LabelTags: "chose",
"traefik.port": "80", types.LabelPort: "80",
"traefik.enable": "true", types.LabelEnable: "true",
}, },
Health: "healthy", Health: "healthy",
State: "active", State: "active",
@ -171,7 +171,7 @@ func TestRancherGetFrontendName(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.rule": "Headers:User-Agent,bat/0.1.0", types.LabelFrontendRule: "Headers:User-Agent,bat/0.1.0",
}, },
}, },
@ -181,7 +181,7 @@ func TestRancherGetFrontendName(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.rule": "Host:foo.bar", types.LabelFrontendRule: "Host:foo.bar",
}, },
}, },
@ -191,7 +191,7 @@ func TestRancherGetFrontendName(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.rule": "Path:/test", types.LabelFrontendRule: "Path:/test",
}, },
}, },
@ -201,7 +201,7 @@ func TestRancherGetFrontendName(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.rule": "PathPrefix:/test2", types.LabelFrontendRule: "PathPrefix:/test2",
}, },
}, },
@ -242,7 +242,7 @@ func TestRancherGetFrontendRule(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.rule": "Host:foo.bar.com", types.LabelFrontendRule: "Host:foo.bar.com",
}, },
}, },
@ -252,7 +252,7 @@ func TestRancherGetFrontendRule(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.rule": "Path:/test", types.LabelFrontendRule: "Path:/test",
}, },
}, },
@ -262,7 +262,7 @@ func TestRancherGetFrontendRule(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.rule": "PathPrefix:/test2", types.LabelFrontendRule: "PathPrefix:/test2",
}, },
}, },
@ -297,7 +297,7 @@ func TestRancherGetBackend(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.backend": "foobar", types.LabelBackend: "foobar",
}, },
}, },
@ -332,7 +332,7 @@ func TestRancherGetWeight(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.weight": "5", types.LabelWeight: "5",
}, },
}, },
@ -367,7 +367,7 @@ func TestRancherGetPort(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.port": "1337", types.LabelPort: "1337",
}, },
}, },
@ -402,7 +402,7 @@ func TestRancherGetDomain(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.domain": "foo.bar", types.LabelDomain: "foo.bar",
}, },
}, },
@ -437,7 +437,7 @@ func TestRancherGetProtocol(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.protocol": "https", types.LabelProtocol: "https",
}, },
}, },
@ -472,7 +472,7 @@ func TestRancherGetPassHostHeader(t *testing.T) {
service: rancherData{ service: rancherData{
Name: "test-service", Name: "test-service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.frontend.passHostHeader": "false", types.LabelFrontendPassHostHeader: "false",
}, },
}, },
@ -541,8 +541,8 @@ func TestRancherLoadRancherConfig(t *testing.T) {
{ {
Name: "test/service", Name: "test/service",
Labels: map[string]string{ Labels: map[string]string{
"traefik.port": "80", types.LabelPort: "80",
"traefik.frontend.auth.basic": "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0", types.LabelFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
}, },
Health: "healthy", Health: "healthy",
Containers: []string{"127.0.0.1"}, Containers: []string{"127.0.0.1"},

54
types/common_label.go Normal file
View file

@ -0,0 +1,54 @@
package types
const (
// LabelDomain Traefik label
LabelDomain = "traefik.domain"
// LabelEnable Traefik label
LabelEnable = "traefik.enable"
// LabelPort Traefik label
LabelPort = "traefik.port"
// LabelPortIndex Traefik label
LabelPortIndex = "traefik.portIndex"
// LabelProtocol Traefik label
LabelProtocol = "traefik.protocol"
// LabelTags Traefik label
LabelTags = "traefik.tags"
// LabelWeight Traefik label
LabelWeight = "traefik.weight"
// LabelFrontendAuthBasic Traefik label
LabelFrontendAuthBasic = "traefik.frontend.auth.basic"
// LabelFrontendEntryPoints Traefik label
LabelFrontendEntryPoints = "traefik.frontend.entryPoints"
// LabelFrontendPassHostHeader Traefik label
LabelFrontendPassHostHeader = "traefik.frontend.passHostHeader"
// LabelFrontendPriority Traefik label
LabelFrontendPriority = "traefik.frontend.priority"
// LabelFrontendRule Traefik label
LabelFrontendRule = "traefik.frontend.rule"
// LabelFrontendRuleType Traefik label
LabelFrontendRuleType = "traefik.frontend.rule.type"
// LabelTraefikFrontendValue Traefik label
LabelTraefikFrontendValue = "traefik.frontend.value"
// LabelTraefikFrontendWhitelistSourceRange Traefik label
LabelTraefikFrontendWhitelistSourceRange = "traefik.frontend.whitelistSourceRange"
// LabelBackend Traefik label
LabelBackend = "traefik.backend"
// LabelBackendID Traefik label
LabelBackendID = "traefik.backend.id"
// LabelTraefikBackendCircuitbreaker Traefik label
LabelTraefikBackendCircuitbreaker = "traefik.backend.circuitbreaker"
// LabelBackendCircuitbreakerExpression Traefik label
LabelBackendCircuitbreakerExpression = "traefik.backend.circuitbreaker.expression"
// LabelBackendHealthcheckPath Traefik label
LabelBackendHealthcheckPath = "traefik.backend.healthcheck.path"
// LabelBackendHealthcheckInterval Traefik label
LabelBackendHealthcheckInterval = "traefik.backend.healthcheck.interval"
// LabelBackendLoadbalancerMethod Traefik label
LabelBackendLoadbalancerMethod = "traefik.backend.loadbalancer.method"
// LabelBackendLoadbalancerSticky Traefik label
LabelBackendLoadbalancerSticky = "traefik.backend.loadbalancer.sticky"
// LabelBackendMaxconnAmount Traefik label
LabelBackendMaxconnAmount = "traefik.backend.maxconn.amount"
// LabelBackendMaxconnExtractorfunc Traefik label
LabelBackendMaxconnExtractorfunc = "traefik.backend.maxconn.extractorfunc"
)