csi: set kernel mount options from env var if not in cluster spec

If the cephfs kernel mount options are not specified in the
cephcluster.spec.csi CR settings, fall back to the setting
in the operator env var CSI_CEPHFS_KERNEL_MOUNT_OPTIONS.

Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
This commit is contained in:
Travis Nielsen committed 2025-08-27 16:11:34 -06:00
1 parent cc39368964
commit eeebfbf496
2 files changed
+25

No files matched your search

@@ -168,6 +168,10 @@ func CreateOrLoadClusterInfo(clusterdContext *clusterd.Context, context context.
if len(clusterInfo.CSIDriverSpec.ReadAffinity.CrushLocationLabels) == 0 {
clusterInfo.CSIDriverSpec.ReadAffinity.CrushLocationLabels = strings.Split(topology.GetDefaultTopologyLabels(), ",")
}
// if the csi spec does not specify mount options, apply them from the operator env vars
if cephClusterSpec.CSI.CephFS.KernelMountOptions == "" {
clusterInfo.CSIDriverSpec.CephFS.KernelMountOptions = k8sutil.GetOperatorSetting("CSI_CEPHFS_KERNEL_MOUNT_OPTIONS", "")
}
// If an admin key was provided we don't need to load the other resources
// Some people might want to give the admin key
@@ -139,4 +139,25 @@ func TestCreateClusterSecrets(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "testid", info.CephCred.Username)
assert.Equal(t, "testkey", info.CephCred.Secret)
assert.Equal(t, "", info.CSIDriverSpec.CephFS.KernelMountOptions)
// Verify the csi settings are loaded from an env var
t.Setenv("CSI_CEPHFS_KERNEL_MOUNT_OPTIONS", "ms_mode=crc")
info, _, _, err = CreateOrLoadClusterInfo(context, ctx, namespace, ownerInfo, cephClusterSpec)
assert.NoError(t, err)
assert.Equal(t, "ms_mode=crc", info.CSIDriverSpec.CephFS.KernelMountOptions)
// Verify the csi settings are loaded from the cephClusterSpec if specified and override the env var
cephClusterSpec.CSI = cephv1.CSIDriverSpec{
ReadAffinity: cephv1.ReadAffinitySpec{
Enabled: true,
CrushLocationLabels: []string{"kubernetes.io/hostname"},
},
CephFS: cephv1.CSICephFSSpec{
KernelMountOptions: "ms_mode=secure",
},
}
info, _, _, err = CreateOrLoadClusterInfo(context, ctx, namespace, ownerInfo, cephClusterSpec)
assert.NoError(t, err)
assert.Equal(t, "ms_mode=secure", info.CSIDriverSpec.CephFS.KernelMountOptions)
}