Skip to content

Commit

Permalink
[Chore] Delete redundant pod existance checking (#2113)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortalHappiness authored May 3, 2024
1 parent e89ae34 commit e0318a3
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions ray-operator/controllers/ray/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -980,10 +979,6 @@ func (r *RayClusterReconciler) createHeadPod(ctx context.Context, instance rayv1

// build the pod then create it
pod := r.buildHeadPod(ctx, instance)
podIdentifier := types.NamespacedName{
Name: pod.Name,
Namespace: pod.Namespace,
}
if EnableBatchScheduler {
if scheduler, err := r.BatchSchedulerMgr.GetSchedulerForCluster(&instance); err == nil {
scheduler.AddMetadataToPod(&instance, utils.RayNodeHeadGroupLabelValue, &pod)
Expand All @@ -994,19 +989,7 @@ func (r *RayClusterReconciler) createHeadPod(ctx context.Context, instance rayv1

logger.Info("createHeadPod", "head pod with name", pod.GenerateName)
if err := r.Create(ctx, &pod); err != nil {
if errors.IsAlreadyExists(err) {
fetchedPod := corev1.Pod{}
// the pod might be in terminating state, we need to check
if errPod := r.Get(ctx, podIdentifier, &fetchedPod); errPod == nil {
if fetchedPod.DeletionTimestamp != nil {
logger.Error(errPod, "create pod error!", "pod is in a terminating state, we will wait until it is cleaned up", podIdentifier)
return err
}
}
logger.Info("Creating pod", "Pod already exists", pod.Name)
} else {
return err
}
return err
}
r.Recorder.Eventf(&instance, corev1.EventTypeNormal, "Created", "Created head pod %s", pod.Name)
return nil
Expand All @@ -1017,10 +1000,6 @@ func (r *RayClusterReconciler) createWorkerPod(ctx context.Context, instance ray

// build the pod then create it
pod := r.buildWorkerPod(ctx, instance, worker)
podIdentifier := types.NamespacedName{
Name: pod.Name,
Namespace: pod.Namespace,
}
if EnableBatchScheduler {
if scheduler, err := r.BatchSchedulerMgr.GetSchedulerForCluster(&instance); err == nil {
scheduler.AddMetadataToPod(&instance, worker.GroupName, &pod)
Expand All @@ -1031,20 +1010,7 @@ func (r *RayClusterReconciler) createWorkerPod(ctx context.Context, instance ray

replica := pod
if err := r.Create(ctx, &replica); err != nil {
if errors.IsAlreadyExists(err) {
fetchedPod := corev1.Pod{}
// the pod might be in terminating state, we need to check
if errPod := r.Get(ctx, podIdentifier, &fetchedPod); errPod == nil {
if fetchedPod.DeletionTimestamp != nil {
logger.Error(errPod, "create pod error!", "pod is in a terminating state, we will wait until it is cleaned up", podIdentifier)
return err
}
}
logger.Info("Creating pod", "Pod already exists", pod.Name)
} else {
logger.Error(fmt.Errorf("createWorkerPod error"), "error creating pod", "pod", pod, "err = ", err)
return err
}
return err
}
logger.Info("Created pod", "Pod ", pod.GenerateName)
r.Recorder.Eventf(&instance, corev1.EventTypeNormal, "Created", "Created worker pod %s", pod.Name)
Expand Down

0 comments on commit e0318a3

Please sign in to comment.