Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
Signed-off-by: Yicheng-Lu-llll <[email protected]>
  • Loading branch information
Yicheng-Lu-llll committed Mar 13, 2023
1 parent bd7bd5d commit 33d14f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions ray-operator/controllers/ray/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func BuildAutoscalerContainer(autoscalerImage string) v1.Container {
ImagePullPolicy: v1.PullAlways,
Env: []v1.EnvVar{
{
Name: "RAY_CLUSTER_NAME",
Name: RAY_CLUSTER_NAME,
ValueFrom: &v1.EnvVarSource{
FieldRef: &v1.ObjectFieldSelector{
FieldPath: fmt.Sprintf("metadata.labels['%s']", RayClusterLabelKey),
Expand Down Expand Up @@ -573,17 +573,17 @@ func setContainerEnvVars(pod *v1.Pod, rayContainerIndex int, rayNodeType rayiov1
container.Env = append(container.Env, portEnv)
}

if !envVarExists(RAY_CLUSTER_NAME, container.Env) {
clusterNameEnv := v1.EnvVar{
Name: RAY_CLUSTER_NAME,
ValueFrom: &v1.EnvVarSource{
FieldRef: &v1.ObjectFieldSelector{
FieldPath: fmt.Sprintf("metadata.labels['%s']", RayClusterLabelKey),
},
// The RAY_CLUSTER_NAME environment variable is managed by KubeRay and should not be modified by users.
// TODO: Audit all environment variables to identify which should not be modified by users.
clusterNameEnv := v1.EnvVar{
Name: RAY_CLUSTER_NAME,
ValueFrom: &v1.EnvVarSource{
FieldRef: &v1.ObjectFieldSelector{
FieldPath: fmt.Sprintf("metadata.labels['%s']", RayClusterLabelKey),
},
}
container.Env = append(container.Env, clusterNameEnv)
},
}
container.Env = append(container.Env, clusterNameEnv)

if strings.ToLower(creator) == RayServiceCreatorLabelValue {
// Only add this env for Ray Service cluster to improve service SLA.
Expand Down
6 changes: 3 additions & 3 deletions ray-operator/controllers/ray/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ func checkPodEnv(t *testing.T, pod v1.Pod, envName string, expectedValue string)
for _, env := range pod.Spec.Containers[0].Env {
if env.Name == envName {
// env.ValueFrom is the source for the environment variable's value. It will be nil if env.Value is not empty.
// See https://pkg.go.dev/k8s.io/api/core/v1#EnvVar for more details.
if env.ValueFrom == nil {
if !(env.Value == expectedValue) {
if env.Value != expectedValue {
t.Fatalf("Expected `%v` but got `%v`", expectedValue, env.Value)
}
} else {
fmt.Println(env.Name, env.Value, env.ValueFrom.FieldRef.FieldPath)
if !(env.ValueFrom.FieldRef.FieldPath == expectedValue) {
if env.ValueFrom.FieldRef.FieldPath != expectedValue {
t.Fatalf("Expected `%v` but got `%v`", expectedValue, env.ValueFrom.FieldRef.FieldPath)
}
}
Expand Down

0 comments on commit 33d14f3

Please sign in to comment.