Restrict traefik.toml to static configuration.
This commit is contained in:
parent
f49800e56a
commit
093658836e
78 changed files with 274 additions and 440 deletions
|
@ -149,7 +149,6 @@ func TestDo_globalConfiguration(t *testing.T) {
|
|||
Watch: true,
|
||||
Filename: "file Filename",
|
||||
DebugLogGeneratedTemplate: true,
|
||||
TraefikFile: "",
|
||||
}
|
||||
|
||||
config.Providers.Docker = &docker.Provider{
|
||||
|
|
|
@ -5,17 +5,3 @@ type ResourceLoader interface {
|
|||
// Load populates cmd.Configuration, optionally using args to do so.
|
||||
Load(args []string, cmd *Command) (bool, error)
|
||||
}
|
||||
|
||||
type filenameGetter interface {
|
||||
GetFilename() string
|
||||
}
|
||||
|
||||
// GetConfigFile returns the configuration file corresponding to the first configuration file loader found in ResourceLoader, if any.
|
||||
func GetConfigFile(loaders []ResourceLoader) string {
|
||||
for _, loader := range loaders {
|
||||
if v, ok := loader.(filenameGetter); ok {
|
||||
return v.GetFilename()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
watch = true
|
||||
filename = "foobar"
|
||||
debugLogGeneratedTemplate = true
|
||||
traefikFile = "foobar"
|
||||
[providers.marathon]
|
||||
constraints = "foobar"
|
||||
trace = true
|
||||
|
|
|
@ -192,7 +192,6 @@ func Test_decodeFileToNode_Toml(t *testing.T) {
|
|||
{Name: "debugLogGeneratedTemplate", Value: "true"},
|
||||
{Name: "directory", Value: "foobar"},
|
||||
{Name: "filename", Value: "foobar"},
|
||||
{Name: "traefikFile", Value: "foobar"},
|
||||
{Name: "watch", Value: "true"}}},
|
||||
{Name: "kubernetesCRD",
|
||||
Children: []*parser.Node{
|
||||
|
@ -435,7 +434,6 @@ func Test_decodeFileToNode_Yaml(t *testing.T) {
|
|||
{Name: "debugLogGeneratedTemplate", Value: "true"},
|
||||
{Name: "directory", Value: "foobar"},
|
||||
{Name: "filename", Value: "foobar"},
|
||||
{Name: "traefikFile", Value: "foobar"},
|
||||
{Name: "watch", Value: "true"}}},
|
||||
{Name: "kubernetesCRD",
|
||||
Children: []*parser.Node{
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
watch = true
|
||||
filename = "foobar"
|
||||
debugLogGeneratedTemplate = true
|
||||
traefikFile = "foobar"
|
||||
[providers.marathon]
|
||||
constraints = "foobar"
|
||||
trace = true
|
||||
|
|
|
@ -55,7 +55,6 @@ providers:
|
|||
watch: true
|
||||
filename: foobar
|
||||
debugLogGeneratedTemplate: true
|
||||
traefikFile: foobar
|
||||
marathon:
|
||||
constraints: foobar
|
||||
trace: true
|
||||
|
|
|
@ -149,7 +149,7 @@ func (t *Tracing) SetDefaults() {
|
|||
type Providers struct {
|
||||
ProvidersThrottleDuration types.Duration `description:"Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time." json:"providersThrottleDuration,omitempty" toml:"providersThrottleDuration,omitempty" yaml:"providersThrottleDuration,omitempty" export:"true"`
|
||||
Docker *docker.Provider `description:"Enable Docker backend with default settings." json:"docker,omitempty" toml:"docker,omitempty" yaml:"docker,omitempty" export:"true" label:"allowEmpty"`
|
||||
File *file.Provider `description:"Enable File backend with default settings." json:"file,omitempty" toml:"file,omitempty" yaml:"file,omitempty" export:"true" label:"allowEmpty"`
|
||||
File *file.Provider `description:"Enable File backend with default settings." json:"file,omitempty" toml:"file,omitempty" yaml:"file,omitempty" export:"true"`
|
||||
Marathon *marathon.Provider `description:"Enable Marathon backend with default settings." json:"marathon,omitempty" toml:"marathon,omitempty" yaml:"marathon,omitempty" export:"true" label:"allowEmpty"`
|
||||
KubernetesIngress *ingress.Provider `description:"Enable Kubernetes backend with default settings." json:"kubernetesIngress,omitempty" toml:"kubernetesIngress,omitempty" yaml:"kubernetesIngress,omitempty" export:"true" label:"allowEmpty"`
|
||||
KubernetesCRD *crd.Provider `description:"Enable Kubernetes backend with default settings." json:"kubernetesCRD,omitempty" toml:"kubernetesCRD,omitempty" yaml:"kubernetesCRD,omitempty" export:"true" label:"allowEmpty"`
|
||||
|
@ -159,7 +159,7 @@ type Providers struct {
|
|||
|
||||
// SetEffectiveConfiguration adds missing configuration parameters derived from existing ones.
|
||||
// It also takes care of maintaining backwards compatibility.
|
||||
func (c *Configuration) SetEffectiveConfiguration(configFile string) {
|
||||
func (c *Configuration) SetEffectiveConfiguration() {
|
||||
if len(c.EntryPoints) == 0 {
|
||||
ep := &EntryPoint{Address: ":80"}
|
||||
ep.SetDefaults()
|
||||
|
@ -185,10 +185,6 @@ func (c *Configuration) SetEffectiveConfiguration(configFile string) {
|
|||
}
|
||||
}
|
||||
|
||||
if c.Providers.File != nil {
|
||||
c.Providers.File.TraefikFile = configFile
|
||||
}
|
||||
|
||||
if c.Providers.Rancher != nil {
|
||||
if c.Providers.Rancher.RefreshSeconds <= 0 {
|
||||
c.Providers.Rancher.RefreshSeconds = 15
|
||||
|
|
|
@ -32,7 +32,6 @@ type Provider struct {
|
|||
Watch bool `description:"Watch provider." json:"watch,omitempty" toml:"watch,omitempty" yaml:"watch,omitempty" export:"true"`
|
||||
Filename string `description:"Override default configuration template. For advanced users :)" json:"filename,omitempty" toml:"filename,omitempty" yaml:"filename,omitempty" export:"true"`
|
||||
DebugLogGeneratedTemplate bool `description:"Enable debug logging of generated configuration template." json:"debugLogGeneratedTemplate,omitempty" toml:"debugLogGeneratedTemplate,omitempty" yaml:"debugLogGeneratedTemplate,omitempty" export:"true"`
|
||||
TraefikFile string `description:"-" json:"traefikFile,omitempty" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
// SetDefaults sets the default values.
|
||||
|
@ -64,7 +63,7 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.
|
|||
case len(p.Filename) > 0:
|
||||
watchItem = filepath.Dir(p.Filename)
|
||||
default:
|
||||
watchItem = filepath.Dir(p.TraefikFile)
|
||||
return errors.New("error using file configuration provider, neither filename or directory defined")
|
||||
}
|
||||
|
||||
if err := p.addWatcher(pool, watchItem, configurationChan, p.watcherCallback); err != nil {
|
||||
|
@ -89,11 +88,7 @@ func (p *Provider) BuildConfiguration() (*dynamic.Configuration, error) {
|
|||
return p.loadFileConfig(p.Filename, true)
|
||||
}
|
||||
|
||||
if len(p.TraefikFile) > 0 {
|
||||
return p.loadFileConfig(p.TraefikFile, false)
|
||||
}
|
||||
|
||||
return nil, errors.New("error using file configuration backend, no filename defined")
|
||||
return nil, errors.New("error using file configuration provider, neither filename or directory defined")
|
||||
}
|
||||
|
||||
func (p *Provider) addWatcher(pool *safe.Pool, directory string, configurationChan chan<- dynamic.Message, callback func(chan<- dynamic.Message, fsnotify.Event)) error {
|
||||
|
@ -116,15 +111,8 @@ func (p *Provider) addWatcher(pool *safe.Pool, directory string, configurationCh
|
|||
return
|
||||
case evt := <-watcher.Events:
|
||||
if p.Directory == "" {
|
||||
var filename string
|
||||
if len(p.Filename) > 0 {
|
||||
filename = p.Filename
|
||||
} else {
|
||||
filename = p.TraefikFile
|
||||
}
|
||||
|
||||
_, evtFileName := filepath.Split(evt.Name)
|
||||
_, confFileName := filepath.Split(filename)
|
||||
_, confFileName := filepath.Split(p.Filename)
|
||||
if evtFileName == confFileName {
|
||||
callback(configurationChan, evt)
|
||||
}
|
||||
|
@ -140,11 +128,9 @@ func (p *Provider) addWatcher(pool *safe.Pool, directory string, configurationCh
|
|||
}
|
||||
|
||||
func (p *Provider) watcherCallback(configurationChan chan<- dynamic.Message, event fsnotify.Event) {
|
||||
watchItem := p.TraefikFile
|
||||
watchItem := p.Filename
|
||||
if len(p.Directory) > 0 {
|
||||
watchItem = p.Directory
|
||||
} else if len(p.Filename) > 0 {
|
||||
watchItem = p.Filename
|
||||
}
|
||||
|
||||
logger := log.WithoutContext().WithField(log.ProviderName, providerName)
|
||||
|
|
|
@ -20,7 +20,6 @@ type ProvideTestCase struct {
|
|||
desc string
|
||||
directoryPaths []string
|
||||
filePath string
|
||||
traefikFilePath string
|
||||
expectedNumRouter int
|
||||
expectedNumService int
|
||||
expectedNumTLSConf int
|
||||
|
@ -131,11 +130,6 @@ func TestProvideWithWatch(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if len(test.traefikFilePath) > 0 {
|
||||
err := copyFile(test.traefikFilePath, provider.TraefikFile)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if len(test.directoryPaths) > 0 {
|
||||
for i, filePath := range test.directoryPaths {
|
||||
err := copyFile(filePath, filepath.Join(provider.Directory, strconv.Itoa(i)+filepath.Ext(filePath)))
|
||||
|
@ -181,36 +175,6 @@ func getTestCases() []ProvideTestCase {
|
|||
expectedNumService: 6,
|
||||
expectedNumTLSConf: 5,
|
||||
},
|
||||
{
|
||||
desc: "simple file and a traefik file",
|
||||
filePath: "./fixtures/toml/simple_file_02.toml",
|
||||
traefikFilePath: "./fixtures/toml/simple_traefik_file_01.toml",
|
||||
expectedNumRouter: 4,
|
||||
expectedNumService: 8,
|
||||
expectedNumTLSConf: 4,
|
||||
},
|
||||
{
|
||||
desc: "simple file and a traefik file yaml",
|
||||
filePath: "./fixtures/yaml/simple_file_02.yml",
|
||||
traefikFilePath: "./fixtures/yaml/simple_traefik_file_01.yml",
|
||||
expectedNumRouter: 4,
|
||||
expectedNumService: 8,
|
||||
expectedNumTLSConf: 4,
|
||||
},
|
||||
{
|
||||
desc: "simple traefik file",
|
||||
traefikFilePath: "./fixtures/toml/simple_traefik_file_02.toml",
|
||||
expectedNumRouter: 2,
|
||||
expectedNumService: 3,
|
||||
expectedNumTLSConf: 4,
|
||||
},
|
||||
{
|
||||
desc: "simple traefik file yaml",
|
||||
traefikFilePath: "./fixtures/yaml/simple_traefik_file_02.yml",
|
||||
expectedNumRouter: 2,
|
||||
expectedNumService: 3,
|
||||
expectedNumTLSConf: 4,
|
||||
},
|
||||
{
|
||||
desc: "template file",
|
||||
filePath: "./fixtures/toml/template_file.toml",
|
||||
|
@ -221,13 +185,6 @@ func getTestCases() []ProvideTestCase {
|
|||
filePath: "./fixtures/yaml/template_file.yml",
|
||||
expectedNumRouter: 20,
|
||||
},
|
||||
{
|
||||
desc: "simple traefik file with templating",
|
||||
traefikFilePath: "./fixtures/toml/simple_traefik_file_with_templating.toml",
|
||||
expectedNumRouter: 2,
|
||||
expectedNumService: 3,
|
||||
expectedNumTLSConf: 4,
|
||||
},
|
||||
{
|
||||
desc: "simple directory",
|
||||
directoryPaths: []string{
|
||||
|
@ -304,21 +261,6 @@ func createProvider(t *testing.T, test ProvideTestCase, watch bool) (*Provider,
|
|||
provider.Filename = file.Name()
|
||||
}
|
||||
|
||||
if len(test.traefikFilePath) > 0 {
|
||||
var file *os.File
|
||||
if watch {
|
||||
var err error
|
||||
file, err = ioutil.TempFile(tempDir, "temp*"+filepath.Ext(test.traefikFilePath))
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
var err error
|
||||
file, err = createTempFile(test.traefikFilePath, tempDir)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
provider.TraefikFile = file.Name()
|
||||
}
|
||||
|
||||
return provider, func() {
|
||||
os.RemoveAll(tempDir)
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
[log]
|
||||
level = "DEBUG"
|
|
@ -1,44 +0,0 @@
|
|||
[providers.file]
|
||||
|
||||
## dynamic configuration ##
|
||||
|
||||
[http.routers]
|
||||
|
||||
[http.routers."router1"]
|
||||
service = "application-1"
|
||||
|
||||
[http.routers."router2"]
|
||||
service = "application-2"
|
||||
|
||||
|
||||
[http.services]
|
||||
|
||||
[http.services.application-1.loadBalancer]
|
||||
[[http.services.application-1.loadBalancer.servers]]
|
||||
url = "http://172.17.0.1:80"
|
||||
|
||||
[http.services.application-2.loadBalancer]
|
||||
[[http.services.application-2.loadBalancer.servers]]
|
||||
url = "http://172.17.0.2:80"
|
||||
|
||||
[http.services.application-3.loadBalancer]
|
||||
[[http.services.application-3.loadBalancer.servers]]
|
||||
url = "http://172.17.0.3:80"
|
||||
|
||||
[tls]
|
||||
|
||||
[[tls.certificates]]
|
||||
certFile = "integration/fixtures/https/snitest1.com.cert"
|
||||
keyFile = "integration/fixtures/https/snitest1.com.key"
|
||||
|
||||
[[tls.certificates]]
|
||||
certFile = "integration/fixtures/https/snitest2.com.cert"
|
||||
keyFile = "integration/fixtures/https/snitest2.com.key"
|
||||
|
||||
[[tls.certificates]]
|
||||
certFile = "integration/fixtures/https/snitest3.com.cert"
|
||||
keyFile = "integration/fixtures/https/snitest3.com.key"
|
||||
|
||||
[[tls.certificates]]
|
||||
certFile = "integration/fixtures/https/snitest4.com.cert"
|
||||
keyFile = "integration/fixtures/https/snitest4.com.key"
|
|
@ -1,45 +0,0 @@
|
|||
temp="{{ getTag \"test\" }}"
|
||||
|
||||
[providers.file]
|
||||
|
||||
## dynamic configuration ##
|
||||
|
||||
[http.routers]
|
||||
|
||||
[http.routers."router1"]
|
||||
service = "application-1"
|
||||
|
||||
[http.routers."router2"]
|
||||
service = "application-2"
|
||||
|
||||
[http.services]
|
||||
|
||||
[http.services.application-1.loadBalancer]
|
||||
[[http.services.application-1.loadBalancer.servers]]
|
||||
url = "http://172.17.0.1:80"
|
||||
|
||||
[http.services.application-2.loadBalancer]
|
||||
[[http.services.application-2.loadBalancer.servers]]
|
||||
url = "http://172.17.0.2:80"
|
||||
|
||||
[http.services.application-3.loadBalancer]
|
||||
[[http.services.application-3.loadBalancer.servers]]
|
||||
url = "http://172.17.0.3:80"
|
||||
|
||||
[tls]
|
||||
|
||||
[[tls.certificates]]
|
||||
certFile = "integration/fixtures/https/snitest1.com.cert"
|
||||
keyFile = "integration/fixtures/https/snitest1.com.key"
|
||||
|
||||
[[tls.certificates]]
|
||||
certFile = "integration/fixtures/https/snitest2.com.cert"
|
||||
keyFile = "integration/fixtures/https/snitest2.com.key"
|
||||
|
||||
[[tls.certificates]]
|
||||
certFile = "integration/fixtures/https/snitest3.com.cert"
|
||||
keyFile = "integration/fixtures/https/snitest3.com.key"
|
||||
|
||||
[[tls.certificates]]
|
||||
certFile = "integration/fixtures/https/snitest4.com.cert"
|
||||
keyFile = "integration/fixtures/https/snitest4.com.key"
|
|
@ -1,2 +0,0 @@
|
|||
log:
|
||||
level: DEBUG
|
|
@ -1,32 +0,0 @@
|
|||
providers:
|
||||
file: {}
|
||||
http:
|
||||
routers:
|
||||
router1:
|
||||
service: application-1
|
||||
router2:
|
||||
service: application-2
|
||||
services:
|
||||
application-1:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- url: 'http://172.17.0.1:80'
|
||||
application-2:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- url: 'http://172.17.0.2:80'
|
||||
application-3:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- url: 'http://172.17.0.3:80'
|
||||
|
||||
tls:
|
||||
certificates:
|
||||
- certFile: integration/fixtures/https/snitest1.com.cert
|
||||
keyFile: integration/fixtures/https/snitest1.com.key
|
||||
- certFile: integration/fixtures/https/snitest2.com.cert
|
||||
keyFile: integration/fixtures/https/snitest2.com.key
|
||||
- certFile: integration/fixtures/https/snitest3.com.cert
|
||||
keyFile: integration/fixtures/https/snitest3.com.key
|
||||
- certFile: integration/fixtures/https/snitest4.com.cert
|
||||
keyFile: integration/fixtures/https/snitest4.com.key
|
Loading…
Add table
Add a link
Reference in a new issue