feat(ecs): add frontend redirect labels.

This commit is contained in:
Fernandez Ludovic 2017-12-16 20:12:44 +01:00 committed by Traefiker
parent e45e63dc37
commit e60fbbbebe
2 changed files with 21 additions and 0 deletions

View file

@ -41,6 +41,10 @@ func (p *Provider) buildConfiguration(services map[string][]ecsInstance) (*types
"getMaxConnAmount": getFuncFirstInt64Value(label.TraefikBackendMaxConnAmount, math.MaxInt64),
"getMaxConnExtractorFunc": getFuncFirstStringValue(label.TraefikBackendMaxConnExtractorFunc, label.DefaultBackendMaxconnExtractorFunc),
"getWhitelistSourceRange": getFuncSliceString(label.TraefikFrontendWhitelistSourceRange),
"hasRedirect": hasRedirect,
"getRedirectEntryPoint": getFuncStringValue(label.TraefikFrontendRedirectEntryPoint, label.DefaultFrontendRedirectEntryPoint),
"getRedirectRegex": getFuncStringValue(label.TraefikFrontendRedirectRegex, ""),
"getRedirectReplacement": getFuncStringValue(label.TraefikFrontendRedirectReplacement, ""),
}
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
Services map[string][]ecsInstance
@ -101,6 +105,11 @@ func hasMaxConnLabels(instances []ecsInstance) bool {
return mca && mcef
}
func hasRedirect(instance ecsInstance) bool {
return hasLabel(instance, label.TraefikFrontendRedirectEntryPoint) ||
hasLabel(instance, label.TraefikFrontendRedirectRegex) && hasLabel(instance, label.TraefikFrontendRedirectReplacement)
}
// Label functions
func getFuncStringValue(labelName string, defaultValue string) func(i ecsInstance) string {
@ -160,6 +169,11 @@ func getFuncFirstBoolValue(labelName string, defaultValue bool) func(instances [
}
}
func hasLabel(i ecsInstance, labelName string) bool {
value, ok := i.containerDefinition.DockerLabels[labelName]
return ok && value != nil && len(*value) > 0
}
func getStringValue(i ecsInstance, labelName string, defaultValue string) string {
if v, ok := i.containerDefinition.DockerLabels[labelName]; ok {
if v == nil {

View file

@ -61,6 +61,13 @@
"{{.}}",
{{end}}]
{{if hasRedirect $service}}
[frontends."frontend-{{ $serviceName }}".redirect]
entryPoint = "{{getRedirectEntryPoint .}}"
regex = "{{getRedirectRegex .}}"
replacement = "{{getRedirectReplacement .}}"
{{end}}
[frontends.frontend-{{ $serviceName }}.routes.route-frontend-{{ $serviceName }}]
rule = "{{getFrontendRule .}}"