Change the loading resource order
This commit is contained in:
parent
dd62051e6c
commit
4d44ab9628
4 changed files with 9 additions and 3 deletions
|
@ -44,7 +44,7 @@ func main() {
|
||||||
// traefik config inits
|
// traefik config inits
|
||||||
tConfig := cmd.NewTraefikConfiguration()
|
tConfig := cmd.NewTraefikConfiguration()
|
||||||
|
|
||||||
loaders := []cli.ResourceLoader{&cli.FileLoader{}, &cli.EnvLoader{}, &cli.FlagLoader{}}
|
loaders := []cli.ResourceLoader{&cli.FileLoader{}, &cli.FlagLoader{}, &cli.EnvLoader{}}
|
||||||
|
|
||||||
cmdTraefik := &cli.Command{
|
cmdTraefik := &cli.Command{
|
||||||
Name: "traefik",
|
Name: "traefik",
|
||||||
|
|
|
@ -36,8 +36,8 @@ Traefik gets its _dynamic configuration_ from [providers](../providers/overview.
|
||||||
There are three different, mutually exclusive, ways to define static configuration options in Traefik:
|
There are three different, mutually exclusive, ways to define static configuration options in Traefik:
|
||||||
|
|
||||||
- In a configuration file
|
- In a configuration file
|
||||||
- As environment variables
|
|
||||||
- In the command-line arguments
|
- In the command-line arguments
|
||||||
|
- As environment variables
|
||||||
|
|
||||||
These ways are evaluated in the order listed above.
|
These ways are evaluated in the order listed above.
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cli
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config/env"
|
"github.com/containous/traefik/pkg/config/env"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
|
@ -19,6 +20,7 @@ func (e *EnvLoader) Load(_ []string, cmd *Command) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := env.Decode(vars, env.DefaultNamePrefix, cmd.Configuration); err != nil {
|
if err := env.Decode(vars, env.DefaultNamePrefix, cmd.Configuration); err != nil {
|
||||||
|
log.WithoutContext().Debug("environment variables", strings.Join(vars, ", "))
|
||||||
return false, fmt.Errorf("failed to decode configuration from environment variables: %v ", err)
|
return false, fmt.Errorf("failed to decode configuration from environment variables: %v ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ type FlagLoader struct{}
|
||||||
|
|
||||||
// Load loads the command's configuration from flag arguments.
|
// Load loads the command's configuration from flag arguments.
|
||||||
func (*FlagLoader) Load(args []string, cmd *Command) (bool, error) {
|
func (*FlagLoader) Load(args []string, cmd *Command) (bool, error) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := flag.Decode(args, cmd.Configuration); err != nil {
|
if err := flag.Decode(args, cmd.Configuration); err != nil {
|
||||||
return false, fmt.Errorf("failed to decode configuration from flags: %v", err)
|
return false, fmt.Errorf("failed to decode configuration from flags: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue