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

[Refactor] Remove cleanupInvalidVolumeMounts #2104

Merged
merged 1 commit into from
Apr 26, 2024
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
21 changes: 0 additions & 21 deletions ray-operator/controllers/ray/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,6 @@ func BuildPod(ctx context.Context, podTemplateSpec corev1.PodTemplateSpec, rayNo
addEmptyDir(ctx, &pod.Spec.Containers[utils.RayContainerIndex], &pod, RayLogVolumeName, RayLogVolumeMountPath, corev1.StorageMediumDefault)
addEmptyDir(ctx, &pod.Spec.Containers[autoscalerContainerIndex], &pod, RayLogVolumeName, RayLogVolumeMountPath, corev1.StorageMediumDefault)
}
cleanupInvalidVolumeMounts(&pod.Spec.Containers[utils.RayContainerIndex], &pod)
if len(pod.Spec.InitContainers) > utils.RayContainerIndex {
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't understand the logic to compare the number of init containers and RayContainerIndex.

cleanupInvalidVolumeMounts(&pod.Spec.InitContainers[utils.RayContainerIndex], &pod)
}

var cmd, args string
if len(pod.Spec.Containers[utils.RayContainerIndex].Command) > 0 {
Expand Down Expand Up @@ -844,23 +840,6 @@ func checkIfVolumeExists(pod *corev1.Pod, volumeName string) bool {
return false
}

func cleanupInvalidVolumeMounts(container *corev1.Container, pod *corev1.Pod) {
// if a volumeMount is specified in the container,
// but has no corresponding pod volume, it is removed
k := 0
for _, mountedVol := range container.VolumeMounts {
for _, podVolume := range pod.Spec.Volumes {
if mountedVol.Name == podVolume.Name {
// valid mount, moving on...
container.VolumeMounts[k] = mountedVol
k++
break
}
}
}
container.VolumeMounts = container.VolumeMounts[:k]
}

func findMemoryReqOrLimit(container corev1.Container) (res *resource.Quantity) {
var mem *resource.Quantity
// check the requests, if they are not set, check the limits.
Expand Down
26 changes: 0 additions & 26 deletions ray-operator/controllers/ray/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,32 +769,6 @@ func splitAndSort(s string) []string {
return result
}

func TestCleanupInvalidVolumeMounts(t *testing.T) {
ctx := context.Background()
cluster := instance.DeepCopy()

// Test head pod
podName := strings.ToLower(cluster.Name + utils.DashSymbol + string(rayv1.HeadNode) + utils.DashSymbol + utils.FormatInt32(0))
podTemplateSpec := DefaultHeadPodTemplate(ctx, *cluster, cluster.Spec.HeadGroupSpec, podName, "6379")
pod := BuildPod(ctx, podTemplateSpec, rayv1.HeadNode, cluster.Spec.HeadGroupSpec.RayStartParams, "6379", nil, utils.GetCRDType(""), "")

pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, []corev1.VolumeMount{
{
Name: "mock-name1",
MountPath: "/mock-path1",
ReadOnly: true,
},
{
Name: "mock-name2",
MountPath: "/mock-path2",
ReadOnly: true,
},
}...)
assert.Equal(t, len(pod.Spec.Containers[0].VolumeMounts), 3)
cleanupInvalidVolumeMounts(&pod.Spec.Containers[0], &pod)
assert.Equal(t, len(pod.Spec.Containers[0].VolumeMounts), 1)
}

func TestDefaultWorkerPodTemplateWithName(t *testing.T) {
ctx := context.Background()

Expand Down
Loading