From cbf405d674b6fdc324c4ffbd0caf5d1d8ee933b2 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 9 Oct 2025 14:20:43 +0300 Subject: [PATCH] fix: log explicit messages when bootstrap.dcs.standby_cluster can't parse Previously, a generic panic was logged, so it was hard to figure out the cause --- pkg/patroni/patroni.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/patroni/patroni.go b/pkg/patroni/patroni.go index b294ddb8..fbba22f1 100644 --- a/pkg/patroni/patroni.go +++ b/pkg/patroni/patroni.go @@ -331,11 +331,33 @@ func updateStandbyClusterSettings(configMap *corev1.ConfigMap, settings interfac err := yaml.Unmarshal([]byte(configMap.Data[configMapKey]), &config) if err != nil { logger.Error("Could not unmarshal patroni config map", zap.Error(err)) + return configMap } - config["bootstrap"].(map[interface{}]interface{})["dcs"].(map[interface{}]interface{})["standby_cluster"] = settings + + // Validate config structure exists before type assertion + if config == nil { + logger.Error("Config map is nil after unmarshal") + return configMap + } + + bootstrap, ok := config["bootstrap"].(map[interface{}]interface{}) + if !ok || bootstrap == nil { + logger.Error("Config map missing 'bootstrap' section or wrong type") + return configMap + } + + dcs, ok := bootstrap["dcs"].(map[interface{}]interface{}) + if !ok || dcs == nil { + logger.Error("Config map missing 'bootstrap.dcs' section or wrong type") + return configMap + } + + dcs["standby_cluster"] = settings + result, err := yaml.Marshal(config) if err != nil { logger.Error("Could not marshal patroni config map", zap.Error(err)) + return configMap } configMap.Data[configMapKey] = string(result) return configMap