diff --git a/controllers/apps/v2beta1/emqx_controller.go b/controllers/apps/v2beta1/emqx_controller.go index 7b58e213f..e1ae1fdbb 100644 --- a/controllers/apps/v2beta1/emqx_controller.go +++ b/controllers/apps/v2beta1/emqx_controller.go @@ -27,6 +27,7 @@ import ( emperror "emperror.dev/errors" innerErr "github.com/emqx/emqx-operator/internal/errors" innerReq "github.com/emqx/emqx-operator/internal/requester" + "github.com/rory-z/go-hocon" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -102,6 +103,12 @@ func (r *EMQXReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. return ctrl.Result{}, nil } + _, err := hocon.ParseString(instance.Spec.Config.Data) + if err != nil { + r.EventRecorder.Event(instance, corev1.EventTypeWarning, "InvalidConfig", "the .spec.config.data is not a valid HOCON config") + return ctrl.Result{}, emperror.Wrap(err, "failed to parse config") + } + requester, err := newRequester(r.Client, instance) if err != nil { if k8sErrors.IsNotFound(emperror.Cause(err)) { diff --git a/controllers/apps/v2beta1/sync_emqx_config.go b/controllers/apps/v2beta1/sync_emqx_config.go index 9066148e3..726b1a262 100644 --- a/controllers/apps/v2beta1/sync_emqx_config.go +++ b/controllers/apps/v2beta1/sync_emqx_config.go @@ -19,11 +19,7 @@ type syncConfig struct { } func (s *syncConfig) reconcile(ctx context.Context, instance *appsv2beta1.EMQX, r innerReq.RequesterInterface) subResult { - hoconConfig, err := hocon.ParseString(instance.Spec.Config.Data) - if err != nil { - s.EventRecorder.Event(instance, corev1.EventTypeWarning, "InvalidConfig", err.Error()) - return subResult{err: emperror.Wrap(err, "failed to parse config")} - } + hoconConfig, _ := hocon.ParseString(instance.Spec.Config.Data) // If core nodes is nil, the EMQX is in the process of being created if len(instance.Status.CoreNodes) == 0 { diff --git a/e2e/v2beta1/e2e_test.go b/e2e/v2beta1/e2e_test.go index f12c8951d..8e8620db1 100644 --- a/e2e/v2beta1/e2e_test.go +++ b/e2e/v2beta1/e2e_test.go @@ -189,7 +189,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { It("change EMQX image", func() { Expect(k8sClient.Get(context.TODO(), client.ObjectKeyFromObject(instance), instance)).Should(Succeed()) storage := instance.DeepCopy() - instance.Spec.Image = "emqx:5.1" + instance.Spec.Image = "emqx:5" Expect(k8sClient.Update(context.TODO(), instance)).Should(Succeed()) Eventually(func() *appsv2beta1.EMQX { @@ -383,7 +383,7 @@ var _ = Describe("E2E Test", Label("base"), Ordered, func() { It("change EMQX image", func() { Expect(k8sClient.Get(context.TODO(), client.ObjectKeyFromObject(instance), instance)).Should(Succeed()) storage := instance.DeepCopy() - instance.Spec.Image = "emqx/emqx:5.1" + instance.Spec.Image = "emqx/emqx:latest" Expect(k8sClient.Update(context.TODO(), instance)).Should(Succeed()) Eventually(func() *appsv2beta1.EMQX {