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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ray-operator/controllers/ray/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?

if controllerutil.ContainsFinalizer(&workerPod, utils.WorkerDeletionFinalizer) {
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
}
}

}
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
    }
}

}
shouldDelete, reason := shouldDeletePod(workerPod, rayv1.WorkerNode)
logger.Info("reconcilePods", "worker Pod", workerPod.Name, "shouldDelete", shouldDelete, "reason", reason)
if shouldDelete {
Expand Down Expand Up @@ -1132,6 +1147,7 @@ func (r *RayClusterReconciler) buildWorkerPod(ctx context.Context, instance rayv
headPort := common.GetHeadPort(instance.Spec.HeadGroupSpec.RayStartParams)
autoscalingEnabled := instance.Spec.EnableInTreeAutoscaling
podTemplateSpec := common.DefaultWorkerPodTemplate(ctx, instance, worker, podName, fqdnRayIP, headPort)
podTemplateSpec.Finalizers = append(podTemplateSpec.Finalizers, utils.WorkerDeletionFinalizer)
if len(r.workerSidecarContainers) > 0 {
podTemplateSpec.Spec.Containers = append(podTemplateSpec.Spec.Containers, r.workerSidecarContainers...)
}
Expand Down
2 changes: 2 additions & 0 deletions ray-operator/controllers/ray/utils/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (

// Finalizers for GCS fault tolerance
GCSFaultToleranceRedisCleanupFinalizer = "ray.io/gcs-ft-redis-cleanup-finalizer"
// Finalizers for worker deletion
WorkerDeletionFinalizer = "ray.io/worker-deletion-finalizer"

// EnableServeServiceKey is exclusively utilized to indicate if a RayCluster is directly used for serving.
// See https://github.com/ray-project/kuberay/pull/1672 for more details.
Expand Down