Skip to content

Commit e0318a3

Browse files
[Chore] Delete redundant pod existance checking (#2113)
1 parent e89ae34 commit e0318a3

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

ray-operator/controllers/ray/raycluster_controller.go

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"k8s.io/apimachinery/pkg/api/errors"
3434
"k8s.io/apimachinery/pkg/api/resource"
3535
"k8s.io/apimachinery/pkg/runtime"
36-
"k8s.io/apimachinery/pkg/types"
3736
ctrl "sigs.k8s.io/controller-runtime"
3837
"sigs.k8s.io/controller-runtime/pkg/builder"
3938
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -980,10 +979,6 @@ func (r *RayClusterReconciler) createHeadPod(ctx context.Context, instance rayv1
980979

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

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

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

10321011
replica := pod
10331012
if err := r.Create(ctx, &replica); err != nil {
1034-
if errors.IsAlreadyExists(err) {
1035-
fetchedPod := corev1.Pod{}
1036-
// the pod might be in terminating state, we need to check
1037-
if errPod := r.Get(ctx, podIdentifier, &fetchedPod); errPod == nil {
1038-
if fetchedPod.DeletionTimestamp != nil {
1039-
logger.Error(errPod, "create pod error!", "pod is in a terminating state, we will wait until it is cleaned up", podIdentifier)
1040-
return err
1041-
}
1042-
}
1043-
logger.Info("Creating pod", "Pod already exists", pod.Name)
1044-
} else {
1045-
logger.Error(fmt.Errorf("createWorkerPod error"), "error creating pod", "pod", pod, "err = ", err)
1046-
return err
1047-
}
1013+
return err
10481014
}
10491015
logger.Info("Created pod", "Pod ", pod.GenerateName)
10501016
r.Recorder.Eventf(&instance, corev1.EventTypeNormal, "Created", "Created worker pod %s", pod.Name)

0 commit comments

Comments
 (0)