From fa13fe21840853010f13058d776c4d43b65914da Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 18 Jun 2020 17:31:56 -0700 Subject: [PATCH] allow loading some from config and some values from ENVs (#9872) A regression perhaps introduced in #9851 --- cmd/config-current.go | 27 ++++++++++++--------------- cmd/config/etcd/dns/etcd_dns.go | 5 +++++ cmd/gateway-main.go | 4 +--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/config-current.go b/cmd/config-current.go index 0d5176883..5a591228f 100644 --- a/cmd/config-current.go +++ b/cmd/config-current.go @@ -333,15 +333,18 @@ func lookupConfigs(s config.Config) { } if etcdCfg.Enabled { - globalEtcdClient, err = etcd.New(etcdCfg) - if err != nil { - if globalIsGateway { - logger.FatalIf(err, "Unable to initialize etcd config") - } else { - logger.LogIf(ctx, fmt.Errorf("Unable to initialize etcd config: %w", err)) + if globalEtcdClient == nil { + globalEtcdClient, err = etcd.New(etcdCfg) + if err != nil { + if globalIsGateway { + logger.FatalIf(err, "Unable to initialize etcd config") + } else { + logger.LogIf(ctx, fmt.Errorf("Unable to initialize etcd config: %w", err)) + } } } - if len(globalDomainNames) != 0 && !globalDomainIPs.IsEmpty() && globalEtcdClient != nil { + + if len(globalDomainNames) != 0 && !globalDomainIPs.IsEmpty() && globalEtcdClient != nil && globalDNSConfig == nil { globalDNSConfig, err = dns.NewCoreDNS(etcdCfg.Config, dns.DomainNames(globalDomainNames), dns.DomainIPs(globalDomainIPs), @@ -570,8 +573,6 @@ func newServerConfig() config.Config { return config.New() } -var lookupConfigOnce sync.Once - // newSrvConfig - initialize a new server config, saves env parameters if // found, otherwise use default parameters func newSrvConfig(objAPI ObjectLayer) error { @@ -579,9 +580,7 @@ func newSrvConfig(objAPI ObjectLayer) error { srvCfg := newServerConfig() // Override any values from ENVs. - lookupConfigOnce.Do(func() { - lookupConfigs(srvCfg) - }) + lookupConfigs(srvCfg) // hold the mutex lock before a new config is assigned. globalServerConfigMu.Lock() @@ -605,9 +604,7 @@ func loadConfig(objAPI ObjectLayer) error { } // Override any values from ENVs. - lookupConfigOnce.Do(func() { - lookupConfigs(srvCfg) - }) + lookupConfigs(srvCfg) // hold the mutex lock before a new config is assigned. globalServerConfigMu.Lock() diff --git a/cmd/config/etcd/dns/etcd_dns.go b/cmd/config/etcd/dns/etcd_dns.go index 094536008..ee151d23c 100644 --- a/cmd/config/etcd/dns/etcd_dns.go +++ b/cmd/config/etcd/dns/etcd_dns.go @@ -47,6 +47,11 @@ func newCoreDNSMsg(ip string, port string, ttl uint32, t time.Time) ([]byte, err }) } +// Close closes the internal etcd client and cannot be used further +func (c *CoreDNS) Close() { + c.etcdClient.Close() +} + // List - Retrieves list of DNS entries for the domain. func (c *CoreDNS) List() (map[string][]SrvRecord, error) { var srvRecords = map[string][]SrvRecord{} diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index f99454cad..1eb9fb2c2 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -162,9 +162,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { srvCfg := newServerConfig() // Override any values from ENVs. - lookupConfigOnce.Do(func() { - lookupConfigs(srvCfg) - }) + lookupConfigs(srvCfg) // hold the mutex lock before a new config is assigned. globalServerConfigMu.Lock()