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.
This commit is contained in:
Shireesh Anjal
2022-06-03 10:24:25 -07:00
committed by GitHub
parent 591858cd1a
commit e9d27aef5c
2 changed files with 33 additions and 17 deletions
+15 -7
View File
@@ -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
+18 -10
View File
@@ -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"
}
}
}