From e9d27aef5c55505777f3595da56071a24ccc00fe Mon Sep 17 00:00:00 2001 From: Shireesh Anjal <355479+anjalshireesh@users.noreply.github.com> Date: Fri, 3 Jun 2022 22:54:25 +0530 Subject: [PATCH] fix: callhome get error when subnet hook not set (#4089) When there is no SUBNET webhook configured in the cluster (which is the default state), the `mc support callhome get` command fails as it tries to fetch the `logger_webhook:subnet` setting which doesn't exist. Fixed by ignoring the specific error that says the sub-system target doesn't exist, and printing `logs=off` in such cases. --- cmd/subnet-utils.go | 22 +++++++++++++++------- cmd/support-callhome-get.go | 28 ++++++++++++++++++---------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/cmd/subnet-utils.go b/cmd/subnet-utils.go index d2fcfb4d..698dbcb9 100644 --- a/cmd/subnet-utils.go +++ b/cmd/subnet-utils.go @@ -199,17 +199,23 @@ func subnetPostReq(reqURL string, payload interface{}, headers map[string]string return subnetReqDo(r, headers) } -func getSubSysKeyFromMinIOConfig(client *madmin.AdminClient, subSys string) madmin.KVS { - sh, pe := client.HelpConfigKV(globalContext, subSys, "", false) - fatalIf(probe.NewError(pe), fmt.Sprintf("Unable to get config keys for %s", subSys)) +func getSubSysKeyFromMinIOConfig(client *madmin.AdminClient, subSys string) (madmin.KVS, error) { + sh, e := client.HelpConfigKV(globalContext, subSys, "", false) + if e != nil { + return madmin.KVS{}, e + } buf, e := client.GetConfigKV(globalContext, subSys) - fatalIf(probe.NewError(e), fmt.Sprintf("Unable to get server config for %s", subSys)) + if e != nil { + return madmin.KVS{}, e + } tgt, e := madmin.ParseSubSysTarget(buf, sh) - fatalIf(probe.NewError(e), fmt.Sprintf("Unable to parse sub-system target '%s'", subSys)) + if e != nil { + return madmin.KVS{}, e + } - return tgt.KVS + return tgt.KVS, nil } func getSubnetKeyFromMinIOConfig(alias string, key string) (string, bool) { @@ -217,7 +223,9 @@ func getSubnetKeyFromMinIOConfig(alias string, key string) (string, bool) { fatalIf(err, "Unable to initialize admin connection.") if minioConfigSupportsSubnet(client) { - return getSubSysKeyFromMinIOConfig(client, "subnet").Lookup(key) + kvs, e := getSubSysKeyFromMinIOConfig(client, "subnet") + fatalIf(probe.NewError(e), "Unable to get server config for subnet") + return kvs.Lookup(key) } return "", false diff --git a/cmd/support-callhome-get.go b/cmd/support-callhome-get.go index a9a32bc2..7ff6aedb 100644 --- a/cmd/support-callhome-get.go +++ b/cmd/support-callhome-get.go @@ -98,18 +98,26 @@ func printCallhomeSetting(alias string, s string) { val := "off" - kvs := getSubSysKeyFromMinIOConfig(client, "logger_webhook:subnet") - ep, found := kvs.Lookup("endpoint") + key := "logger_webhook:subnet" + kvs, e := getSubSysKeyFromMinIOConfig(client, key) + if e != nil { + // Ignore error saying the subnet webhook is not configured + if e.Error() != fmt.Sprintf("sub-system target '%s' doesn't exist", key) { + fatalIf(probe.NewError(e), "Unable to get server config for subnet") + } + } else { + ep, found := kvs.Lookup("endpoint") - if found && len(ep) > 0 { - // subnet webhook is configured. check if it is enabled - enable, found := kvs.Lookup("enable") + if found && len(ep) > 0 { + // subnet webhook is configured. check if it is enabled + enable, found := kvs.Lookup("enable") - if found { - val = enable - } else { - // if the 'enable' key is not found, it means that the webhook is enabled - val = "on" + if found { + val = enable + } else { + // if the 'enable' key is not found, it means that the webhook is enabled + val = "on" + } } }