Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split consul and consul catalog. #2655

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/traefik/anonymize/anonymize_config_test.go
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/containous/traefik/provider"
"github.com/containous/traefik/provider/boltdb"
"github.com/containous/traefik/provider/consul"
"github.com/containous/traefik/provider/consulcatalog"
"github.com/containous/traefik/provider/docker"
"github.com/containous/traefik/provider/dynamodb"
"github.com/containous/traefik/provider/ecs"
Expand Down Expand Up @@ -333,7 +334,7 @@ func TestDo_globalConfiguration(t *testing.T) {
},
RespectReadinessChecks: true,
}
config.ConsulCatalog = &consul.CatalogProvider{
config.ConsulCatalog = &consulcatalog.Provider{
BaseProvider: provider.BaseProvider{
Watch: true,
Filename: "ConsulCatalog Filename",
Expand Down
3 changes: 2 additions & 1 deletion cmd/traefik/configuration.go
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/containous/traefik/ping"
"github.com/containous/traefik/provider/boltdb"
"github.com/containous/traefik/provider/consul"
"github.com/containous/traefik/provider/consulcatalog"
"github.com/containous/traefik/provider/docker"
"github.com/containous/traefik/provider/dynamodb"
"github.com/containous/traefik/provider/ecs"
Expand Down Expand Up @@ -94,7 +95,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
defaultConsul.Constraints = types.Constraints{}

// default CatalogProvider
var defaultConsulCatalog consul.CatalogProvider
var defaultConsulCatalog consulcatalog.Provider
defaultConsulCatalog.Endpoint = "127.0.0.1:8500"
defaultConsulCatalog.ExposedByDefault = true
defaultConsulCatalog.Constraints = types.Constraints{}
Expand Down
3 changes: 2 additions & 1 deletion configuration/configuration.go
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/containous/traefik/ping"
"github.com/containous/traefik/provider/boltdb"
"github.com/containous/traefik/provider/consul"
"github.com/containous/traefik/provider/consulcatalog"
"github.com/containous/traefik/provider/docker"
"github.com/containous/traefik/provider/dynamodb"
"github.com/containous/traefik/provider/ecs"
Expand Down Expand Up @@ -79,7 +80,7 @@ type GlobalConfiguration struct {
File *file.Provider `description:"Enable File backend with default settings" export:"true"`
Marathon *marathon.Provider `description:"Enable Marathon backend with default settings" export:"true"`
Consul *consul.Provider `description:"Enable Consul backend with default settings" export:"true"`
ConsulCatalog *consul.CatalogProvider `description:"Enable Consul catalog backend with default settings" export:"true"`
ConsulCatalog *consulcatalog.Provider `description:"Enable Consul catalog backend with default settings" export:"true"`
Etcd *etcd.Provider `description:"Enable Etcd backend with default settings" export:"true"`
Zookeeper *zk.Provider `description:"Enable Zookeeper backend with default settings" export:"true"`
Boltdb *boltdb.Provider `description:"Enable Boltdb backend with default settings" export:"true"`
Expand Down
@@ -1,4 +1,4 @@
package consul
package consulcatalog

import (
"errors"
Expand All @@ -22,10 +22,10 @@ const (
DefaultWatchWaitTime = 15 * time.Second
)

var _ provider.Provider = (*CatalogProvider)(nil)
var _ provider.Provider = (*Provider)(nil)

// CatalogProvider holds configurations of the Consul catalog provider.
type CatalogProvider struct {
// Provider holds configurations of the Consul catalog provider.
type Provider struct {
provider.BaseProvider `mapstructure:",squash" export:"true"`
Endpoint string `description:"Consul server endpoint"`
Domain string `description:"Default domain used"`
Expand Down Expand Up @@ -85,7 +85,7 @@ func (a nodeSorter) Less(i int, j int) bool {

// Provide allows the consul catalog provider to provide configurations to traefik
// using the given configuration channel.
func (p *CatalogProvider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints types.Constraints) error {
func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints types.Constraints) error {
config := api.DefaultConfig()
config.Address = p.Endpoint
client, err := api.NewClient(config)
Expand All @@ -112,7 +112,7 @@ func (p *CatalogProvider) Provide(configurationChan chan<- types.ConfigMessage,
return err
}

func (p *CatalogProvider) watch(configurationChan chan<- types.ConfigMessage, stop chan bool) error {
func (p *Provider) watch(configurationChan chan<- types.ConfigMessage, stop chan bool) error {
stopCh := make(chan struct{})
watchCh := make(chan map[string][]string)
errorCh := make(chan error)
Expand Down Expand Up @@ -147,7 +147,7 @@ func (p *CatalogProvider) watch(configurationChan chan<- types.ConfigMessage, st
}
}

func (p *CatalogProvider) watchCatalogServices(stopCh <-chan struct{}, watchCh chan<- map[string][]string, errorCh chan<- error) {
func (p *Provider) watchCatalogServices(stopCh <-chan struct{}, watchCh chan<- map[string][]string, errorCh chan<- error) {
catalog := p.client.Catalog()

safe.Go(func() {
Expand Down Expand Up @@ -216,7 +216,7 @@ func (p *CatalogProvider) watchCatalogServices(stopCh <-chan struct{}, watchCh c
})
}

func (p *CatalogProvider) watchHealthState(stopCh <-chan struct{}, watchCh chan<- map[string][]string, errorCh chan<- error) {
func (p *Provider) watchHealthState(stopCh <-chan struct{}, watchCh chan<- map[string][]string, errorCh chan<- error) {
health := p.client.Health()
catalog := p.client.Catalog()

Expand Down Expand Up @@ -287,7 +287,7 @@ func (p *CatalogProvider) watchHealthState(stopCh <-chan struct{}, watchCh chan<
})
}

func (p *CatalogProvider) getNodes(index map[string][]string) ([]catalogUpdate, error) {
func (p *Provider) getNodes(index map[string][]string) ([]catalogUpdate, error) {
visited := make(map[string]bool)

var nodes []catalogUpdate
Expand Down Expand Up @@ -383,7 +383,7 @@ func getServicePorts(services []*api.CatalogService) []int {
return servicePorts
}

func (p *CatalogProvider) healthyNodes(service string) (catalogUpdate, error) {
func (p *Provider) healthyNodes(service string) (catalogUpdate, error) {
health := p.client.Health()
data, _, err := health.Service(service, "", true, &api.QueryOptions{})
if err != nil {
Expand Down Expand Up @@ -412,7 +412,7 @@ func (p *CatalogProvider) healthyNodes(service string) (catalogUpdate, error) {
}, nil
}

func (p *CatalogProvider) nodeFilter(service string, node *api.ServiceEntry) bool {
func (p *Provider) nodeFilter(service string, node *api.ServiceEntry) bool {
// Filter disabled application.
if !p.isServiceEnabled(node) {
log.Debugf("Filtering disabled Consul service %s", service)
Expand All @@ -429,11 +429,11 @@ func (p *CatalogProvider) nodeFilter(service string, node *api.ServiceEntry) boo
return true
}

func (p *CatalogProvider) isServiceEnabled(node *api.ServiceEntry) bool {
func (p *Provider) isServiceEnabled(node *api.ServiceEntry) bool {
return p.getBoolAttribute(label.SuffixEnable, node.Service.Tags, p.ExposedByDefault)
}

func (p *CatalogProvider) getConstraintTags(tags []string) []string {
func (p *Provider) getConstraintTags(tags []string) []string {
var values []string

prefix := p.getPrefixedName("tags=")
Expand Down