diff --git a/autogen/gentemplates/gen.go b/autogen/gentemplates/gen.go index e4b479f9a..2eb30a08e 100644 --- a/autogen/gentemplates/gen.go +++ b/autogen/gentemplates/gen.go @@ -572,7 +572,7 @@ var _templatesKvTmpl = []byte(`{{$frontends := List .Prefix "/frontends/" }} [frontends]{{range $frontends}} {{$frontend := Last .}} - {{$entryPoints := SplitGet . "/entrypoints"}} + {{$entryPoints := GetList . "/entrypoints"}} [frontends."{{$frontend}}"] backend = "{{Get "" . "/backend"}}" passHostHeader = {{Get "true" . "/passHostHeader"}} diff --git a/provider/kv/kv.go b/provider/kv/kv.go index 6d5e4d0f9..9c065723a 100644 --- a/provider/kv/kv.go +++ b/provider/kv/kv.go @@ -147,6 +147,7 @@ func (p *Provider) loadConfig() *types.Configuration { "getSticky": p.getSticky, "hasStickinessLabel": p.hasStickinessLabel, "getStickinessCookieName": p.getStickinessCookieName, + "GetList": p.getList, } configuration, err := p.GetConfiguration("templates/kv.tmpl", KvFuncMap, templateObjects) @@ -264,3 +265,31 @@ func (p *Provider) hasStickinessLabel(rootPath string) bool { func (p *Provider) getStickinessCookieName(rootPath string) string { return p.get("", rootPath, "/loadbalancer", "/stickiness", "/cookiename") } + +func (p *Provider) getList(keyParts ...string) []string { + values := p.splitGet(keyParts...) + if len(values) > 0 { + return values + } + + return p.getSlice(keyParts...) +} + +// get sub keys. ex: foo/0, foo/1, foo/2 +func (p *Provider) getSlice(keyParts ...string) []string { + baseKey := strings.Join(keyParts, "") + if !strings.HasSuffix(baseKey, "/") { + baseKey += "/" + } + + listKeys := p.list(baseKey) + + var values []string + for _, entryKey := range listKeys { + val := p.get("", entryKey) + if len(val) > 0 { + values = append(values, val) + } + } + return values +} diff --git a/templates/kv.tmpl b/templates/kv.tmpl index 08d353016..fc4ab782f 100644 --- a/templates/kv.tmpl +++ b/templates/kv.tmpl @@ -50,7 +50,7 @@ [frontends]{{range $frontends}} {{$frontend := Last .}} - {{$entryPoints := SplitGet . "/entrypoints"}} + {{$entryPoints := GetList . "/entrypoints"}} [frontends."{{$frontend}}"] backend = "{{Get "" . "/backend"}}" passHostHeader = {{Get "true" . "/passHostHeader"}}