Skip to content

Commit

Permalink
[Bug] Pod reconciliation fails if worker pod name is supplied (#587)
Browse files Browse the repository at this point in the history
Set RayCluster ObjectMeta.Name to an empty string, and use GenerateName to prevent name conflicts.
  • Loading branch information
kevin85421 authored Sep 23, 2022
1 parent 3707836 commit cbc9b0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ray-operator/controllers/ray/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 10 additions & 0 deletions ray-operator/controllers/ray/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
}

0 comments on commit cbc9b0b

Please sign in to comment.