From 725172e13bb757a8b63ca26536b8b023b24351b8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 21 Dec 2019 22:35:50 -0800 Subject: [PATCH] fix: Do not need safe-mode for unreachable targets upon restart (#8686) --- cmd/config-current.go | 5 +++++ cmd/globals.go | 8 +++++--- cmd/notification.go | 24 ++++++++---------------- cmd/server-main.go | 4 ---- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/cmd/config-current.go b/cmd/config-current.go index 1d4b48c7b..7594d9f6b 100644 --- a/cmd/config-current.go +++ b/cmd/config-current.go @@ -415,6 +415,11 @@ func lookupConfigs(s config.Config) { logger.AddAuditTarget(http.New(l.Endpoint, loggerUserAgent, string(logger.All), NewCustomHTTPTransport())) } } + + globalConfigTargetList, err = notify.GetNotificationTargets(s, GlobalServiceDoneCh, NewCustomHTTPTransport()) + if err != nil { + logger.LogIf(ctx, fmt.Errorf("Unable to initialize notification target(s): %w", err)) + } } // Help - return sub-system level help diff --git a/cmd/globals.go b/cmd/globals.go index 8c11ffdb4..9740a963c 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -36,6 +36,7 @@ import ( xhttp "github.com/minio/minio/cmd/http" "github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/certs" + "github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/pubsub" ) @@ -137,9 +138,10 @@ var ( // globalConfigSys server config system. globalConfigSys *ConfigSys - globalNotificationSys *NotificationSys - globalPolicySys *PolicySys - globalIAMSys *IAMSys + globalNotificationSys *NotificationSys + globalConfigTargetList *event.TargetList + globalPolicySys *PolicySys + globalIAMSys *IAMSys globalLifecycleSys *LifecycleSys diff --git a/cmd/notification.go b/cmd/notification.go index ab6e002d2..0be2fbc38 100644 --- a/cmd/notification.go +++ b/cmd/notification.go @@ -30,8 +30,6 @@ import ( "time" "github.com/klauspost/compress/zip" - "github.com/minio/minio/cmd/config" - "github.com/minio/minio/cmd/config/notify" "github.com/minio/minio/cmd/crypto" "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/event" @@ -589,20 +587,6 @@ func (sys *NotificationSys) PutBucketNotification(ctx context.Context, bucketNam }() } -// AddNotificationTargetsFromConfig - adds notification targets from server config. -func (sys *NotificationSys) AddNotificationTargetsFromConfig(cfg config.Config) error { - targetList, err := notify.GetNotificationTargets(cfg, GlobalServiceDoneCh, NewCustomHTTPTransport()) - if err != nil { - return err - } - for _, target := range targetList.Targets() { - if err = sys.targetList.Add(target); err != nil { - return err - } - } - return nil -} - // AddRemoteTarget - adds event rules map, HTTP/PeerRPC client target to bucket name. func (sys *NotificationSys) AddRemoteTarget(bucketName string, target event.Target, rulesMap event.RulesMap) error { if err := sys.targetList.Add(target); err != nil { @@ -718,6 +702,14 @@ func (sys *NotificationSys) Init(buckets []BucketInfo, objAPI ObjectLayer) error return nil } + if globalConfigTargetList != nil { + for _, target := range globalConfigTargetList.Targets() { + if err := sys.targetList.Add(target); err != nil { + return err + } + } + } + doneCh := make(chan struct{}) defer close(doneCh) diff --git a/cmd/server-main.go b/cmd/server-main.go index ec57753f1..531ff5b43 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -227,10 +227,6 @@ func initAllSubsystems(buckets []BucketInfo, newObject ObjectLayer) (err error) return fmt.Errorf("Unable to initialize config system: %w", err) } - if err = globalNotificationSys.AddNotificationTargetsFromConfig(globalServerConfig); err != nil { - return fmt.Errorf("Unable to initialize notification target(s) from config: %w", err) - } - if globalEtcdClient != nil { // **** WARNING **** // Migrating to encrypted backend on etcd should happen before initialization of