traefik/vendor/github.com/containous/traefik-extra-service-fabric/servicefabric_tmpl.go

141 lines
4.9 KiB
Go
Raw Normal View History

2017-11-27 13:26:04 +00:00
package servicefabric
const tmpl = `
{{$groupedServiceMap := getServices .Services "backend.group.name"}}
2017-11-27 13:26:04 +00:00
[backends]
{{range $aggName, $aggServices := $groupedServiceMap }}
[backends."{{$aggName}}"]
{{range $service := $aggServices}}
{{range $partition := $service.Partitions}}
{{range $instance := $partition.Instances}}
[backends."{{$aggName}}".servers."{{$service.ID}}-{{$instance.ID}}"]
url = "{{getDefaultEndpoint $instance}}"
weight = {{getLabelValue $service "backend.group.weight" "1"}}
2017-11-27 13:26:04 +00:00
{{end}}
{{end}}
{{end}}
{{end}}
{{range $service := .Services}}
{{range $partition := $service.Partitions}}
{{if eq $partition.ServiceKind "Stateless"}}
[backends."{{$service.Name}}"]
[backends."{{$service.Name}}".LoadBalancer]
{{if hasLabel $service "backend.loadbalancer.method"}}
method = "{{getLabelValue $service "backend.loadbalancer.method" "" }}"
2017-11-27 13:26:04 +00:00
{{else}}
method = "drr"
{{end}}
{{if hasLabel $service "backend.healthcheck"}}
2017-11-27 13:26:04 +00:00
[backends."{{$service.Name}}".healthcheck]
path = "{{getLabelValue $service "backend.healthcheck" ""}}"
interval = "{{getLabelValue $service "backend.healthcheck.interval" "10s"}}"
2017-11-27 13:26:04 +00:00
{{end}}
{{if hasLabel $service "backend.loadbalancer.stickiness"}}
2017-11-27 13:26:04 +00:00
[backends."{{$service.Name}}".LoadBalancer.stickiness]
{{end}}
{{if hasLabel $service "backend.circuitbreaker"}}
2017-11-27 13:26:04 +00:00
[backends."{{$service.Name}}".circuitbreaker]
expression = "{{getLabelValue $service "backend.circuitbreaker" ""}}"
2017-11-27 13:26:04 +00:00
{{end}}
{{if hasLabel $service "backend.maxconn.amount"}}
2017-11-27 13:26:04 +00:00
[backends."{{$service.Name}}".maxconn]
amount = {{getLabelValue $service "backend.maxconn.amount" ""}}
{{if hasLabel $service "backend.maxconn.extractorfunc"}}
extractorfunc = "{{getLabelValue $service "backend.maxconn.extractorfunc" ""}}"
2017-11-27 13:26:04 +00:00
{{end}}
{{end}}
{{range $instance := $partition.Instances}}
[backends."{{$service.Name}}".servers."{{$instance.ID}}"]
url = "{{getDefaultEndpoint $instance}}"
weight = {{getLabelValue $service "backend.weight" "1"}}
2017-11-27 13:26:04 +00:00
{{end}}
{{else if eq $partition.ServiceKind "Stateful"}}
{{range $replica := $partition.Replicas}}
{{if isPrimary $replica}}
{{$backendName := getBackendName $service.Name $partition}}
2017-11-27 13:26:04 +00:00
[backends."{{$backendName}}".servers."{{$replica.ID}}"]
url = "{{getDefaultEndpoint $replica}}"
weight = 1
[backends."{{$backendName}}".LoadBalancer]
method = "drr"
[backends."{{$backendName}}".circuitbreaker]
expression = "NetworkErrorRatio() > 0.5"
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
[frontends]
{{range $groupName, $groupServices := $groupedServiceMap}}
{{$service := index $groupServices 0}}
[frontends."{{$groupName}}"]
backend = "{{$groupName}}"
{{if hasLabel $service "frontend.priority"}}
2017-11-27 13:26:04 +00:00
priority = 100
{{end}}
{{range $key, $value := getLabelsWithPrefix $service "frontend.rule"}}
2017-11-27 13:26:04 +00:00
[frontends."{{$groupName}}".routes."{{$key}}"]
rule = "{{$value}}"
{{end}}
{{end}}
{{range $service := .Services}}
2017-11-29 12:26:03 +00:00
{{if isExposed $service}}
2017-11-27 13:26:04 +00:00
{{if eq $service.ServiceKind "Stateless"}}
[frontends."{{$service.Name}}"]
backend = "{{$service.Name}}"
{{if hasLabel $service "frontend.passHostHeader"}}
passHostHeader = {{getLabelValue $service "frontend.passHostHeader" ""}}
2017-11-27 13:26:04 +00:00
{{end}}
{{if hasLabel $service "frontend.whitelistSourceRange"}}
whitelistSourceRange = {{getLabelValue $service "frontend.whitelistSourceRange" ""}}
2017-11-27 13:26:04 +00:00
{{end}}
{{if hasLabel $service "frontend.priority"}}
priority = {{getLabelValue $service "frontend.priority" ""}}
2017-11-27 13:26:04 +00:00
{{end}}
{{if hasLabel $service "frontend.basicAuth"}}
basicAuth = {{getLabelValue $service "frontend.basicAuth" ""}}
2017-11-27 13:26:04 +00:00
{{end}}
{{if hasLabel $service "frontend.entryPoints"}}
entryPoints = {{getLabelValue $service "frontend.entryPoints" ""}}
2017-11-27 13:26:04 +00:00
{{end}}
{{range $key, $value := getLabelsWithPrefix $service "frontend.rule"}}
2017-11-27 13:26:04 +00:00
[frontends."{{$service.Name}}".routes."{{$key}}"]
rule = "{{$value}}"
{{end}}
{{else if eq $service.ServiceKind "Stateful"}}
{{range $partition := $service.Partitions}}
{{$partitionId := $partition.PartitionInformation.ID}}
{{if hasLabel $service "frontend.rule"}}
2017-11-27 13:26:04 +00:00
[frontends."{{$service.Name}}/{{$partitionId}}"]
backend = "{{getBackendName $service.Name $partition}}"
2017-11-27 13:26:04 +00:00
[frontends."{{$service.Name}}/{{$partitionId}}".routes.default]
rule = {{getLabelValue $service "frontend.rule.partition.$partitionId" ""}}
2017-11-27 13:26:04 +00:00
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
`