cephfs: upgrading mount syntax

The old syntax is almost deprecated,and there are reasons to upgrade it
- old syntax is lack of fsid(critical for debugging and observability)
- mds_namespace is deprecated, it might be inappropriate to continue using it
- kernel will try new syntax first and then the old one, it's a waste

Signed-off-by: mageekchiu <qiukang@mail.ustc.edu.cn>
This commit is contained in:
mageekchiu 2025-03-09 18:58:55 +08:00 committed by mergify[bot]
parent 91baf7681d
commit 0c60fd28ea
3 changed files with 46 additions and 20 deletions

View File

@ -482,14 +482,6 @@ var _ = Describe(cephfsType, func() {
}
})
By("check static PVC with without FsName", func() {
scPath := cephFSExamplePath + "secret.yaml"
err := validateCephFsStaticPV(f, appPath, scPath, "")
if err != nil {
framework.Failf("failed to validate CephFS static pv without filesystem name: %v", err)
}
})
By("create a storageclass with pool and a PVC then bind it to an app", func() {
err := createCephfsStorageClass(f.ClientSet, f, true, nil)
if err != nil {

View File

@ -72,25 +72,24 @@ func (m *kernelMounter) mountKernel(
m.needsModprobe = false
}
fsID, err := volOptions.GetFSID()
if err != nil {
return fmt.Errorf("failed to get fsID, stop mounting: %w", err)
}
args := []string{
"-t", "ceph",
fmt.Sprintf("%s:%s", volOptions.Monitors, volOptions.RootPath),
fmt.Sprintf("%s@%s.%s=%s", cr.ID, fsID, volOptions.FsName, volOptions.RootPath),
mountPoint,
}
optionsStr := fmt.Sprintf("name=%s,secretfile=%s", cr.ID, cr.KeyFile)
mdsNamespace := ""
if volOptions.FsName != "" {
mdsNamespace = "mds_namespace=" + volOptions.FsName
}
optionsStr = util.MountOptionsAdd(optionsStr, mdsNamespace, volOptions.KernelMountOptions, netDev)
optionsStr := fmt.Sprintf("mon_addr=%s,secretfile=%s", strings.ReplaceAll(volOptions.Monitors, ",", "/"), cr.KeyFile)
optionsStr = util.MountOptionsAdd(optionsStr, volOptions.KernelMountOptions, netDev)
args = append(args, "-o", optionsStr)
var (
stderr string
err error
)
var stderr string
if volOptions.NetNamespaceFilePath != "" {
_, stderr, err = util.ExecuteCommandWithNSEnter(ctx, volOptions.NetNamespaceFilePath, "mount", args[:]...)

View File

@ -103,6 +103,19 @@ func (vo *VolumeOptions) Destroy() {
}
}
func (vo *VolumeOptions) GetFSID() (string, error) {
if vo.conn == nil {
return "", errors.New("cluster not connected yet")
}
fsID, err := vo.conn.GetFSID()
if err != nil {
return "", err
}
return fsID, nil
}
func validateNonEmptyField(field, fieldName string) error {
if field == "" {
return fmt.Errorf("parameter '%s' cannot be empty", fieldName)
@ -682,6 +695,17 @@ func NewVolumeOptionsFromMonitorList(
opts.BackingSnapshot = true
}
cr, err := util.NewAdminCredentials(secrets)
if err != nil {
return nil, nil, err
}
defer cr.DeleteCredentials()
err = opts.Connect(cr)
if err != nil {
return nil, nil, err
}
return &opts, &vid, nil
}
@ -730,7 +754,7 @@ func NewVolumeOptionsFromStaticVolume(
return nil, nil, err
}
if err = extractOptionalOption(&opts.FsName, "fsName", options); err != nil {
if err = extractOption(&opts.FsName, "fsName", options); err != nil {
return nil, nil, err
}
@ -761,6 +785,17 @@ func NewVolumeOptionsFromStaticVolume(
opts.BackingSnapshot = true
}
cr, err := util.NewAdminCredentials(secrets)
if err != nil {
return nil, nil, err
}
defer cr.DeleteCredentials()
err = opts.Connect(cr)
if err != nil {
return nil, nil, err
}
return &opts, &vid, nil
}