Skip to content

Commit

Permalink
fix(v2alpha2): fix error when set replicant template but replicas = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rory-Z committed Jul 20, 2023
1 parent c588285 commit ed5fb6b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion controllers/apps/v2alpha2/sync_emqx_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/v2alpha2/update_emqx_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/v2alpha2/update_pod_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions controllers/apps/v2alpha2/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit ed5fb6b

Please sign in to comment.