From cbc9b0b4e9cd10fcb7293f6ca8326094a4ce4c27 Mon Sep 17 00:00:00 2001 From: Kai-Hsun Chen Date: Thu, 22 Sep 2022 20:55:35 -0400 Subject: [PATCH] [Bug] Pod reconciliation fails if worker pod name is supplied (#587) Set RayCluster ObjectMeta.Name to an empty string, and use GenerateName to prevent name conflicts. --- ray-operator/controllers/ray/common/pod.go | 3 +++ ray-operator/controllers/ray/common/pod_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) 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, "") +}