diff --git a/cmd/config-common.go b/cmd/config-common.go index 397d9b116..cf597cd3d 100644 --- a/cmd/config-common.go +++ b/cmd/config-common.go @@ -103,16 +103,14 @@ func readConfigEtcd(ctx context.Context, client *etcd.Client, configFile string) return nil, errConfigNotFound } -// watchConfig - watches for changes on `configFile` on etcd and loads them. -func watchConfig(objAPI ObjectLayer, configFile string, loadCfgFn func(ObjectLayer) error) { - if globalEtcdClient != nil { - ctx, cancel := context.WithTimeout(context.Background(), defaultContextTimeout) - defer cancel() - for watchResp := range globalEtcdClient.Watch(ctx, configFile) { - for _, event := range watchResp.Events { - if event.IsModify() || event.IsCreate() { - loadCfgFn(objAPI) - } +// watchConfigEtcd - watches for changes on `configFile` on etcd and loads them. +func watchConfigEtcd(objAPI ObjectLayer, configFile string, loadCfgFn func(ObjectLayer) error) { + ctx, cancel := context.WithTimeout(context.Background(), defaultContextTimeout) + defer cancel() + for watchResp := range globalEtcdClient.Watch(ctx, configFile) { + for _, event := range watchResp.Events { + if event.IsModify() || event.IsCreate() { + loadCfgFn(objAPI) } } } diff --git a/cmd/config-current.go b/cmd/config-current.go index 8da7a28b5..89172b0e8 100644 --- a/cmd/config-current.go +++ b/cmd/config-current.go @@ -545,19 +545,15 @@ func (s *serverConfig) loadToCachedConfigs() { globalIsCompressionEnabled = compressionConf.Enabled } - if globalIAMValidators == nil { - globalIAMValidators = getAuthValidators(s) - } + globalIAMValidators = getAuthValidators(s) - if globalPolicyOPA == nil { - if s.Policy.OPA.URL != nil && s.Policy.OPA.URL.String() != "" { - globalPolicyOPA = iampolicy.NewOpa(iampolicy.OpaArgs{ - URL: s.Policy.OPA.URL, - AuthToken: s.Policy.OPA.AuthToken, - Transport: NewCustomHTTPTransport(), - CloseRespFn: CloseResponse, - }) - } + if s.Policy.OPA.URL != nil && s.Policy.OPA.URL.String() != "" { + globalPolicyOPA = iampolicy.NewOpa(iampolicy.OpaArgs{ + URL: s.Policy.OPA.URL, + AuthToken: s.Policy.OPA.AuthToken, + Transport: NewCustomHTTPTransport(), + CloseRespFn: CloseResponse, + }) } } diff --git a/cmd/config.go b/cmd/config.go index a6d43c63a..bfc92c0ca 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -157,6 +157,8 @@ func initConfig(objAPI ObjectLayer) error { return errServerNotInitialized } + configFile := path.Join(minioConfigPrefix, minioConfigFile) + if globalEtcdClient != nil { if err := checkConfigEtcd(context.Background(), globalEtcdClient, getConfigFile()); err != nil { if err == errConfigNotFound { @@ -172,6 +174,10 @@ func initConfig(objAPI ObjectLayer) error { return err } } + + // Watch config for changes and reloads them. + go watchConfigEtcd(objAPI, configFile, loadConfig) + } else { if isFile(getConfigFile()) { if err := migrateConfig(); err != nil { @@ -184,15 +190,11 @@ func initConfig(objAPI ObjectLayer) error { if err := migrateConfigToMinioSys(objAPI); err != nil { return err } - } - configFile := path.Join(minioConfigPrefix, minioConfigFile) - - // Watch config for changes and reloads them in-memory. - go watchConfig(objAPI, configFile, loadConfig) - - if err := migrateMinioSysConfig(objAPI); err != nil { - return err + // Migrates backend '/.minio.sys/config/config.json' to latest version. + if err := migrateMinioSysConfig(objAPI); err != nil { + return err + } } return loadConfig(objAPI) diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index 43cb15f0a..860e96920 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -223,7 +223,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { globalConfigSys = NewConfigSys() // Load globalServerConfig from etcd - _ = globalConfigSys.Init(newObject) + logger.LogIf(context.Background(), globalConfigSys.Init(newObject)) } // Load logger subsystem @@ -247,7 +247,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { globalIAMSys = NewIAMSys() if enableIAMOps { // Initialize IAM sys. - _ = globalIAMSys.Init(newObject) + logger.LogIf(context.Background(), globalIAMSys.Init(newObject)) } // Create new policy system. @@ -259,7 +259,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { // Create new notification system. globalNotificationSys = NewNotificationSys(globalServerConfig, globalEndpoints) if globalEtcdClient != nil && newObject.IsNotificationSupported() { - _ = globalNotificationSys.Init(newObject) + logger.LogIf(context.Background(), globalNotificationSys.Init(newObject)) } // Encryption support checks in gateway mode.