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:
parent
2e84b1e556
commit
d653a348b1
20 changed files with 390 additions and 330 deletions
|
@ -35,6 +35,11 @@ const (
|
|||
SwarmAPIVersion string = "1.24"
|
||||
// SwarmDefaultWatchTime is the duration of the interval when polling docker
|
||||
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)
|
||||
|
@ -319,7 +324,7 @@ func (p *Provider) loadDockerConfig(containersInspected []dockerData) *types.Con
|
|||
}
|
||||
|
||||
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 true
|
||||
|
@ -455,8 +460,8 @@ func (p *Provider) getServiceProtocol(container dockerData, serviceName string)
|
|||
}
|
||||
|
||||
func (p *Provider) hasLoadBalancerLabel(container dockerData) bool {
|
||||
_, errMethod := getLabel(container, "traefik.backend.loadbalancer.method")
|
||||
_, errSticky := getLabel(container, "traefik.backend.loadbalancer.sticky")
|
||||
_, errMethod := getLabel(container, types.LabelBackendLoadbalancerMethod)
|
||||
_, errSticky := getLabel(container, types.LabelBackendLoadbalancerSticky)
|
||||
if errMethod != nil && errSticky != nil {
|
||||
return false
|
||||
}
|
||||
|
@ -464,31 +469,31 @@ func (p *Provider) hasLoadBalancerLabel(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
|
||||
}
|
||||
if _, err := getLabel(container, "traefik.backend.maxconn.extractorfunc"); err != nil {
|
||||
if _, err := getLabel(container, types.LabelBackendMaxconnExtractorfunc); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
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 "NetworkErrorRatio() > 1"
|
||||
}
|
||||
|
||||
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 "wrr"
|
||||
}
|
||||
|
||||
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)
|
||||
if errConv != nil {
|
||||
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 {
|
||||
if label, err := getLabel(container, "traefik.backend.maxconn.extractorfunc"); err == nil {
|
||||
if label, err := getLabel(container, types.LabelBackendMaxconnExtractorfunc); err == nil {
|
||||
return label
|
||||
}
|
||||
return "request.host"
|
||||
}
|
||||
|
||||
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 {
|
||||
log.Debugf("Filtering container without port and no traefik.port label %s", container.Name)
|
||||
return false
|
||||
|
@ -518,7 +523,7 @@ func (p *Provider) containerFilter(container dockerData) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
constraintTags := strings.Split(container.Labels["traefik.tags"], ",")
|
||||
constraintTags := strings.Split(container.Labels[types.LabelTags], ",")
|
||||
if ok, failingConstraint := p.MatchConstraints(constraintTags); !ok {
|
||||
if failingConstraint != nil {
|
||||
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
|
||||
// it's label. It returns a default one (Host) if the label is not present.
|
||||
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
|
||||
}
|
||||
if labels, err := getLabels(container, []string{"com.docker.compose.project", "com.docker.compose.service"}); err == nil {
|
||||
return "Host:" + p.getSubDomain(labels["com.docker.compose.service"]+"."+labels["com.docker.compose.project"]) + "." + p.Domain
|
||||
if labels, err := getLabels(container, []string{labelDockerComposeProject, labelDockerComposeService}); err == nil {
|
||||
return "Host:" + p.getSubDomain(labels[labelDockerComposeService]+"."+labels[labelDockerComposeProject]) + "." + p.Domain
|
||||
}
|
||||
if len(p.Domain) > 0 {
|
||||
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 {
|
||||
if label, err := getLabel(container, "traefik.backend"); err == nil {
|
||||
if label, err := getLabel(container, types.LabelBackend); err == nil {
|
||||
return provider.Normalize(label)
|
||||
}
|
||||
if labels, err := getLabels(container, []string{"com.docker.compose.project", "com.docker.compose.service"}); err == nil {
|
||||
return provider.Normalize(labels["com.docker.compose.service"] + "_" + labels["com.docker.compose.project"])
|
||||
if labels, err := getLabels(container, []string{labelDockerComposeProject, labelDockerComposeService}); err == nil {
|
||||
return provider.Normalize(labels[labelDockerComposeService] + "_" + labels[labelDockerComposeProject])
|
||||
}
|
||||
return provider.Normalize(container.ServiceName)
|
||||
}
|
||||
|
||||
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
|
||||
if networkSettings.Networks != nil {
|
||||
network := networkSettings.Networks[label]
|
||||
|
@ -606,7 +611,7 @@ func (p *Provider) getIPAddress(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
|
||||
}
|
||||
|
||||
|
@ -630,42 +635,42 @@ func (p *Provider) getPort(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 "0"
|
||||
}
|
||||
|
||||
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 "false"
|
||||
}
|
||||
|
||||
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 "false"
|
||||
}
|
||||
|
||||
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 p.Domain
|
||||
}
|
||||
|
||||
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 "http"
|
||||
}
|
||||
|
||||
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 "true"
|
||||
|
@ -674,28 +679,28 @@ func (p *Provider) getPassHostHeader(container dockerData) string {
|
|||
func (p *Provider) getWhitelistSourceRange(container dockerData) []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)
|
||||
}
|
||||
return whitelistSourceRange
|
||||
}
|
||||
|
||||
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 "0"
|
||||
}
|
||||
|
||||
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 []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, ",")
|
||||
}
|
||||
|
||||
|
@ -703,7 +708,7 @@ func (p *Provider) getBasicAuth(container dockerData) []string {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -23,7 +23,7 @@ func TestDockerGetFrontendName(t *testing.T) {
|
|||
},
|
||||
{
|
||||
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",
|
||||
},
|
||||
|
@ -36,19 +36,19 @@ func TestDockerGetFrontendName(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
types.LabelFrontendRule: "Host:foo.bar",
|
||||
})),
|
||||
expected: "Host-foo-bar",
|
||||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.rule": "Path:/test",
|
||||
types.LabelFrontendRule: "Path:/test",
|
||||
})),
|
||||
expected: "Path-test",
|
||||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.rule": "PathPrefix:/test2",
|
||||
types.LabelFrontendRule: "PathPrefix:/test2",
|
||||
})),
|
||||
expected: "PathPrefix-test2",
|
||||
},
|
||||
|
@ -85,7 +85,7 @@ func TestDockerGetFrontendRule(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
types.LabelFrontendRule: "Host:foo.bar",
|
||||
})),
|
||||
expected: "Host:foo.bar",
|
||||
}, {
|
||||
|
@ -97,7 +97,7 @@ func TestDockerGetFrontendRule(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.rule": "Path:/test",
|
||||
types.LabelFrontendRule: "Path:/test",
|
||||
})),
|
||||
expected: "Path:/test",
|
||||
},
|
||||
|
@ -134,7 +134,7 @@ func TestDockerGetBackend(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.backend": "foobar",
|
||||
types.LabelBackend: "foobar",
|
||||
})),
|
||||
expected: "foobar",
|
||||
},
|
||||
|
@ -173,7 +173,7 @@ func TestDockerGetIPAddress(t *testing.T) {
|
|||
{
|
||||
container: containerJSON(
|
||||
labels(map[string]string{
|
||||
"traefik.docker.network": "testnet",
|
||||
labelDockerNetwork: "testnet",
|
||||
}),
|
||||
withNetwork("testnet", ipv4("10.11.12.13")),
|
||||
),
|
||||
|
@ -182,7 +182,7 @@ func TestDockerGetIPAddress(t *testing.T) {
|
|||
{
|
||||
container: containerJSON(
|
||||
labels(map[string]string{
|
||||
"traefik.docker.network": "testnet2",
|
||||
labelDockerNetwork: "testnet2",
|
||||
}),
|
||||
withNetwork("testnet", ipv4("10.11.12.13")),
|
||||
withNetwork("testnet2", ipv4("10.11.12.14")),
|
||||
|
@ -237,13 +237,13 @@ func TestDockerGetPort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.port": "8080",
|
||||
types.LabelPort: "8080",
|
||||
})),
|
||||
expected: "8080",
|
||||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.port": "8080",
|
||||
types.LabelPort: "8080",
|
||||
}), ports(nat.PortMap{
|
||||
"80/tcp": {},
|
||||
})),
|
||||
|
@ -251,7 +251,7 @@ func TestDockerGetPort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.port": "8080",
|
||||
types.LabelPort: "8080",
|
||||
}), ports(nat.PortMap{
|
||||
"8080/tcp": {},
|
||||
"80/tcp": {},
|
||||
|
@ -285,7 +285,7 @@ func TestDockerGetWeight(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.weight": "10",
|
||||
types.LabelWeight: "10",
|
||||
})),
|
||||
expected: "10",
|
||||
},
|
||||
|
@ -316,7 +316,7 @@ func TestDockerGetDomain(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.domain": "foo.bar",
|
||||
types.LabelDomain: "foo.bar",
|
||||
})),
|
||||
expected: "foo.bar",
|
||||
},
|
||||
|
@ -349,7 +349,7 @@ func TestDockerGetProtocol(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.protocol": "https",
|
||||
types.LabelProtocol: "https",
|
||||
})),
|
||||
expected: "https",
|
||||
},
|
||||
|
@ -380,7 +380,7 @@ func TestDockerGetPassHostHeader(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.passHostHeader": "false",
|
||||
types.LabelFrontendPassHostHeader: "false",
|
||||
})),
|
||||
expected: "false",
|
||||
},
|
||||
|
@ -414,14 +414,14 @@ func TestDockerGetWhitelistSourceRange(t *testing.T) {
|
|||
{
|
||||
desc: "whitelist-label with empty string",
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.whitelistSourceRange": "",
|
||||
types.LabelTraefikFrontendWhitelistSourceRange: "",
|
||||
})),
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
desc: "whitelist-label with IPv4 mask",
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.whitelistSourceRange": "1.2.3.4/16",
|
||||
types.LabelTraefikFrontendWhitelistSourceRange: "1.2.3.4/16",
|
||||
})),
|
||||
expected: []string{
|
||||
"1.2.3.4/16",
|
||||
|
@ -430,7 +430,7 @@ func TestDockerGetWhitelistSourceRange(t *testing.T) {
|
|||
{
|
||||
desc: "whitelist-label with IPv6 mask",
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.whitelistSourceRange": "fe80::/16",
|
||||
types.LabelTraefikFrontendWhitelistSourceRange: "fe80::/16",
|
||||
})),
|
||||
expected: []string{
|
||||
"fe80::/16",
|
||||
|
@ -439,7 +439,7 @@ func TestDockerGetWhitelistSourceRange(t *testing.T) {
|
|||
{
|
||||
desc: "whitelist-label with multiple masks",
|
||||
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{
|
||||
"1.1.1.1/24",
|
||||
|
@ -576,7 +576,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "false",
|
||||
types.LabelEnable: "false",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
|
@ -600,7 +600,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
types.LabelFrontendRule: "Host:foo.bar",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
|
@ -665,7 +665,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.port": "80",
|
||||
types.LabelPort: "80",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
|
@ -690,7 +690,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "true",
|
||||
types.LabelEnable: "true",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
|
@ -714,7 +714,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "anything",
|
||||
types.LabelEnable: "anything",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
|
@ -738,7 +738,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
types.LabelFrontendRule: "Host:foo.bar",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
|
@ -782,7 +782,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "true",
|
||||
types.LabelEnable: "true",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
|
@ -806,7 +806,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "true",
|
||||
types.LabelEnable: "true",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
|
@ -829,8 +829,8 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "true",
|
||||
"traefik.frontend.rule": "Host:i.love.this.host",
|
||||
types.LabelEnable: "true",
|
||||
types.LabelFrontendRule: "Host:i.love.this.host",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
|
@ -912,9 +912,9 @@ func TestDockerLoadDockerConfig(t *testing.T) {
|
|||
containerJSON(
|
||||
name("test1"),
|
||||
labels(map[string]string{
|
||||
"traefik.backend": "foobar",
|
||||
"traefik.frontend.entryPoints": "http,https",
|
||||
"traefik.frontend.auth.basic": "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
||||
types.LabelBackend: "foobar",
|
||||
types.LabelFrontendEntryPoints: "http,https",
|
||||
types.LabelFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
"80/tcp": {},
|
||||
|
@ -924,7 +924,7 @@ func TestDockerLoadDockerConfig(t *testing.T) {
|
|||
containerJSON(
|
||||
name("test2"),
|
||||
labels(map[string]string{
|
||||
"traefik.backend": "foobar",
|
||||
types.LabelBackend: "foobar",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
"80/tcp": {},
|
||||
|
@ -977,12 +977,12 @@ func TestDockerLoadDockerConfig(t *testing.T) {
|
|||
containerJSON(
|
||||
name("test1"),
|
||||
labels(map[string]string{
|
||||
"traefik.backend": "foobar",
|
||||
"traefik.frontend.entryPoints": "http,https",
|
||||
"traefik.backend.maxconn.amount": "1000",
|
||||
"traefik.backend.maxconn.extractorfunc": "somethingelse",
|
||||
"traefik.backend.loadbalancer.method": "drr",
|
||||
"traefik.backend.circuitbreaker.expression": "NetworkErrorRatio() > 0.5",
|
||||
types.LabelBackend: "foobar",
|
||||
types.LabelFrontendEntryPoints: "http,https",
|
||||
types.LabelBackendMaxconnAmount: "1000",
|
||||
types.LabelBackendMaxconnExtractorfunc: "somethingelse",
|
||||
types.LabelBackendLoadbalancerMethod: "drr",
|
||||
types.LabelBackendCircuitbreakerExpression: "NetworkErrorRatio() > 0.5",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
"80/tcp": {},
|
||||
|
|
|
@ -23,7 +23,7 @@ func TestDockerGetServiceProtocol(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.protocol": "https",
|
||||
types.LabelProtocol: "https",
|
||||
})),
|
||||
expected: "https",
|
||||
},
|
||||
|
@ -61,7 +61,7 @@ func TestDockerGetServiceWeight(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.weight": "200",
|
||||
types.LabelWeight: "200",
|
||||
})),
|
||||
expected: "200",
|
||||
},
|
||||
|
@ -99,7 +99,7 @@ func TestDockerGetServicePort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.port": "2500",
|
||||
types.LabelPort: "2500",
|
||||
})),
|
||||
expected: "2500",
|
||||
},
|
||||
|
@ -137,7 +137,7 @@ func TestDockerGetServiceFrontendRule(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.rule": "Path:/helloworld",
|
||||
types.LabelFrontendRule: "Path:/helloworld",
|
||||
})),
|
||||
expected: "Path:/helloworld",
|
||||
},
|
||||
|
@ -175,7 +175,7 @@ func TestDockerGetServiceBackend(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.backend": "another-backend",
|
||||
types.LabelBackend: "another-backend",
|
||||
})),
|
||||
expected: "another-backend-myservice",
|
||||
},
|
||||
|
@ -213,7 +213,7 @@ func TestDockerGetServicePriority(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.priority": "33",
|
||||
types.LabelFrontendPriority: "33",
|
||||
})),
|
||||
expected: "33",
|
||||
},
|
||||
|
@ -251,7 +251,7 @@ func TestDockerGetServicePassHostHeader(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.passHostHeader": "false",
|
||||
types.LabelFrontendPassHostHeader: "false",
|
||||
})),
|
||||
expected: "false",
|
||||
},
|
||||
|
@ -289,7 +289,7 @@ func TestDockerGetServiceEntryPoints(t *testing.T) {
|
|||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
"traefik.frontend.entryPoints": "http,https",
|
||||
types.LabelFrontendEntryPoints: "http,https",
|
||||
})),
|
||||
expected: []string{"http", "https"},
|
||||
},
|
||||
|
|
|
@ -28,21 +28,21 @@ func TestSwarmGetFrontendName(t *testing.T) {
|
|||
},
|
||||
{
|
||||
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",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
types.LabelFrontendRule: "Host:foo.bar",
|
||||
})),
|
||||
expected: "Host-foo-bar",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.frontend.rule": "Path:/test",
|
||||
types.LabelFrontendRule: "Path:/test",
|
||||
})),
|
||||
expected: "Path-test",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -51,7 +51,7 @@ func TestSwarmGetFrontendName(t *testing.T) {
|
|||
service: swarmService(
|
||||
serviceName("test"),
|
||||
serviceLabels(map[string]string{
|
||||
"traefik.frontend.rule": "PathPrefix:/test2",
|
||||
types.LabelFrontendRule: "PathPrefix:/test2",
|
||||
}),
|
||||
),
|
||||
expected: "PathPrefix-test2",
|
||||
|
@ -94,14 +94,14 @@ func TestSwarmGetFrontendRule(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
types.LabelFrontendRule: "Host:foo.bar",
|
||||
})),
|
||||
expected: "Host:foo.bar",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.frontend.rule": "Path:/test",
|
||||
types.LabelFrontendRule: "Path:/test",
|
||||
})),
|
||||
expected: "Path:/test",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -143,7 +143,7 @@ func TestSwarmGetBackend(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.backend": "foobar",
|
||||
types.LabelBackend: "foobar",
|
||||
})),
|
||||
expected: "foobar",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -192,7 +192,7 @@ func TestSwarmGetIPAddress(t *testing.T) {
|
|||
{
|
||||
service: swarmService(
|
||||
serviceLabels(map[string]string{
|
||||
"traefik.docker.network": "barnet",
|
||||
labelDockerNetwork: "barnet",
|
||||
}),
|
||||
withEndpointSpec(modeVIP),
|
||||
withEndpoint(
|
||||
|
@ -237,7 +237,7 @@ func TestSwarmGetPort(t *testing.T) {
|
|||
{
|
||||
service: swarmService(
|
||||
serviceLabels(map[string]string{
|
||||
"traefik.port": "8080",
|
||||
types.LabelPort: "8080",
|
||||
}),
|
||||
withEndpointSpec(modeDNSSR),
|
||||
),
|
||||
|
@ -275,7 +275,7 @@ func TestSwarmGetWeight(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.weight": "10",
|
||||
types.LabelWeight: "10",
|
||||
})),
|
||||
expected: "10",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -311,7 +311,7 @@ func TestSwarmGetDomain(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.domain": "foo.bar",
|
||||
types.LabelDomain: "foo.bar",
|
||||
})),
|
||||
expected: "foo.bar",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -348,7 +348,7 @@ func TestSwarmGetProtocol(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.protocol": "https",
|
||||
types.LabelProtocol: "https",
|
||||
})),
|
||||
expected: "https",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -384,7 +384,7 @@ func TestSwarmGetPassHostHeader(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.frontend.passHostHeader": "false",
|
||||
types.LabelFrontendPassHostHeader: "false",
|
||||
})),
|
||||
expected: "false",
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -520,8 +520,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.enable": "false",
|
||||
"traefik.port": "80",
|
||||
types.LabelEnable: "false",
|
||||
types.LabelPort: "80",
|
||||
})),
|
||||
expected: false,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -533,8 +533,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
"traefik.port": "80",
|
||||
types.LabelFrontendRule: "Host:foo.bar",
|
||||
types.LabelPort: "80",
|
||||
})),
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -546,7 +546,7 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.port": "80",
|
||||
types.LabelPort: "80",
|
||||
})),
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -558,8 +558,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.enable": "true",
|
||||
"traefik.port": "80",
|
||||
types.LabelEnable: "true",
|
||||
types.LabelPort: "80",
|
||||
})),
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -571,8 +571,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.enable": "anything",
|
||||
"traefik.port": "80",
|
||||
types.LabelEnable: "anything",
|
||||
types.LabelPort: "80",
|
||||
})),
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -584,8 +584,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
"traefik.port": "80",
|
||||
types.LabelFrontendRule: "Host:foo.bar",
|
||||
types.LabelPort: "80",
|
||||
})),
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -597,7 +597,7 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.port": "80",
|
||||
types.LabelPort: "80",
|
||||
})),
|
||||
expected: false,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -609,8 +609,8 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.enable": "true",
|
||||
"traefik.port": "80",
|
||||
types.LabelEnable: "true",
|
||||
types.LabelPort: "80",
|
||||
})),
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
|
@ -653,7 +653,7 @@ func TestSwarmLoadDockerConfig(t *testing.T) {
|
|||
swarmService(
|
||||
serviceName("test"),
|
||||
serviceLabels(map[string]string{
|
||||
"traefik.port": "80",
|
||||
types.LabelPort: "80",
|
||||
}),
|
||||
withEndpointSpec(modeVIP),
|
||||
withEndpoint(virtualIP("1", "127.0.0.1/24")),
|
||||
|
@ -695,10 +695,10 @@ func TestSwarmLoadDockerConfig(t *testing.T) {
|
|||
swarmService(
|
||||
serviceName("test1"),
|
||||
serviceLabels(map[string]string{
|
||||
"traefik.port": "80",
|
||||
"traefik.backend": "foobar",
|
||||
"traefik.frontend.entryPoints": "http,https",
|
||||
"traefik.frontend.auth.basic": "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
||||
types.LabelPort: "80",
|
||||
types.LabelBackend: "foobar",
|
||||
types.LabelFrontendEntryPoints: "http,https",
|
||||
types.LabelFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
||||
}),
|
||||
withEndpointSpec(modeVIP),
|
||||
withEndpoint(virtualIP("1", "127.0.0.1/24")),
|
||||
|
@ -706,8 +706,8 @@ func TestSwarmLoadDockerConfig(t *testing.T) {
|
|||
swarmService(
|
||||
serviceName("test2"),
|
||||
serviceLabels(map[string]string{
|
||||
"traefik.port": "80",
|
||||
"traefik.backend": "foobar",
|
||||
types.LabelPort: "80",
|
||||
types.LabelBackend: "foobar",
|
||||
}),
|
||||
withEndpointSpec(modeVIP),
|
||||
withEndpoint(virtualIP("1", "127.0.0.1/24")),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue