diff --git a/ray-operator/controllers/ray/common/pod.go b/ray-operator/controllers/ray/common/pod.go index 7cc6b4ebb8..67767e16b9 100644 --- a/ray-operator/controllers/ray/common/pod.go +++ b/ray-operator/controllers/ray/common/pod.go @@ -190,6 +190,9 @@ func DefaultWorkerPodTemplate(instance rayiov1alpha1.RayCluster, workerSpec rayi log.Info("Setting pod namespaces", "namespace", instance.Namespace) } + // If the replica of workers is more than 1, `ObjectMeta.Name` may cause name conflict errors. + // Hence, we set `ObjectMeta.Name` to an empty string, and use GenerateName to prevent name conflicts. + podTemplate.ObjectMeta.Name = "" if podTemplate.Labels == nil { podTemplate.Labels = make(map[string]string) } diff --git a/ray-operator/controllers/ray/common/pod_test.go b/ray-operator/controllers/ray/common/pod_test.go index fa1a470c71..8a0d183ff3 100644 --- a/ray-operator/controllers/ray/common/pod_test.go +++ b/ray-operator/controllers/ray/common/pod_test.go @@ -642,3 +642,13 @@ func TestCleanupInvalidVolumeMounts(t *testing.T) { cleanupInvalidVolumeMounts(&pod.Spec.Containers[0], &pod) assert.Equal(t, len(pod.Spec.Containers[0].VolumeMounts), 1) } + +func TestDefaultWorkerPodTemplateWithName(t *testing.T) { + cluster := instance.DeepCopy() + svcName := utils.GenerateServiceName(cluster.Name) + worker := cluster.Spec.WorkerGroupSpecs[0] + worker.Template.ObjectMeta.Name = "ray-worker-test" + podName := cluster.Name + DashSymbol + string(rayiov1alpha1.WorkerNode) + DashSymbol + worker.GroupName + DashSymbol + utils.FormatInt32(0) + podTemplateSpec := DefaultWorkerPodTemplate(*cluster, worker, podName, svcName, "6379") + assert.Equal(t, podTemplateSpec.ObjectMeta.Name, "") +}