mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
rbd: provide a way to supply mounter specific mapOptions from sc
Uses the below schema to supply mounter specific map/unmapOptions to the nodeplugin based on the discussion we all had at https://github.com/ceph/ceph-csi/pull/2636 This should specifically be really helpful with the `tryOthermonters` set to true, i.e with fallback mechanism settings turned ON. mapOption: "kbrd:v1,v2,v3;nbd:v1,v2,v3" - By omitting `krbd:` or `nbd:`, the option(s) apply to rbdDefaultMounter which is krbd. - A user can _override_ the options for a mounter by specifying `krbd:` or `nbd:`. mapOption: "v1,v2,v3;nbd:v1,v2,v3" is effectively the same as the 1st example. - Sections are split by `;`. - If users want to specify common options for both `krbd` and `nbd`, they should mention them twice. Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
b2099eb3b1
commit
bdcf3273b5
@ -29,6 +29,7 @@ import (
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
)
|
||||
|
||||
@ -222,6 +223,65 @@ func setRbdNbdToolFeatures() {
|
||||
log.DefaultLog("NBD module loaded: %t, rbd-nbd supported features, cookie: %t", hasNBD, hasNBDCookieSupport)
|
||||
}
|
||||
|
||||
// parseMapOptions helps parse formatted mapOptions and unmapOptions and
|
||||
// returns mounter specific options.
|
||||
func parseMapOptions(mapOptions string) (string, string, error) {
|
||||
var krbdMapOptions, nbdMapOptions string
|
||||
const (
|
||||
noKeyLength = 1
|
||||
validLength = 2
|
||||
)
|
||||
for _, item := range strings.Split(mapOptions, ";") {
|
||||
var mounter, options string
|
||||
if item == "" {
|
||||
continue
|
||||
}
|
||||
s := strings.Split(item, ":")
|
||||
switch len(s) {
|
||||
case noKeyLength:
|
||||
options = strings.TrimSpace(s[0])
|
||||
krbdMapOptions = options
|
||||
case validLength:
|
||||
mounter = strings.TrimSpace(s[0])
|
||||
options = strings.TrimSpace(s[1])
|
||||
switch strings.ToLower(mounter) {
|
||||
case accessTypeKRbd:
|
||||
krbdMapOptions = options
|
||||
case accessTypeNbd:
|
||||
nbdMapOptions = options
|
||||
default:
|
||||
return "", "", fmt.Errorf("unknown mounter type: %q", mounter)
|
||||
}
|
||||
default:
|
||||
return "", "", fmt.Errorf("badly formatted map/unmap options: %q", mapOptions)
|
||||
}
|
||||
}
|
||||
|
||||
return krbdMapOptions, nbdMapOptions, nil
|
||||
}
|
||||
|
||||
// getMapOptions is a wrapper func, calls parse map/unmap funcs and feeds the
|
||||
// rbdVolume object.
|
||||
func getMapOptions(req *csi.NodeStageVolumeRequest, rv *rbdVolume) error {
|
||||
krbdMapOptions, nbdMapOptions, err := parseMapOptions(req.GetVolumeContext()["mapOptions"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
krbdUnmapOptions, nbdUnmapOptions, err := parseMapOptions(req.GetVolumeContext()["unmapOptions"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rv.Mounter == rbdDefaultMounter {
|
||||
rv.MapOptions = krbdMapOptions
|
||||
rv.UnmapOptions = krbdUnmapOptions
|
||||
} else if rv.Mounter == rbdNbdMounter {
|
||||
rv.MapOptions = nbdMapOptions
|
||||
rv.UnmapOptions = nbdUnmapOptions
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachRBDImage(ctx context.Context, volOptions *rbdVolume, device string, cr *util.Credentials) (string, error) {
|
||||
var err error
|
||||
|
||||
|
Reference in New Issue
Block a user