New static configuration loading system.

Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
This commit is contained in:
Ludovic Fernandez 2019-06-17 11:48:05 +02:00 committed by Traefiker Bot
parent d18edd6f77
commit 8d7eccad5d
165 changed files with 10894 additions and 6076 deletions

View file

@ -8,9 +8,9 @@ import (
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/label"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider"
"github.com/containous/traefik/pkg/provider/label"
"github.com/docker/go-connections/nat"
)

View file

@ -339,7 +339,7 @@ func Test_buildConfiguration(t *testing.T) {
testCases := []struct {
desc string
containers []dockerData
constraints types.Constraints
constraints []*types.Constraint
expected *config.Configuration
}{
{
@ -1924,11 +1924,11 @@ func Test_buildConfiguration(t *testing.T) {
},
},
},
constraints: types.Constraints{
&types.Constraint{
constraints: []*types.Constraint{
{
Key: "tag",
MustMatch: true,
Regex: "bar",
Value: "bar",
},
},
expected: &config.Configuration{
@ -1965,11 +1965,11 @@ func Test_buildConfiguration(t *testing.T) {
},
},
},
constraints: types.Constraints{
&types.Constraint{
constraints: []*types.Constraint{
{
Key: "tag",
MustMatch: true,
Regex: "foo",
Value: "foo",
},
},
expected: &config.Configuration{

View file

@ -45,19 +45,29 @@ var _ provider.Provider = (*Provider)(nil)
// Provider holds configurations of the provider.
type Provider struct {
provider.Constrainer `mapstructure:",squash" export:"true"`
Watch bool `description:"Watch provider" export:"true"`
Endpoint string `description:"Docker server endpoint. Can be a tcp or a unix socket endpoint"`
DefaultRule string `description:"Default rule"`
TLS *types.ClientTLS `description:"Enable Docker TLS support" export:"true"`
ExposedByDefault bool `description:"Expose containers by default" export:"true"`
UseBindPortIP bool `description:"Use the ip address from the bound port, rather than from the inner network" export:"true"`
SwarmMode bool `description:"Use Docker on Swarm Mode" export:"true"`
Network string `description:"Default Docker network used" export:"true"`
SwarmModeRefreshSeconds int `description:"Polling interval for swarm mode (in seconds)" export:"true"`
provider.Constrainer `description:"List of constraints used to filter out some containers." export:"true"`
Watch bool `description:"Watch provider." export:"true"`
Endpoint string `description:"Docker server endpoint. Can be a tcp or a unix socket endpoint."`
DefaultRule string `description:"Default rule."`
TLS *types.ClientTLS `description:"Enable Docker TLS support." export:"true"`
ExposedByDefault bool `description:"Expose containers by default." export:"true"`
UseBindPortIP bool `description:"Use the ip address from the bound port, rather than from the inner network." export:"true"`
SwarmMode bool `description:"Use Docker on Swarm Mode." export:"true"`
Network string `description:"Default Docker network used." export:"true"`
SwarmModeRefreshSeconds types.Duration `description:"Polling interval for swarm mode." export:"true"`
defaultRuleTpl *template.Template
}
// SetDefaults sets the default values.
func (p *Provider) SetDefaults() {
p.Watch = true
p.ExposedByDefault = true
p.Endpoint = "unix:///var/run/docker.sock"
p.SwarmMode = false
p.SwarmModeRefreshSeconds = types.Duration(15 * time.Second)
p.DefaultRule = DefaultTemplateRule
}
// Init the provider.
func (p *Provider) Init() error {
defaultRuleTpl, err := provider.MakeDefaultRuleTemplate(p.DefaultRule, nil)
@ -184,7 +194,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
if p.SwarmMode {
errChan := make(chan error)
// TODO: This need to be change. Linked to Swarm events docker/docker#23827
ticker := time.NewTicker(time.Second * time.Duration(p.SwarmModeRefreshSeconds))
ticker := time.NewTicker(time.Duration(p.SwarmModeRefreshSeconds))
pool.GoCtx(func(ctx context.Context) {
ctx = log.With(ctx, log.Str(log.ProviderName, "docker"))

View file

@ -3,7 +3,7 @@ package docker
import (
"fmt"
"github.com/containous/traefik/pkg/provider/label"
"github.com/containous/traefik/pkg/config/label"
)
const (