1
0
Fork 0

feat(consul-provider): If Service.Address is nil then use Node.Address

test(consul-catalog): Test on backend-name and backend-address
This commit is contained in:
Poney baker 2016-04-15 09:56:06 +02:00
parent 2f5c9273ee
commit 378a261e64
3 changed files with 117 additions and 12 deletions

View file

@ -2,6 +2,7 @@ package provider
import (
"errors"
"strconv"
"strings"
"text/template"
"time"
@ -123,6 +124,26 @@ func (provider *ConsulCatalog) getFrontendRule(service serviceUpdate) string {
return "Host:" + service.ServiceName + "." + provider.Domain
}
func (provider *ConsulCatalog) getBackendAddress(node *api.ServiceEntry) string {
if node.Service.Address != "" {
return node.Service.Address
}
return node.Node.Address
}
func (provider *ConsulCatalog) getBackendName(node *api.ServiceEntry, index int) string {
serviceName := node.Service.Service + "--" + node.Service.Address + "--" + strconv.Itoa(node.Service.Port)
if len(node.Service.Tags) > 0 {
serviceName += "--" + strings.Join(node.Service.Tags, "--")
}
serviceName = strings.Replace(serviceName, ".", "-", -1)
serviceName = strings.Replace(serviceName, "=", "-", -1)
// unique int at the end
serviceName += "--" + strconv.Itoa(index)
return serviceName
}
func (provider *ConsulCatalog) getAttribute(name string, tags []string, defaultValue string) string {
for _, tag := range tags {
if strings.Index(strings.ToLower(tag), DefaultConsulCatalogTagPrefix+".") == 0 {
@ -136,11 +157,12 @@ func (provider *ConsulCatalog) getAttribute(name string, tags []string, defaultV
func (provider *ConsulCatalog) buildConfig(catalog []catalogUpdate) *types.Configuration {
var FuncMap = template.FuncMap{
"getBackend": provider.getBackend,
"getFrontendRule": provider.getFrontendRule,
"getAttribute": provider.getAttribute,
"getEntryPoints": provider.getEntryPoints,
"replace": replace,
"getBackend": provider.getBackend,
"getFrontendRule": provider.getFrontendRule,
"getBackendName": provider.getBackendName,
"getBackendAddress": provider.getBackendAddress,
"getAttribute": provider.getAttribute,
"getEntryPoints": provider.getEntryPoints,
}
allNodes := []*api.ServiceEntry{}