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 a8fa745
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 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

0 comments on commit a8fa745

Please sign in to comment.