Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add default init container in workers to wait for GCS to be ready #973

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ray-operator/controllers/ray/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ func DefaultWorkerPodTemplate(instance rayiov1alpha1.RayCluster, workerSpec rayi
log.Info("Setting pod namespaces", "namespace", instance.Namespace)
}

// The Ray worker should only start once the GCS server is ready.
initContainer := v1.Container{
Name: "wait-gcs-ready",
Image: podTemplate.Spec.Containers[0].Image,
kevin85421 marked this conversation as resolved.
Show resolved Hide resolved
ImagePullPolicy: v1.PullIfNotPresent,
Command: []string{"/bin/bash", "-lc", "--"},
Args: []string{
fmt.Sprintf("until ray health-check --address %s:%s > /dev/null 2>&1; do echo wait for GCS to be ready; sleep 5; done", fqdnRayIP, headPort),
},
}
podTemplate.Spec.InitContainers = append(podTemplate.Spec.InitContainers, initContainer)

// 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 = ""
Expand Down
14 changes: 14 additions & 0 deletions ray-operator/controllers/ray/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,3 +800,17 @@ func TestDefaultWorkerPodTemplateWithConfigurablePorts(t *testing.T) {
t.Fatal(err)
}
}

func TestDefaultInitContainer(t *testing.T) {
// A default init container to check the health of GCS is expected to be added.
cluster := instance.DeepCopy()
fqdnRayIP := utils.GenerateFQDNServiceName(cluster.Name, cluster.Namespace)
worker := cluster.Spec.WorkerGroupSpecs[0]
podName := cluster.Name + DashSymbol + string(rayiov1alpha1.WorkerNode) + DashSymbol + worker.GroupName + DashSymbol + utils.FormatInt32(0)
expectedResult := len(cluster.Spec.WorkerGroupSpecs[0].Template.Spec.InitContainers) + 1

// Pass a deep copy of worker (*worker.DeepCopy()) to prevent "worker" from updating.
podTemplateSpec := DefaultWorkerPodTemplate(*cluster, *worker.DeepCopy(), podName, fqdnRayIP, "6379")
actualResult := len(podTemplateSpec.Spec.InitContainers)
assert.Equal(t, expectedResult, actualResult, "A default init container is expected to be added.")
}