From a79cd3c7a491bdddf8e20fbde3fece03394e49a3 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 12 Apr 2021 02:07:35 -0500 Subject: [PATCH] correct providers order --- app/main.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/main.go b/app/main.go index 690faaf..869d4df 100644 --- a/app/main.go +++ b/app/main.go @@ -8,6 +8,7 @@ import ( "os" "os/signal" "runtime" + "strings" "syscall" "time" @@ -56,6 +57,7 @@ var opts struct { Host string `long:"host" env:"HOST" default:"unix:///var/run/docker.sock" description:"docker host"` Network string `long:"network" env:"NETWORK" default:"" description:"docker network"` Excluded []string `long:"exclude" env:"EXCLUDE" description:"excluded containers" env-delim:","` + AutoAPI bool `long:"auto" env:"AUTO" description:"enable automatic routing (without labels)"` } `group:"docker" namespace:"docker" env-namespace:"DOCKER"` File struct { @@ -143,9 +145,20 @@ func main() { } } +// make all providers. the order is matter, defines which provider will have priority in case of conflicting rules +// static first, file second and docker the last one func makeProviders() ([]discovery.Provider, error) { var res []discovery.Provider + if opts.Static.Enabled { + var msgs []string + for _, rule := range opts.Static.Rules { + msgs = append(msgs, "\""+rule+"\"") + } + log.Printf("[DEBUG] inject static rules: %s", strings.Join(msgs, " ")) + res = append(res, &provider.Static{Rules: opts.Static.Rules}) + } + if opts.File.Enabled { res = append(res, &provider.File{ FileName: opts.File.Name, @@ -162,10 +175,6 @@ func makeProviders() ([]discovery.Provider, error) { res = append(res, &provider.Docker{DockerClient: client, Excludes: opts.Docker.Excluded, Network: opts.Docker.Network}) } - if opts.Static.Enabled { - res = append(res, &provider.Static{Rules: opts.Static.Rules}) - } - if len(res) == 0 && opts.Assets.Location == "" { return nil, errors.Errorf("no providers enabled") }