fix: initialize config once per startup (#9851)

master
Harshavardhana 5 years ago committed by GitHub
parent 3ba4804d6c
commit f5e1b3d09e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      cmd/config-current.go
  2. 4
      cmd/gateway-main.go

@ -311,8 +311,6 @@ func validateConfig(s config.Config) error {
globalNotificationSys.ConfiguredTargetIDs())
}
var syncEtcdOnce sync.Once
func lookupConfigs(s config.Config) {
ctx := GlobalContext
@ -335,16 +333,30 @@ func lookupConfigs(s config.Config) {
}
if etcdCfg.Enabled {
syncEtcdOnce.Do(func() {
globalEtcdClient, err = etcd.New(etcdCfg)
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 {
globalDNSConfig, err = dns.NewCoreDNS(etcdCfg.Config,
dns.DomainNames(globalDomainNames),
dns.DomainIPs(globalDomainIPs),
dns.DomainPort(globalMinioPort),
dns.CoreDNSPath(etcdCfg.CoreDNSPath),
)
if err != nil {
if globalIsGateway {
logger.FatalIf(err, "Unable to initialize etcd config")
logger.FatalIf(err, "Unable to initialize DNS config")
} else {
logger.LogIf(ctx, fmt.Errorf("Unable to initialize etcd config: %w", err))
logger.LogIf(ctx, fmt.Errorf("Unable to initialize DNS config for %s: %w",
globalDomainNames, err))
}
}
})
}
}
// Bucket federation is 'true' only when IAM assets are not namespaced
@ -354,19 +366,6 @@ func lookupConfigs(s config.Config) {
// but not federation.
globalBucketFederation = etcdCfg.PathPrefix == "" && etcdCfg.Enabled
if len(globalDomainNames) != 0 && !globalDomainIPs.IsEmpty() && globalEtcdClient != nil {
globalDNSConfig, err = dns.NewCoreDNS(etcdCfg.Config,
dns.DomainNames(globalDomainNames),
dns.DomainIPs(globalDomainIPs),
dns.DomainPort(globalMinioPort),
dns.CoreDNSPath(etcdCfg.CoreDNSPath),
)
if err != nil {
logger.LogIf(ctx, fmt.Errorf("Unable to initialize DNS config for %s: %w",
globalDomainNames, err))
}
}
globalServerRegion, err = config.LookupRegion(s[config.RegionSubSys][config.Default])
if err != nil {
logger.LogIf(ctx, fmt.Errorf("Invalid region configuration: %w", err))
@ -571,6 +570,8 @@ 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 {
@ -578,7 +579,9 @@ func newSrvConfig(objAPI ObjectLayer) error {
srvCfg := newServerConfig()
// Override any values from ENVs.
lookupConfigs(srvCfg)
lookupConfigOnce.Do(func() {
lookupConfigs(srvCfg)
})
// hold the mutex lock before a new config is assigned.
globalServerConfigMu.Lock()
@ -602,7 +605,9 @@ func loadConfig(objAPI ObjectLayer) error {
}
// Override any values from ENVs.
lookupConfigs(srvCfg)
lookupConfigOnce.Do(func() {
lookupConfigs(srvCfg)
})
// hold the mutex lock before a new config is assigned.
globalServerConfigMu.Lock()

@ -162,7 +162,9 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
srvCfg := newServerConfig()
// Override any values from ENVs.
lookupConfigs(srvCfg)
lookupConfigOnce.Do(func() {
lookupConfigs(srvCfg)
})
// hold the mutex lock before a new config is assigned.
globalServerConfigMu.Lock()

Loading…
Cancel
Save