Skip to content

Commit

Permalink
fix: fix didn't delete pod when CR's replicas = 0
Browse files Browse the repository at this point in the history
Signed-off-by: Rory Z <[email protected]>
  • Loading branch information
Rory-Z committed Sep 21, 2023
1 parent 8e2a9c9 commit 5cbae92
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions controllers/apps/v1beta3/emqx_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ func (r *EmqxReconciler) Do(ctx context.Context, instance appsv1beta3.Emqx) (ctr
return ctrl.Result{}, nil
}
if instance.GetReplicas() == nil || *instance.GetReplicas() == 0 {
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
storageSts := &appsv1.StatefulSet{}
if err := r.Get(ctx, client.ObjectKeyFromObject(generateStatefulSetDef(instance)), storageSts); err != nil {
if k8sErrors.IsNotFound(err) {
return nil
}
return err
}
storageSts.Spec.Replicas = instance.GetReplicas()
return r.Handler.Update(storageSts, func(o client.Object) error { return nil })
}); err != nil {
return ctrl.Result{}, emperror.Wrap(err, "failed to update statefulSet")
}

if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
_ = r.Get(ctx, client.ObjectKeyFromObject(instance), instance)
instance = updateEmqxStatus(instance, []appsv1beta3.EmqxNode{})
Expand Down

0 comments on commit 5cbae92

Please sign in to comment.