From 58eea01b27cfe5a60a318854967324b942f2dec2 Mon Sep 17 00:00:00 2001 From: Rory Z <16801068+Rory-Z@users.noreply.github.com> Date: Tue, 23 Jan 2024 09:44:05 +0800 Subject: [PATCH] fix: fix update emqx config error Don't update readonly keys Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- controllers/apps/v2beta1/sync_emqx_config.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/controllers/apps/v2beta1/sync_emqx_config.go b/controllers/apps/v2beta1/sync_emqx_config.go index 47fe9cd8c..efe52f316 100644 --- a/controllers/apps/v2beta1/sync_emqx_config.go +++ b/controllers/apps/v2beta1/sync_emqx_config.go @@ -57,9 +57,22 @@ func (s *syncConfig) reconcile(ctx context.Context, logger logr.Logger, instance // Delete readonly configs hoconConfigObj := hoconConfig.GetRoot().(hocon.Object) - delete(hoconConfigObj, "node") - delete(hoconConfigObj, "cluster") - delete(hoconConfigObj, "dashboard") + if _, ok := hoconConfigObj["node"]; ok { + s.EventRecorder.Event(instance, corev1.EventTypeNormal, "WontUpdateReadOnlyConfig", "Won't update `node` config, because it's readonly config") + delete(hoconConfigObj, "node") + } + if _, ok := hoconConfigObj["cluster"]; ok { + s.EventRecorder.Event(instance, corev1.EventTypeNormal, "WontUpdateReadOnlyConfig", "Won't update `cluster` config, because it's readonly config") + delete(hoconConfigObj, "cluster") + } + if _, ok := hoconConfigObj["dashboard"]; ok { + s.EventRecorder.Event(instance, corev1.EventTypeNormal, "WontUpdateReadOnlyConfig", "Won't update `dashboard` config, because it's readonly config") + delete(hoconConfigObj, "dashboard") + } + if _, ok := hoconConfigObj["rpc"]; ok { + s.EventRecorder.Event(instance, corev1.EventTypeNormal, "WontUpdateReadOnlyConfig", "Won't update `rpc` config, because it's readonly config") + delete(hoconConfigObj, "rpc") + } if err := putEMQXConfigsByAPI(r, instance.Spec.Config.Mode, hoconConfigObj.String()); err != nil { return subResult{err: emperror.Wrap(err, "failed to put emqx config")}