Avoid code which looks at local files when etcd is configured (#7144)

This situation happens only in gateway nas which supports
etcd based `config.json` to support all FS mode features.

The issue was we would try to migrate something which doesn't
exist when etcd is configured which leads to inconsistent
server configs in memory.

This PR fixes this situation by properly loading config after
initialization, avoiding backend disk config migration to be
done only if etcd is not configured.
This commit is contained in:
Harshavardhana 2019-01-28 13:31:35 -08:00 committed by kannappanr
parent 526546d588
commit 0a28c28a8c
4 changed files with 29 additions and 33 deletions

View File

@ -103,16 +103,14 @@ func readConfigEtcd(ctx context.Context, client *etcd.Client, configFile string)
return nil, errConfigNotFound return nil, errConfigNotFound
} }
// watchConfig - watches for changes on `configFile` on etcd and loads them. // watchConfigEtcd - watches for changes on `configFile` on etcd and loads them.
func watchConfig(objAPI ObjectLayer, configFile string, loadCfgFn func(ObjectLayer) error) { func watchConfigEtcd(objAPI ObjectLayer, configFile string, loadCfgFn func(ObjectLayer) error) {
if globalEtcdClient != nil { ctx, cancel := context.WithTimeout(context.Background(), defaultContextTimeout)
ctx, cancel := context.WithTimeout(context.Background(), defaultContextTimeout) defer cancel()
defer cancel() for watchResp := range globalEtcdClient.Watch(ctx, configFile) {
for watchResp := range globalEtcdClient.Watch(ctx, configFile) { for _, event := range watchResp.Events {
for _, event := range watchResp.Events { if event.IsModify() || event.IsCreate() {
if event.IsModify() || event.IsCreate() { loadCfgFn(objAPI)
loadCfgFn(objAPI)
}
} }
} }
} }

View File

@ -545,19 +545,15 @@ func (s *serverConfig) loadToCachedConfigs() {
globalIsCompressionEnabled = compressionConf.Enabled 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() != "" {
if s.Policy.OPA.URL != nil && s.Policy.OPA.URL.String() != "" { globalPolicyOPA = iampolicy.NewOpa(iampolicy.OpaArgs{
globalPolicyOPA = iampolicy.NewOpa(iampolicy.OpaArgs{ URL: s.Policy.OPA.URL,
URL: s.Policy.OPA.URL, AuthToken: s.Policy.OPA.AuthToken,
AuthToken: s.Policy.OPA.AuthToken, Transport: NewCustomHTTPTransport(),
Transport: NewCustomHTTPTransport(), CloseRespFn: CloseResponse,
CloseRespFn: CloseResponse, })
})
}
} }
} }

View File

@ -157,6 +157,8 @@ func initConfig(objAPI ObjectLayer) error {
return errServerNotInitialized return errServerNotInitialized
} }
configFile := path.Join(minioConfigPrefix, minioConfigFile)
if globalEtcdClient != nil { if globalEtcdClient != nil {
if err := checkConfigEtcd(context.Background(), globalEtcdClient, getConfigFile()); err != nil { if err := checkConfigEtcd(context.Background(), globalEtcdClient, getConfigFile()); err != nil {
if err == errConfigNotFound { if err == errConfigNotFound {
@ -172,6 +174,10 @@ func initConfig(objAPI ObjectLayer) error {
return err return err
} }
} }
// Watch config for changes and reloads them.
go watchConfigEtcd(objAPI, configFile, loadConfig)
} else { } else {
if isFile(getConfigFile()) { if isFile(getConfigFile()) {
if err := migrateConfig(); err != nil { if err := migrateConfig(); err != nil {
@ -184,15 +190,11 @@ func initConfig(objAPI ObjectLayer) error {
if err := migrateConfigToMinioSys(objAPI); err != nil { if err := migrateConfigToMinioSys(objAPI); err != nil {
return err return err
} }
}
configFile := path.Join(minioConfigPrefix, minioConfigFile) // Migrates backend '<export_path>/.minio.sys/config/config.json' to latest version.
if err := migrateMinioSysConfig(objAPI); err != nil {
// Watch config for changes and reloads them in-memory. return err
go watchConfig(objAPI, configFile, loadConfig) }
if err := migrateMinioSysConfig(objAPI); err != nil {
return err
} }
return loadConfig(objAPI) return loadConfig(objAPI)

View File

@ -223,7 +223,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
globalConfigSys = NewConfigSys() globalConfigSys = NewConfigSys()
// Load globalServerConfig from etcd // Load globalServerConfig from etcd
_ = globalConfigSys.Init(newObject) logger.LogIf(context.Background(), globalConfigSys.Init(newObject))
} }
// Load logger subsystem // Load logger subsystem
@ -247,7 +247,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
globalIAMSys = NewIAMSys() globalIAMSys = NewIAMSys()
if enableIAMOps { if enableIAMOps {
// Initialize IAM sys. // Initialize IAM sys.
_ = globalIAMSys.Init(newObject) logger.LogIf(context.Background(), globalIAMSys.Init(newObject))
} }
// Create new policy system. // Create new policy system.
@ -259,7 +259,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
// Create new notification system. // Create new notification system.
globalNotificationSys = NewNotificationSys(globalServerConfig, globalEndpoints) globalNotificationSys = NewNotificationSys(globalServerConfig, globalEndpoints)
if globalEtcdClient != nil && newObject.IsNotificationSupported() { if globalEtcdClient != nil && newObject.IsNotificationSupported() {
_ = globalNotificationSys.Init(newObject) logger.LogIf(context.Background(), globalNotificationSys.Init(newObject))
} }
// Encryption support checks in gateway mode. // Encryption support checks in gateway mode.