@@ -638,22 +638,14 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
638638 utils.PodNamespaceEnvVar,
639639 },
640640 VolumeMounts: utils.Call(func() []corev1.VolumeMount {
641- mounts := append (
642- // Add user defined volume mounts at the start to make sure they do not
643- // overwrite built in volumes mounts.
644- utils .MapSlice (
645- pluginSpec .Volumes ,
646- func (v csiv1.VolumeSpec ) corev1.VolumeMount {
647- return v .Mount
648- },
649- ),
641+ mounts := []corev1.VolumeMount{
650642 utils.SocketDirVolumeMount,
651643 utils.HostDevVolumeMount,
652644 utils.HostSysVolumeMount,
653645 utils.LibModulesVolumeMount,
654646 utils.KeysTmpDirVolumeMount,
655647 utils.CsiConfigVolumeMount,
656- )
648+ }
657649 if r.driver.Spec.Encryption != nil {
658650 mounts = append(mounts, utils.KmsConfigVolumeMount)
659651 }
@@ -663,6 +655,19 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
663655 if logRotationEnabled {
664656 mounts = append(mounts, utils.LogsDirVolumeMount)
665657 }
658+ // Add user defined volume mounts at the end to make sure they
659+ // can overwrite built in volumes mounts.
660+ mounts = utils.MapMergeByKey(
661+ mounts,
662+ pluginSpec.Volumes,
663+ func(v csiv1.VolumeSpec) (corev1.VolumeMount, bool) {
664+ return v.Mount, v.Mount.Name != ""
665+ },
666+ func(v corev1.VolumeMount) string {
667+ return v.Name
668+ },
669+ )
670+
666671 return mounts
667672 }),
668673 Resources: ptr.Deref(
@@ -973,23 +978,15 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
973978 return containers
974979 }),
975980 Volumes: utils.Call(func() []corev1.Volume {
976- volumes := append (
977- // Add user defined volumes at the start to make sure they do not
978- // overwrite built in volumes.
979- utils .MapSlice (
980- pluginSpec .Volumes ,
981- func (v csiv1.VolumeSpec ) corev1.Volume {
982- return v .Volume
983- },
984- ),
981+ volumes := []corev1.Volume{
985982 utils.HostDevVolume,
986983 utils.HostSysVolume,
987984 utils.LibModulesVolume,
988985 utils.SocketDirVolume,
989986 utils.KeysTmpDirVolume,
990987 utils.OidcTokenVolume,
991988 utils.CsiConfigVolume,
992- )
989+ }
993990 if r.driver.Spec.Encryption != nil {
994991 volumes = append(
995992 volumes,
@@ -1003,6 +1000,18 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
10031000 utils.LogRotateDirVolumeName(r.driver.Name),
10041001 )
10051002 }
1003+ // Add user defined volumes at the end to make sure they
1004+ // can overwrite built in volumes.
1005+ volumes = utils.MapMergeByKey(volumes,
1006+ pluginSpec.Volumes,
1007+ func(v csiv1.VolumeSpec) (corev1.Volume, bool) {
1008+ return v.Volume, v.Volume.Name != ""
1009+ },
1010+ func(v corev1.Volume) string {
1011+ return v.Name
1012+ },
1013+ )
1014+
10061015 return volumes
10071016 }),
10081017 },
@@ -1359,15 +1368,7 @@ func (r *driverReconcile) reconcileNodePluginDaemonSet() error {
13591368 utils.PodNamespaceEnvVar,
13601369 },
13611370 VolumeMounts: utils.Call(func() []corev1.VolumeMount {
1362- mounts := append (
1363- // Add user defined volume mounts at the start to make sure they do not
1364- // overwrite built in volumes mounts.
1365- utils .MapSlice (
1366- pluginSpec .Volumes ,
1367- func (v csiv1.VolumeSpec ) corev1.VolumeMount {
1368- return v .Mount
1369- },
1370- ),
1371+ mounts := []corev1.VolumeMount{
13711372 utils.HostDevVolumeMount,
13721373 utils.HostSysVolumeMount,
13731374 utils.HostRunMountVolumeMount,
@@ -1377,7 +1378,7 @@ func (r *driverReconcile) reconcileNodePluginDaemonSet() error {
13771378 utils.CsiConfigVolumeMount,
13781379 utils.PluginMountDirVolumeMount(kubeletDirPath),
13791380 utils.PodsMountDirVolumeMount(kubeletDirPath),
1380- )
1381+ }
13811382 if ptr.Deref(pluginSpec.EnableSeLinuxHostMount, false) {
13821383 mounts = append(mounts, utils.EtcSelinuxVolumeMount)
13831384 }
@@ -1393,6 +1394,19 @@ func (r *driverReconcile) reconcileNodePluginDaemonSet() error {
13931394 if logRotationEnabled {
13941395 mounts = append(mounts, utils.LogsDirVolumeMount)
13951396 }
1397+ // Add user defined volume mounts at the end to make sure they
1398+ // can overwrite built in volumes mounts.
1399+ mounts = utils.MapMergeByKey(
1400+ mounts,
1401+ pluginSpec.Volumes,
1402+ func(v csiv1.VolumeSpec) (corev1.VolumeMount, bool) {
1403+ return v.Mount, v.Mount.Name != ""
1404+ },
1405+ func(v corev1.VolumeMount) string {
1406+ return v.Name
1407+ },
1408+ )
1409+
13961410 return mounts
13971411 }),
13981412 Resources: ptr.Deref(
@@ -1489,15 +1503,7 @@ func (r *driverReconcile) reconcileNodePluginDaemonSet() error {
14891503 return containers
14901504 }),
14911505 Volumes: utils.Call(func() []corev1.Volume {
1492- volumes := append (
1493- // Add user defined volumes at the start to make sure they do not
1494- // overwrite built in volumes.
1495- utils .MapSlice (
1496- pluginSpec .Volumes ,
1497- func (v csiv1.VolumeSpec ) corev1.Volume {
1498- return v .Volume
1499- },
1500- ),
1506+ volumes := []corev1.Volume{
15011507 utils.HostDevVolume,
15021508 utils.HostSysVolume,
15031509 utils.HostRunMountVolume,
@@ -1508,7 +1514,7 @@ func (r *driverReconcile) reconcileNodePluginDaemonSet() error {
15081514 utils.PluginMountDirVolume(kubeletDirPath),
15091515 utils.PodsMountDirVolume(kubeletDirPath),
15101516 utils.RegistrationDirVolume(kubeletDirPath),
1511- )
1517+ }
15121518 if r.isCephFsDriver() {
15131519 volumes = append(
15141520 volumes,
@@ -1541,6 +1547,18 @@ func (r *driverReconcile) reconcileNodePluginDaemonSet() error {
15411547 utils.LogRotateDirVolumeName(r.driver.Name),
15421548 )
15431549 }
1550+ // Add user defined volumes at the end to make sure they
1551+ // can overwrite built in volumes.
1552+ volumes = utils.MapMergeByKey(
1553+ volumes,
1554+ pluginSpec.Volumes,
1555+ func(v csiv1.VolumeSpec) (corev1.Volume, bool) {
1556+ return v.Volume, v.Volume.Name != ""
1557+ },
1558+ func(v corev1.Volume) string {
1559+ return v.Name
1560+ },
1561+ )
15441562 return volumes
15451563 }),
15461564 },
0 commit comments