From 39e8e4f4aabe201bf11cdeff4618d6cd4355f160 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 12 Dec 2019 17:02:14 -0800 Subject: [PATCH] Allow empty target KVS for notification targets (#8644) This is allowed with enable=off arg value --- cmd/config/config.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/config/config.go b/cmd/config/config.go index 55638f9de..de0dabdcf 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -620,8 +620,8 @@ func (c Config) SetKVS(s string, defaultKVS map[string]KVS) error { _, ok := kvs.Lookup(Enable) // Check if state is required - _, defaultOk := defaultKVS[subSys].Lookup(Enable) - if !ok && defaultOk { + _, enableRequired := defaultKVS[subSys].Lookup(Enable) + if !ok && enableRequired { // implicit state "on" if not specified. kvs.Set(Enable, EnableOn) } @@ -646,8 +646,19 @@ func (c Config) SetKVS(s string, defaultKVS map[string]KVS) error { hkvs := HelpSubSysMap[subSys] for _, hkv := range hkvs { + var enabled bool + if enableRequired { + enabled = currKVS.Get(Enable) == EnableOn + } else { + // when enable arg is not required + // then it is implicit on for the sub-system. + enabled = true + } v, _ := currKVS.Lookup(hkv.Key) - if v == "" && !hkv.Optional { + if v == "" && !hkv.Optional && enabled { + // Return error only if the + // key is enabled, for state=off + // let it be empty. return Errorf(SafeModeKind, "'%s' is not optional for '%s' sub-system, please check '%s' documentation", hkv.Key, subSys, subSys)