Skip to content

Commit

Permalink
Update cluster status in updateStatusOnErr wrapper function
Browse files Browse the repository at this point in the history
  • Loading branch information
sircthulhu committed Mar 20, 2024
1 parent e8d85c1 commit 8d0c786
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions internal/controller/etcdcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ func (r *EtcdClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

if err := r.ensureClusterObjects(ctx, instance, isClusterReady); err != nil {
res, err2 := r.updateStatus(ctx, instance)
if err2 != nil {
return res, err2
}
return res, fmt.Errorf("cannot create Cluster auxiliary objects: %w", err)
logger.Error(err, "cannot create Cluster auxiliary objects")
return r.updateStatusOnErr(ctx, instance, fmt.Errorf("cannot create Cluster auxiliary objects: %w", err))
}

r.updateClusterState(instance, metav1.Condition{
Expand Down Expand Up @@ -473,6 +470,19 @@ func (r *EtcdClusterReconciler) getClientServiceName(cluster *etcdaenixiov1alpha
return cluster.Name + "-client"
}

// updateStatusOnErr wraps error and updates EtcdCluster status
func (r *EtcdClusterReconciler) updateStatusOnErr(ctx context.Context, cluster *etcdaenixiov1alpha1.EtcdCluster, err error) (ctrl.Result, error) {
res, statusErr := r.updateStatus(ctx, cluster)
if statusErr != nil {
return res, statusErr
}
if err != nil {
return res, fmt.Errorf("cannot create Cluster auxiliary objects: %w", err)
}
return res, nil
}

// updateStatus updates EtcdCluster status and returns error and requeue in case status could not be updated due to conflict
func (r *EtcdClusterReconciler) updateStatus(ctx context.Context, cluster *etcdaenixiov1alpha1.EtcdCluster) (ctrl.Result, error) {
logger := log.FromContext(ctx)
if err := r.Status().Update(ctx, cluster); err != nil {
Expand Down

0 comments on commit 8d0c786

Please sign in to comment.