Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add finalizer to worker pods to ensure min replica #2041

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YichengWang12
Copy link

@YichengWang12 YichengWang12 commented Mar 24, 2024

Why are these changes needed?

Currently all worker pods can be deleted without protection, regardless of minReplica. This change adds a protection of minReplica using finalizer.

Related issue number

Fix #1740

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

}

}
continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !controllerutil.ContainsFinalizer(&workerPod, utils.WorkerDeletionFinalizer) {
    continue
}

if int32(len(workerPods.Items)) <= *worker.MinReplicas {
    // If the number of worker Pods is less than or equal to the minimum number of replicas, we should not delete the 
    Pod.
    logger.Info("reconcilePods", "worker Pod", workerPod.Name, "shouldDelete", false, "reason", "Number of worker Pods is less than or equal to the minimum number of replicas")
} else {
    controllerutil.RemoveFinalizer(&workerPod, utils.WorkerDeletionFinalizer)
    if err := r.Update(ctx, &workerPod); err != nil {
  	return err
    }
}

@@ -759,6 +759,21 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
deleted := struct{}{}
numDeletedUnhealthyWorkerPods := 0
for _, workerPod := range workerPods.Items {
if workerPod.ObjectMeta.DeletionTimestamp != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how much this check helps.

Even with a finalizer configured, if a pod has been deleted with a deletion timestamp it is already terminating. We will keep the Pod object around but the worker will not actually be available.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. Would admission webhook be better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are trying to avoid admission webhooks as much as possible. @kevin85421 thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Finalizer to block deletion of RayCluster with running jobs
2 participants