From bc34bd389e34605885231a79c4de637fedac93e1 Mon Sep 17 00:00:00 2001 From: Seungcheol Ko Date: Fri, 20 Jul 2018 17:46:44 +0900 Subject: [PATCH] support image features for csi-rbdplugin --- deploy/rbd/kubernetes/rbd-storage-class.yaml | 2 + pkg/rbd/rbd_util.go | 43 +++++++++++++------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/deploy/rbd/kubernetes/rbd-storage-class.yaml b/deploy/rbd/kubernetes/rbd-storage-class.yaml index eb9afeef7..e1b07e56b 100644 --- a/deploy/rbd/kubernetes/rbd-storage-class.yaml +++ b/deploy/rbd/kubernetes/rbd-storage-class.yaml @@ -8,4 +8,6 @@ parameters: pool: kubernetes csiProvisionerSecretName: csi-ceph-secret csiProvisionerSecretNamespace: default + imageFormat: "2" + imageFeatures: layering reclaimPolicy: Delete diff --git a/pkg/rbd/rbd_util.go b/pkg/rbd/rbd_util.go index 58a68916d..afdcd21e5 100644 --- a/pkg/rbd/rbd_util.go +++ b/pkg/rbd/rbd_util.go @@ -27,6 +27,7 @@ import ( "time" "github.com/golang/glog" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/kubernetes/pkg/util/keymutex" ) @@ -46,17 +47,19 @@ const ( ) type rbdVolume struct { - VolName string `json:"volName"` - VolID string `json:"volID"` - Monitors string `json:"monitors"` - Pool string `json:"pool"` - ImageFormat string `json:"imageFormat"` - // TODO (sbezverk) check if it is used and how - ImageFeatures []string `json:"imageFeatures"` - VolSize int64 `json:"volSize"` + VolName string `json:"volName"` + VolID string `json:"volID"` + Monitors string `json:"monitors"` + Pool string `json:"pool"` + ImageFormat string `json:"imageFormat"` + ImageFeatures string `json:"imageFeatures"` + VolSize int64 `json:"volSize"` } -var attachdetachMutex = keymutex.NewKeyMutex() +var ( + attachdetachMutex = keymutex.NewKeyMutex() + supportedFeatures = sets.NewString("layering") +) func getRBDKey(id string, credentials map[string]string) (string, error) { @@ -87,10 +90,7 @@ func createRBDImage(pOpts *rbdVolume, volSz int, credentials map[string]string) } args := []string{"create", image, "--size", volSzGB, "--pool", pOpts.Pool, "--id", RBDUserID, "-m", mon, "--key=" + key, "--image-format", pOpts.ImageFormat} if pOpts.ImageFormat == rbdImageFormat2 { - // if no image features is provided, it results in empty string - // which disable all RBD image format 2 features as we expected - features := strings.Join(pOpts.ImageFeatures, ",") - args = append(args, "--image-feature", features) + args = append(args, "--image-feature", pOpts.ImageFeatures) } output, err = execCommand("rbd", args) @@ -187,7 +187,22 @@ func getRBDVolumeOptions(volOptions map[string]string) (*rbdVolume, error) { } rbdVol.ImageFormat, ok = volOptions["imageFormat"] if !ok { - rbdVol.ImageFormat = "2" + rbdVol.ImageFormat = rbdImageFormat2 + } + if rbdVol.ImageFormat == rbdImageFormat2 { + // if no image features is provided, it results in empty string + // which disable all RBD image format 2 features as we expected + imageFeatures, ok := volOptions["imageFeatures"] + if ok { + arr := strings.Split(imageFeatures, ",") + for _, f := range arr { + if !supportedFeatures.Has(f) { + return nil, fmt.Errorf("invalid feature %q for volume csi-rbdplugin, supported features are: %v", f, supportedFeatures) + } + } + rbdVol.ImageFeatures = imageFeatures + } + } return rbdVol, nil