Skip to content

Commit

Permalink
refactor: treat Task unexpected state explicitly
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Vaca Humanes <adrian.humanes@vml.com>
  • Loading branch information
adrian-vaca-humanes-wt committed Oct 29, 2024
1 parent 52e2200 commit 0c0927e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions klyshko-operator/controllers/tuplegenerationtask_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,11 @@ func (r *TupleGenerationTaskReconciler) Reconcile(ctx context.Context, req ctrl.
}, r.setState(ctx, *taskKey, status, klyshkov1alpha1.TaskFailed)
}
case klyshkov1alpha1.TaskFailed, klyshkov1alpha1.TaskCompleted:
return ctrl.Result{
Requeue: true,
}, r.deletePVC(ctx, taskKey)
logger.V(logging.DEBUG).Info("Task reached a terminal state")
return ctrl.Result{}, r.deletePVC(ctx, taskKey)
default:
return ctrl.Result{}, fmt.Errorf("unexpected state for Task %v, PVC not reclaimed", req.Name)
}

logger.V(logging.DEBUG).Info("Desired state reached")
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -380,15 +379,18 @@ func (r *TupleGenerationTaskReconciler) deletePVC(ctx context.Context, key *Rost
}
found := &v1.PersistentVolumeClaim{}
err := r.Get(ctx, name, found)
if err == nil {
logger.V(logging.DEBUG).Info("Persistent Volume Claim already exists")
err = r.Delete(ctx, found)
if err != nil {
return fmt.Errorf("persistent volume claim deletion failed for task %v: %w", key, err)
}
return nil
if err != nil {
return fmt.Errorf("persistent volume claim deletion failed for task %v: %w", key, err)
}
logger.V(logging.DEBUG).Info("Persistent Volume Claim already exists")

err = r.Delete(ctx, found)
if err != nil {
return fmt.Errorf("persistent volume claim deletion failed for task %v: %w", key, err)
}
return fmt.Errorf("persistent volume claim deletion failed for task %v: %w", key, err)

logger.V(logging.DEBUG).Info("Deleted Persistent Volume Claim for task %v", key)
return nil
}

// provisionerPodName returns the name for the provisioner pod used for the task with the given key.
Expand Down

0 comments on commit 0c0927e

Please sign in to comment.