diff --git a/controllers/apps/v2alpha2/sync_emqx_config.go b/controllers/apps/v2alpha2/sync_emqx_config.go index 9a6ec9fef..f10f79734 100644 --- a/controllers/apps/v2alpha2/sync_emqx_config.go +++ b/controllers/apps/v2alpha2/sync_emqx_config.go @@ -18,7 +18,8 @@ type syncConfig struct { } func (s *syncConfig) reconcile(ctx context.Context, instance *appsv2alpha2.EMQX, r innerReq.RequesterInterface) subResult { - if r == nil { + // If core nodes is nil, the EMQX is in the process of being created + if len(instance.Status.CoreNodes) == 0 { configMap := generateConfigMap(instance, instance.Spec.Config.Data) if err := s.Handler.CreateOrUpdateList(instance, s.Scheme, []client.Object{configMap}); err != nil { return subResult{err: emperror.Wrap(err, "failed to create or update configMap")} diff --git a/controllers/apps/v2alpha2/update_emqx_status.go b/controllers/apps/v2alpha2/update_emqx_status.go index 38ac0fdb7..c5d497c64 100644 --- a/controllers/apps/v2alpha2/update_emqx_status.go +++ b/controllers/apps/v2alpha2/update_emqx_status.go @@ -20,7 +20,7 @@ type updateStatus struct { } func (u *updateStatus) reconcile(ctx context.Context, instance *appsv2alpha2.EMQX, r innerReq.RequesterInterface) subResult { - if isExistReplicant(instance) && instance.Status.ReplicantNodesStatus == nil { + if instance.Spec.ReplicantTemplate != nil && instance.Status.ReplicantNodesStatus == nil { instance.Status.ReplicantNodesStatus = &appsv2alpha2.EMQXNodesStatus{ Replicas: *instance.Spec.ReplicantTemplate.Spec.Replicas, } diff --git a/controllers/apps/v2alpha2/update_pod_conditions.go b/controllers/apps/v2alpha2/update_pod_conditions.go index f4e56c03e..3234fdce1 100644 --- a/controllers/apps/v2alpha2/update_pod_conditions.go +++ b/controllers/apps/v2alpha2/update_pod_conditions.go @@ -63,7 +63,7 @@ func (u *updatePodConditions) checkInCluster(instance *appsv2alpha2.EMQX, r inne } for _, node := range nodes { if pod.UID == node.PodUID { - if node.Edition == "enterprise" { + if node.Edition == "Enterprise" { v, _ := semver.NewVersion(node.Version) if v.Compare(semver.MustParse("5.0.3")) >= 0 { return u.checkRebalanceStatus(instance, r, pod) diff --git a/controllers/apps/v2alpha2/util.go b/controllers/apps/v2alpha2/util.go index 4672de03a..a5d85b2ce 100644 --- a/controllers/apps/v2alpha2/util.go +++ b/controllers/apps/v2alpha2/util.go @@ -70,15 +70,16 @@ func getStateFulSetList(ctx context.Context, k8sClient client.Client, instance * client.MatchingLabels(instance.Spec.CoreTemplate.Labels), ) for _, sts := range list.Items { - hash, ok := sts.Labels[appsv2alpha2.PodTemplateHashLabelKey] - if ok && sts.Status.Replicas != 0 { + if hash, ok := sts.Labels[appsv2alpha2.PodTemplateHashLabelKey]; ok { if hash == instance.Status.CoreNodesStatus.UpdateRevision { updateSts = sts.DeepCopy() } - if hash == instance.Status.CoreNodesStatus.CurrentRevision { + if sts.Status.Replicas != 0 && + hash == instance.Status.CoreNodesStatus.CurrentRevision { currentSts = sts.DeepCopy() } - if hash != instance.Status.CoreNodesStatus.UpdateRevision && + if sts.Status.Replicas != 0 && + hash != instance.Status.CoreNodesStatus.UpdateRevision && hash != instance.Status.CoreNodesStatus.CurrentRevision { oldStsList = append(oldStsList, sts.DeepCopy()) } @@ -109,15 +110,16 @@ func getReplicaSetList(ctx context.Context, k8sClient client.Client, instance *a client.MatchingLabels(instance.Spec.ReplicantTemplate.Labels), ) for _, rs := range list.Items { - hash, ok := rs.Labels[appsv2alpha2.PodTemplateHashLabelKey] - if ok && rs.Status.Replicas != 0 { + if hash, ok := rs.Labels[appsv2alpha2.PodTemplateHashLabelKey]; ok { if hash == instance.Status.ReplicantNodesStatus.UpdateRevision { updateRs = rs.DeepCopy() } - if hash == instance.Status.ReplicantNodesStatus.CurrentRevision { + if rs.Status.Replicas != 0 && + hash == instance.Status.ReplicantNodesStatus.CurrentRevision { currentRs = rs.DeepCopy() } - if hash != instance.Status.ReplicantNodesStatus.UpdateRevision && + if rs.Status.Replicas != 0 && + hash != instance.Status.ReplicantNodesStatus.UpdateRevision && hash != instance.Status.ReplicantNodesStatus.CurrentRevision { oldRsList = append(oldRsList, rs.DeepCopy()) }