Skip to content

Commit

Permalink
fix: fix operator crashed in func generateNodeCookieSecret
Browse files Browse the repository at this point in the history
Signed-off-by: Rory Z <[email protected]>
  • Loading branch information
Rory-Z committed Dec 2, 2023
1 parent b3d1765 commit 41aa59d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 7 additions & 0 deletions controllers/apps/v2beta1/emqx_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)) {
Expand Down
6 changes: 1 addition & 5 deletions controllers/apps/v2beta1/sync_emqx_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions e2e/v2beta1/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 41aa59d

Please sign in to comment.