Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions flyteplugins/go/tasks/plugins/k8s/ray/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,22 @@ func injectLogsSidecar(primaryContainer *v1.Container, podSpec *v1.PodSpec) {
podSpec.Containers = append(podSpec.Containers, *sidecar)
}

// logNoiseDisablingEnvVars turns off Ray's terminal-oriented log decorations (ANSI-colored log
// prefixes and Ray Data progress bars), which are unreadable once collected from a non-interactive
// pod. Shared by the head and worker builders to keep the two in sync.
func logNoiseDisablingEnvVars() []v1.EnvVar {
return []v1.EnvVar{
{
Name: "RAY_COLOR_PREFIX",
Value: "0",
},
{
Name: "RAY_DATA_DISABLE_PROGRESS_BARS",
Value: "1",
},
Comment on lines +379 to +386

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you thank you.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1fanwang mind adding it to v2 as well

@1fanwang 1fanwang Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this is already in v2 via #7504.

}
}

func buildHeadPodTemplate(primaryContainer *v1.Container, basePodSpec *v1.PodSpec, objectMeta *metav1.ObjectMeta, taskCtx pluginsCore.TaskExecutionContext, spec *plugins.HeadGroupSpec) (v1.PodTemplateSpec, error) {
// Some configs are copy from https://github.com/ray-project/kuberay/blob/b72e6bdcd9b8c77a9dc6b5da8560910f3a0c3ffd/apiserver/pkg/util/cluster.go#L97
// They should always be the same, so we could hard code here.
Expand All @@ -386,6 +402,7 @@ func buildHeadPodTemplate(primaryContainer *v1.Container, basePodSpec *v1.PodSpe
},
},
}
envs = append(envs, logNoiseDisablingEnvVars()...)

primaryContainer.Args = []string{}

Expand Down Expand Up @@ -512,6 +529,7 @@ func buildWorkerPodTemplate(primaryContainer *v1.Container, basePodSpec *v1.PodS
},
},
}
envs = append(envs, logNoiseDisablingEnvVars()...)

primaryContainer.Env = append(primaryContainer.Env, envs...)

Expand Down
50 changes: 50 additions & 0 deletions flyteplugins/go/tasks/plugins/k8s/ray/ray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,56 @@ func TestBuildResourceRayEntrypointPreservesEmptyArgs(t *testing.T) {
assert.Contains(t, rayJobObj.Spec.Entrypoint, "vars '' resolver")
}

func TestBuildResourceRayDisablesLogNoise(t *testing.T) {
rayJobResourceHandler := rayJobResourceHandler{}
assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{}))

taskTemplate := dummyRayTaskTemplate("ray-id", dummyRayCustomObj())
rayCtx := dummyRayTaskContext(taskTemplate, resourceRequirements, nil, "", serviceAccount)
r, err := rayJobResourceHandler.BuildResource(context.TODO(), rayCtx)
assert.Nil(t, err)
require.NotNil(t, r)

rayJob, ok := r.(*rayv1.RayJob)
require.True(t, ok)
require.NotEmpty(t, rayJob.Spec.RayClusterSpec.WorkerGroupSpecs)

// Select by container name: the vars belong on the Ray container, not on an injected sidecar.
envByContainer := func(containers []corev1.Container, name string) map[string]string {
for _, cnt := range containers {
if cnt.Name != name {
continue
}
env := make(map[string]string, len(cnt.Env))
for _, e := range cnt.Env {
env[e.Name] = e.Value
}
return env
}
return nil
}

headEnv := envByContainer(rayJob.Spec.RayClusterSpec.HeadGroupSpec.Template.Spec.Containers, "ray-head")
workerEnv := envByContainer(rayJob.Spec.RayClusterSpec.WorkerGroupSpecs[0].Template.Spec.Containers, "ray-worker")
require.NotNil(t, headEnv)
require.NotNil(t, workerEnv)

fixtures := []struct {
name string
value string
}{
{name: "RAY_COLOR_PREFIX", value: "0"},
{name: "RAY_DATA_DISABLE_PROGRESS_BARS", value: "1"},
}

for _, f := range fixtures {
t.Run(f.name, func(t *testing.T) {
assert.Equal(t, f.value, headEnv[f.name], "head container")
assert.Equal(t, f.value, workerEnv[f.name], "worker container")
})
}
}

func TestBuildPodTemplate(t *testing.T) {
taskTemplate := dummyRayTaskTemplate("id", dummyRayCustomObj())
resources := &corev1.ResourceRequirements{
Expand Down
Loading