Skip to content

Commit d9791c1

Browse files
authored
Merge pull request ceph#323 from black-dragon74/allow-vol-overrides
User must be able to specify volumes to override the default volumes
2 parents 365807c + b5b654c commit d9791c1

28 files changed

+5860
-92
lines changed

api/v1/driver_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ type EncryptionSpec struct {
8989
}
9090

9191
type VolumeSpec struct {
92-
//+kubebuilder:validation:Required
92+
//+kubebuilder:validation:Optional
9393
Volume corev1.Volume `json:"volume,omitempty"`
9494

95-
//+kubebuilder:validation:Required
95+
//+kubebuilder:validation:Optional
9696
Mount corev1.VolumeMount `json:"mount,omitempty"`
9797
}
9898

config/crd/bases/csi.ceph.io_drivers.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,9 +3618,6 @@ spec:
36183618
required:
36193619
- name
36203620
type: object
3621-
required:
3622-
- mount
3623-
- volume
36243621
type: object
36253622
type: array
36263623
type: object
@@ -7119,9 +7116,6 @@ spec:
71197116
required:
71207117
- name
71217118
type: object
7122-
required:
7123-
- mount
7124-
- volume
71257119
type: object
71267120
type: array
71277121
type: object

config/crd/bases/csi.ceph.io_operatorconfigs.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,9 +3656,6 @@ spec:
36563656
required:
36573657
- name
36583658
type: object
3659-
required:
3660-
- mount
3661-
- volume
36623659
type: object
36633660
type: array
36643661
type: object
@@ -7188,9 +7185,6 @@ spec:
71887185
required:
71897186
- name
71907187
type: object
7191-
required:
7192-
- mount
7193-
- volume
71947188
type: object
71957189
type: array
71967190
type: object

deploy/all-in-one/install.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4138,9 +4138,6 @@ spec:
41384138
required:
41394139
- name
41404140
type: object
4141-
required:
4142-
- mount
4143-
- volume
41444141
type: object
41454142
type: array
41464143
type: object
@@ -7639,9 +7636,6 @@ spec:
76397636
required:
76407637
- name
76417638
type: object
7642-
required:
7643-
- mount
7644-
- volume
76457639
type: object
76467640
type: array
76477641
type: object
@@ -18451,9 +18445,6 @@ spec:
1845118445
required:
1845218446
- name
1845318447
type: object
18454-
required:
18455-
- mount
18456-
- volume
1845718448
type: object
1845818449
type: array
1845918450
type: object
@@ -21983,9 +21974,6 @@ spec:
2198321974
required:
2198421975
- name
2198521976
type: object
21986-
required:
21987-
- mount
21988-
- volume
2198921977
type: object
2199021978
type: array
2199121979
type: object

deploy/charts/ceph-csi-operator/templates/driver-crd.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3615,9 +3615,6 @@ spec:
36153615
required:
36163616
- name
36173617
type: object
3618-
required:
3619-
- mount
3620-
- volume
36213618
type: object
36223619
type: array
36233620
type: object
@@ -7112,9 +7109,6 @@ spec:
71127109
required:
71137110
- name
71147111
type: object
7115-
required:
7116-
- mount
7117-
- volume
71187112
type: object
71197113
type: array
71207114
type: object

deploy/charts/ceph-csi-operator/templates/operatorconfig-crd.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3645,9 +3645,6 @@ spec:
36453645
required:
36463646
- name
36473647
type: object
3648-
required:
3649-
- mount
3650-
- volume
36513648
type: object
36523649
type: array
36533650
type: object
@@ -7164,9 +7161,6 @@ spec:
71647161
required:
71657162
- name
71667163
type: object
7167-
required:
7168-
- mount
7169-
- volume
71707164
type: object
71717165
type: array
71727166
type: object

deploy/multifile/crd.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4129,9 +4129,6 @@ spec:
41294129
required:
41304130
- name
41314131
type: object
4132-
required:
4133-
- mount
4134-
- volume
41354132
type: object
41364133
type: array
41374134
type: object
@@ -7630,9 +7627,6 @@ spec:
76307627
required:
76317628
- name
76327629
type: object
7633-
required:
7634-
- mount
7635-
- volume
76367630
type: object
76377631
type: array
76387632
type: object
@@ -18442,9 +18436,6 @@ spec:
1844218436
required:
1844318437
- name
1844418438
type: object
18445-
required:
18446-
- mount
18447-
- volume
1844818439
type: object
1844918440
type: array
1845018441
type: object
@@ -21974,9 +21965,6 @@ spec:
2197421965
required:
2197521966
- name
2197621967
type: object
21977-
required:
21978-
- mount
21979-
- volume
2198021968
type: object
2198121969
type: array
2198221970
type: object

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/kubernetes-csi/external-snapshot-metadata/client v0.1.0
99
github.com/onsi/ginkgo/v2 v2.25.3
1010
github.com/onsi/gomega v1.38.2
11+
github.com/stretchr/testify v1.10.0
1112
k8s.io/api v0.34.1
1213
k8s.io/apimachinery v0.34.1
1314
k8s.io/client-go v0.34.1

internal/controller/driver_controller.go

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)