-
Notifications
You must be signed in to change notification settings - Fork 364
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
[release blocker][Feature] Only Autoscaler can make decisions to delete Pods #1253
Merged
kevin85421
merged 3 commits into
ray-project:master
from
kevin85421:disable-random-deletion
Jul 20, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,7 +416,7 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv | |
// Reconcile head Pod | ||
if len(headPods.Items) == 1 { | ||
headPod := headPods.Items[0] | ||
r.Log.Info("reconcilePods ", "head pod found", headPod.Name) | ||
r.Log.Info("reconcilePods", "head pod found", headPod.Name) | ||
if headPod.Status.Phase == corev1.PodRunning || headPod.Status.Phase == corev1.PodPending { | ||
r.Log.Info("reconcilePods", "head pod is up and running... checking workers", headPod.Name) | ||
} else if headPod.Status.Phase == corev1.PodFailed && strings.Contains(headPod.Status.Reason, "Evicted") { | ||
|
@@ -431,15 +431,15 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv | |
} | ||
if len(headPods.Items) == 0 || headPods.Items == nil { | ||
// create head pod | ||
r.Log.Info("reconcilePods ", "creating head pod for cluster", instance.Name) | ||
r.Log.Info("reconcilePods", "creating head pod for cluster", instance.Name) | ||
common.CreatedClustersCounterInc(instance.Namespace) | ||
if err := r.createHeadPod(ctx, *instance); err != nil { | ||
common.FailedClustersCounterInc(instance.Namespace) | ||
return err | ||
} | ||
common.SuccessfulClustersCounterInc(instance.Namespace) | ||
} else if len(headPods.Items) > 1 { | ||
r.Log.Info("reconcilePods ", "more than 1 head pod found for cluster", instance.Name) | ||
r.Log.Info("reconcilePods", "more than 1 head pod found for cluster", instance.Name) | ||
itemLength := len(headPods.Items) | ||
for index := 0; index < itemLength; index++ { | ||
if headPods.Items[index].Status.Phase == corev1.PodRunning || headPods.Items[index].Status.Phase == corev1.PodPending { | ||
|
@@ -594,19 +594,40 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv | |
r.Log.Info("reconcilePods", "all workers already exist for group", worker.GroupName) | ||
continue | ||
} else { | ||
// diff < 0 means that we need to delete some Pods to meet the desired number of replicas. | ||
randomlyRemovedWorkers := -diff | ||
r.Log.Info("reconcilePods", "Number workers to delete randomly", randomlyRemovedWorkers, "Worker group", worker.GroupName) | ||
for i := 0; i < int(randomlyRemovedWorkers); i++ { | ||
randomPodToDelete := runningPods.Items[i] | ||
r.Log.Info("Randomly deleting Pod", "progress", fmt.Sprintf("%d / %d", i+1, randomlyRemovedWorkers), "with name", randomPodToDelete.Name) | ||
if err := r.Delete(ctx, &randomPodToDelete); err != nil { | ||
if !errors.IsNotFound(err) { | ||
return err | ||
// diff < 0 indicates the need to delete some Pods to match the desired number of replicas. However, | ||
// randomly deleting Pods is certainly not ideal. So, if autoscaling is enabled for the cluster, we | ||
// will disable random Pod deletion, making Autoscaler the sole decision-maker for Pod deletions. | ||
enableInTreeAutoscaling := (instance.Spec.EnableInTreeAutoscaling != nil) && (*instance.Spec.EnableInTreeAutoscaling) | ||
|
||
// TODO (kevin85421): `enableRandomPodDelete` is a feature flag for KubeRay v0.6.0. If users want to use | ||
// the old behavior, they can set the environment variable `ENABLE_RANDOM_POD_DELETE` to `true`. When the | ||
// default behavior is stable enough, we can remove this feature flag. | ||
enableRandomPodDelete := false | ||
if enableInTreeAutoscaling { | ||
if s := os.Getenv(common.ENABLE_RANDOM_POD_DELETE); strings.ToLower(s) == "true" { | ||
enableRandomPodDelete = true | ||
} | ||
} | ||
// Case 1: If Autoscaler is disabled, we will always enable random Pod deletion no matter the value of the feature flag. | ||
// Case 2: If Autoscaler is enabled, we will respect the value of the feature flag. If the feature flag environment variable | ||
// is not set, we will disable random Pod deletion by default. | ||
if !enableInTreeAutoscaling || enableRandomPodDelete { | ||
// diff < 0 means that we need to delete some Pods to meet the desired number of replicas. | ||
randomlyRemovedWorkers := -diff | ||
r.Log.Info("reconcilePods", "Number workers to delete randomly", randomlyRemovedWorkers, "Worker group", worker.GroupName) | ||
for i := 0; i < int(randomlyRemovedWorkers); i++ { | ||
randomPodToDelete := runningPods.Items[i] | ||
r.Log.Info("Randomly deleting Pod", "progress", fmt.Sprintf("%d / %d", i+1, randomlyRemovedWorkers), "with name", randomPodToDelete.Name) | ||
if err := r.Delete(ctx, &randomPodToDelete); err != nil { | ||
if !errors.IsNotFound(err) { | ||
return err | ||
} | ||
r.Log.Info("reconcilePods", "The worker Pod has already been deleted", randomPodToDelete.Name) | ||
} | ||
r.Log.Info("reconcilePods", "The worker Pod has already been deleted", randomPodToDelete.Name) | ||
r.Recorder.Eventf(instance, corev1.EventTypeNormal, "Deleted", "Deleted Pod %s", randomPodToDelete.Name) | ||
} | ||
r.Recorder.Eventf(instance, corev1.EventTypeNormal, "Deleted", "Deleted Pod %s", randomPodToDelete.Name) | ||
} else { | ||
r.Log.Info(fmt.Sprintf("Random Pod deletion is disabled for cluster %s. The only decision-maker for Pod deletions is Autoscaler.", instance.Name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Ray Autoscaler. (if that is what you mean :) ) |
||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rephrase the log statement.
"Randomly pick xx workers to delete from worker group xxx."