Skip to content

Commit

Permalink
statefulset not reconciling because nil (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
waveywaves authored Feb 5, 2024
1 parent 79bd98a commit b6d2c82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions controllers/uffizzicluster/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"time"
)

var (
ErrStatefulSetNil = errors.New("statefulSet is nil")
)

func (r *UffizziClusterReconciler) getUffizziClusterStatefulSet(ctx context.Context, uCluster *v1alpha1.UffizziCluster) (*appsv1.StatefulSet, error) {
ucStatefulSet := &appsv1.StatefulSet{}
if err := r.Get(ctx, types.NamespacedName{
Expand All @@ -38,7 +42,8 @@ func (r *UffizziClusterReconciler) scaleStatefulSets(ctx context.Context, scale
replicas := int32(scale)
for _, ss := range statefulSets {
if ss == nil {
return errors.New("statefulSet is nil")
// TODO: ErrStatefulSetNil should be used here, handle it in the caller
continue
}
ss.Spec.Replicas = &replicas
if err := r.Update(ctx, ss); err != nil {
Expand All @@ -51,7 +56,7 @@ func (r *UffizziClusterReconciler) scaleStatefulSets(ctx context.Context, scale
// waitForStatefulSetToScale is a goroutine which waits for the stateful set to be ready
func (r *UffizziClusterReconciler) waitForStatefulSetToScale(ctx context.Context, scale int, ucStatefulSet *appsv1.StatefulSet) error {
if ucStatefulSet == nil {
return errors.New("statefulSet is nil")
return ErrStatefulSetNil
}
// wait for the StatefulSet to be ready
return wait.PollImmediate(time.Second*5, time.Minute*1, func() (bool, error) {
Expand Down
3 changes: 2 additions & 1 deletion controllers/uffizzicluster/uffizzicluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ func (r *UffizziClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque
// logger.Info("vcluster statefulset not found, requeueing")
return ctrl.Result{Requeue: true, RequeueAfter: time.Second * 5}, nil
}
logger.Info("Failed to reconcile sleep state, reconciling", "Error", err.Error())
// cluster did not sleep
logger.Info("Failed to reconcile sleep state, reconciling again", "Error", err.Error())
return ctrl.Result{Requeue: true, RequeueAfter: time.Second * 5}, nil
}

Expand Down

0 comments on commit b6d2c82

Please sign in to comment.