Skip to content

Commit

Permalink
[Refactor] Remove cleanupInvalidVolumeMounts (#2104)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin85421 committed Apr 26, 2024
1 parent 4836d01 commit bafb009
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
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 {
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

0 comments on commit bafb009

Please sign in to comment.