From 3e3eb20819a46cd080e197a1b0e5f1a704bfb846 Mon Sep 17 00:00:00 2001 From: Shlok Chaudhari Date: Fri, 23 Aug 2024 16:33:44 -0500 Subject: [PATCH] Fixing the volume mount names in CreatePod function (#293) --- pkg/csi/csi_ops.go | 8 +++++--- pkg/csi/csi_ops_test.go | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/csi/csi_ops.go b/pkg/csi/csi_ops.go index 202db70..786343b 100644 --- a/pkg/csi/csi_ops.go +++ b/pkg/csi/csi_ops.go @@ -210,9 +210,10 @@ func (c *applicationCreate) CreatePod(ctx context.Context, args *types.CreatePod }}, }, } + pvcCount := 1 for pvcName, path := range args.PVCMap { pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{ - Name: fmt.Sprintf("%s-%s", volumeNameInPod, pvcName), + Name: fmt.Sprintf("%s-%d", volumeNameInPod, pvcCount), VolumeSource: v1.VolumeSource{ PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ ClaimName: pvcName, @@ -221,15 +222,16 @@ func (c *applicationCreate) CreatePod(ctx context.Context, args *types.CreatePod }) if len(path.MountPath) != 0 { pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, v1.VolumeMount{ - Name: fmt.Sprintf("%s-%s", volumeNameInPod, pvcName), + Name: fmt.Sprintf("%s-%d", volumeNameInPod, pvcCount), MountPath: path.MountPath, }) } else { pod.Spec.Containers[0].VolumeDevices = append(pod.Spec.Containers[0].VolumeDevices, v1.VolumeDevice{ - Name: fmt.Sprintf("%s-%s", volumeNameInPod, pvcName), + Name: fmt.Sprintf("%s-%d", volumeNameInPod, pvcCount), DevicePath: path.DevicePath, }) } + pvcCount++ } if args.RunAsUser > 0 { diff --git a/pkg/csi/csi_ops_test.go b/pkg/csi/csi_ops_test.go index 34a0f98..084bf38 100644 --- a/pkg/csi/csi_ops_test.go +++ b/pkg/csi/csi_ops_test.go @@ -702,22 +702,23 @@ func (s *CSITestSuite) TestCreatePod(c *C) { c.Assert(pod.Spec.Containers[0].Command, DeepEquals, tc.args.Command) c.Assert(pod.Spec.Containers[0].Args, DeepEquals, tc.args.ContainerArgs) index := 0 + pvcCount := 1 for pvcName, path := range tc.args.PVCMap { if len(path.MountPath) != 0 { c.Assert(pod.Spec.Containers[0].VolumeMounts[index], DeepEquals, v1.VolumeMount{ - Name: fmt.Sprintf("persistent-storage-%s", pvcName), + Name: fmt.Sprintf("persistent-storage-%d", pvcCount), MountPath: path.MountPath, }) c.Assert(pod.Spec.Containers[0].VolumeDevices, IsNil) } else { c.Assert(pod.Spec.Containers[0].VolumeDevices[index], DeepEquals, v1.VolumeDevice{ - Name: fmt.Sprintf("persistent-storage-%s", pvcName), + Name: fmt.Sprintf("persistent-storage-%d", pvcCount), DevicePath: path.DevicePath, }) c.Assert(pod.Spec.Containers[0].VolumeMounts, IsNil) } c.Assert(pod.Spec.Volumes[index], DeepEquals, v1.Volume{ - Name: fmt.Sprintf("persistent-storage-%s", pvcName), + Name: fmt.Sprintf("persistent-storage-%d", pvcCount), VolumeSource: v1.VolumeSource{ PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ ClaimName: pvcName, @@ -725,6 +726,7 @@ func (s *CSITestSuite) TestCreatePod(c *C) { }, }) index++ + pvcCount++ } if tc.args.ContainerImage == "" { c.Assert(pod.Spec.Containers[0].Image, Equals, common.DefaultPodImage)