From 5a4c09db1bdc1dc04e5773ce2dc75e427030a3a0 Mon Sep 17 00:00:00 2001 From: Rory Z <16801068+Rory-Z@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:28:05 +0800 Subject: [PATCH] fix: fix service port error Fixed the bug where the service port disappears when a node in the EMQX cluster crashes. Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- controllers/apps/v1beta3/emqx_handler.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/controllers/apps/v1beta3/emqx_handler.go b/controllers/apps/v1beta3/emqx_handler.go index 60046d90f..1a58dbacc 100644 --- a/controllers/apps/v1beta3/emqx_handler.go +++ b/controllers/apps/v1beta3/emqx_handler.go @@ -62,8 +62,26 @@ type EmqxReconciler struct { } func (r *EmqxReconciler) Do(ctx context.Context, instance appsv1beta3.Emqx) (ctrl.Result, error) { - var resources []client.Object var err error + var emqxNodes []appsv1beta3.EmqxNode + emqxNodes, err = r.getNodeStatusesByAPI(instance) + if err != nil { + r.EventRecorder.Event(instance, corev1.EventTypeWarning, "FailedToGetNodeStatues", err.Error()) + condition := appsv1beta3.NewCondition( + appsv1beta3.ConditionRunning, + corev1.ConditionFalse, + "FailedToGetNodeStatues", + err.Error(), + ) + instance.SetCondition(*condition) + _ = r.Status().Update(ctx, instance) + } + instance = updateEmqxStatus(instance, emqxNodes) + if err = r.Status().Update(ctx, instance); err != nil { + return ctrl.Result{}, err + } + + var resources []client.Object postFn := func(client.Object) error { return nil } sts := generateStatefulSetDef(instance) @@ -180,7 +198,7 @@ func (r *EmqxReconciler) Do(ctx context.Context, instance appsv1beta3.Emqx) (ctr return ctrl.Result{RequeueAfter: time.Duration(5) * time.Second}, err } - emqxNodes, err := r.getNodeStatusesByAPI(instance) + emqxNodes, err = r.getNodeStatusesByAPI(instance) if err != nil { r.EventRecorder.Event(instance, corev1.EventTypeWarning, "FailedToGetNodeStatues", err.Error()) condition := appsv1beta3.NewCondition(