From 30a5d9a6e7a28cdfadb51d1926d48eb3991fc176 Mon Sep 17 00:00:00 2001 From: Huamin Chen Date: Tue, 18 Sep 2018 14:09:12 +0000 Subject: [PATCH] add rbd-nbd mounter in storage class Signed-off-by: Huamin Chen --- examples/rbd/storageclass.yaml | 2 ++ pkg/rbd/rbd_attach.go | 11 +++++++---- pkg/rbd/rbd_util.go | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/rbd/storageclass.yaml b/examples/rbd/storageclass.yaml index e1a8a06ba..7535e2e01 100644 --- a/examples/rbd/storageclass.yaml +++ b/examples/rbd/storageclass.yaml @@ -25,4 +25,6 @@ parameters: # Ceph users for operating RBD adminid: admin userid: kubernetes + # uncomment the following to use rbd-nbd as mounter on supported nodes + #mounter: rbd-nbd reclaimPolicy: Delete diff --git a/pkg/rbd/rbd_attach.go b/pkg/rbd/rbd_attach.go index 9418af2eb..6385db81a 100644 --- a/pkg/rbd/rbd_attach.go +++ b/pkg/rbd/rbd_attach.go @@ -35,7 +35,7 @@ const ( var ( hostRootFS = "/" - useNBD = false + hasNBD = false ) func init() { @@ -43,7 +43,7 @@ func init() { if len(host) > 0 { hostRootFS = host } - useNBD = checkRbdNbdTools() + hasNBD = checkRbdNbdTools() } func getDevFromImageAndPool(pool, image string) (string, bool) { @@ -226,12 +226,15 @@ func attachRBDImage(volOptions *rbdVolume, userId string, credentials map[string image := volOptions.VolName imagePath := fmt.Sprintf("%s/%s", volOptions.Pool, image) + useNBD := false cmdName := "rbd" moduleName := "rbd" - if useNBD { + if volOptions.Mounter == "rbd-nbd" && hasNBD { + useNBD = true cmdName = "rbd-nbd" moduleName = "nbd" } + devicePath, found := waitForPath(volOptions.Pool, image, 1, useNBD) if !found { attachdetachMutex.LockKey(string(imagePath)) @@ -258,7 +261,7 @@ func attachRBDImage(volOptions *rbdVolume, userId string, credentials map[string if err == wait.ErrWaitTimeout { return "", fmt.Errorf("rbd image %s is still being used", imagePath) } - // return error if any other errors were encountered during wating for the image to becme avialble + // return error if any other errors were encountered during wating for the image to become available if err != nil { return "", err } diff --git a/pkg/rbd/rbd_util.go b/pkg/rbd/rbd_util.go index 93ff3c431..eaea663d7 100644 --- a/pkg/rbd/rbd_util.go +++ b/pkg/rbd/rbd_util.go @@ -42,6 +42,7 @@ const ( rbdImageWatcherInitDelay = 1 * time.Second rbdImageWatcherFactor = 1.4 rbdImageWatcherSteps = 10 + rbdDefaultMounter = "rbd" ) type rbdVolume struct { @@ -54,6 +55,7 @@ type rbdVolume struct { VolSize int64 `json:"volSize"` AdminId string `json:"adminId"` UserId string `json:"userId"` + Mounter string `json:"mounter"` } type rbdSnapshot struct { @@ -226,6 +228,10 @@ func getRBDVolumeOptions(volOptions map[string]string) (*rbdVolume, error) { if !ok { rbdVol.UserId = rbdDefaultUserId } + rbdVol.Mounter, ok = volOptions["mounter"] + if !ok { + rbdVol.Mounter = rbdDefaultMounter + } return rbdVol, nil }