From d744865dc61b9a7fddecd5c4c66212d53bb280a8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 25 Jul 2019 17:41:25 -0700 Subject: [PATCH] Enable config for NAS gateway mode (#7948) Starting with #7751 we don't store config in etcd anymore, allow NAS to honor config on disk. --- cmd/config.go | 20 ++++++++++++++++++++ cmd/gateway-main.go | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/config.go b/cmd/config.go index e9948540f..e6be1d82e 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -23,6 +23,7 @@ import ( "path" "runtime" "strings" + "time" "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/quick" @@ -101,6 +102,25 @@ func (sys *ConfigSys) Load(objAPI ObjectLayer) error { return sys.Init(objAPI) } +// WatchConfigNASDisk - watches nas disk on periodic basis. +func (sys *ConfigSys) WatchConfigNASDisk(objAPI ObjectLayer) { + configInterval := globalRefreshIAMInterval + watchDisk := func() { + ticker := time.NewTicker(configInterval) + defer ticker.Stop() + for { + select { + case <-GlobalServiceDoneCh: + return + case <-ticker.C: + loadConfig(objAPI) + } + } + } + // Refresh configSys in background for NAS gateway. + go watchDisk() +} + // Init - initializes config system from config.json. func (sys *ConfigSys) Init(objAPI ObjectLayer) error { if objAPI == nil { diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index 67ca141f4..c17dcd30d 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -158,7 +158,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { registerSTSRouter(router) } - enableConfigOps := globalEtcdClient != nil && gatewayName == "nas" + enableConfigOps := gatewayName == "nas" enableIAMOps := globalEtcdClient != nil // Enable IAM admin APIs if etcd is enabled, if not just enable basic @@ -236,6 +236,10 @@ func StartGateway(ctx *cli.Context, gw Gateway) { // Load globalServerConfig from etcd logger.LogIf(context.Background(), globalConfigSys.Init(newObject)) + + // Start watching disk for reloading config, this + // is only enabled for "NAS" gateway. + globalConfigSys.WatchConfigNASDisk(newObject) } // Load logger subsystem