From 4e5e9ca0cde963a4b607ca04f0d961659163c156 Mon Sep 17 00:00:00 2001 From: Yecheng Fu Date: Fri, 16 Jun 2017 16:29:58 +0000 Subject: [PATCH] Only `layering` RBD image format 2 feature should be supported for now. --- examples/persistent-volume-provisioning/README.md | 4 ++-- pkg/volume/rbd/BUILD | 1 + pkg/volume/rbd/rbd.go | 11 ++++++++++- pkg/volume/rbd/rbd_util.go | 9 +++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/examples/persistent-volume-provisioning/README.md b/examples/persistent-volume-provisioning/README.md index ada79f51cba..4d3f00af648 100644 --- a/examples/persistent-volume-provisioning/README.md +++ b/examples/persistent-volume-provisioning/README.md @@ -220,9 +220,9 @@ parameters: * `userId`: Ceph client ID that is used to map the RBD image. Default is the same as `adminId`. * `userSecretName`: The name of Ceph Secret for `userId` to map RBD image. It must exist in the same namespace as PVCs. It is required. * `imageFormat`: Ceph RBD image format, "1" or "2". Default is "1". -* `imageFeatures`: Ceph RBD image format 2 features, comma delimited. This is optional, and only be used if you set `imageFormat` to "2". For a complete list of available image features, please refer to [RBD docs](http://docs.ceph.com/docs/master/man/8/rbd/). By default, all features (except for striping) will be enabled. +* `imageFeatures`: Ceph RBD image format 2 features, comma delimited. This is optional, and only be used if you set `imageFormat` to "2". Currently supported features are `layering` only. Default is "", no features is turned on. -NOTE: If you want to use RBD image format 2, you may need to disable some image features, because some of them are not supported by [Ceph kernel module](https://github.com/ceph/ceph-client). For example, only "layering" feature is supported on Linux 4.9 LTS version, so you need to specify `imageFeatures` to "layering", if set `imageFormat` to "2". +NOTE: We cannot turn on `exclusive-lock` feature for now (and `object-map`, `fast-diff`, `journaling` which require `exclusive-lock`), because exclusive lock and advisory lock cannot work together. (See [#45805](https://issue.k8s.io/45805)) #### Quobyte diff --git a/pkg/volume/rbd/BUILD b/pkg/volume/rbd/BUILD index e79c795b5b3..ac71d2268d1 100644 --- a/pkg/volume/rbd/BUILD +++ b/pkg/volume/rbd/BUILD @@ -31,6 +31,7 @@ go_library( "//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/types:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library", ], ) diff --git a/pkg/volume/rbd/rbd.go b/pkg/volume/rbd/rbd.go index 25f5bd76c74..9cc7d522da7 100644 --- a/pkg/volume/rbd/rbd.go +++ b/pkg/volume/rbd/rbd.go @@ -24,6 +24,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" @@ -35,6 +36,10 @@ import ( "k8s.io/kubernetes/pkg/volume/util/volumehelper" ) +var ( + supportedFeatures = sets.NewString("layering") +) + // This is the primary entrypoint for volume plugins. func ProbeVolumePlugins() []volume.VolumePlugin { return []volume.VolumePlugin{&rbdPlugin{nil, exec.New()}} @@ -295,7 +300,11 @@ func (r *rbdVolumeProvisioner) Provision() (*v1.PersistentVolume, error) { case "imagefeatures": arr := dstrings.Split(v, ",") for _, f := range arr { - r.imageFeatures = append(r.imageFeatures, f) + if !supportedFeatures.Has(f) { + return nil, fmt.Errorf("invalid feature %q for volume plugin %s, supported features are: %v", f, r.plugin.GetPluginName(), supportedFeatures) + } else { + r.imageFeatures = append(r.imageFeatures, f) + } } default: return nil, fmt.Errorf("invalid option %q for volume plugin %s", k, r.plugin.GetPluginName()) diff --git a/pkg/volume/rbd/rbd_util.go b/pkg/volume/rbd/rbd_util.go index 9a63c8e64bd..b567d764ea8 100644 --- a/pkg/volume/rbd/rbd_util.go +++ b/pkg/volume/rbd/rbd_util.go @@ -361,10 +361,11 @@ func (util *RBDUtil) CreateImage(p *rbdVolumeProvisioner) (r *v1.RBDVolumeSource glog.V(4).Infof("rbd: create %s size %s format %s using mon %s, pool %s id %s key %s", p.rbdMounter.Image, volSz, p.rbdMounter.imageFormat, mon, p.rbdMounter.Pool, p.rbdMounter.adminId, p.rbdMounter.adminSecret) } args := []string{"create", p.rbdMounter.Image, "--size", volSz, "--pool", p.rbdMounter.Pool, "--id", p.rbdMounter.adminId, "-m", mon, "--key=" + p.rbdMounter.adminSecret, "--image-format", p.rbdMounter.imageFormat} - if p.rbdMounter.imageFormat == rbdImageFormat2 && len(p.rbdMounter.imageFeatures) > 0 { - for _, f := range p.rbdMounter.imageFeatures { - args = append(args, "--image-feature", f) - } + if p.rbdMounter.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(p.rbdMounter.imageFeatures, ",") + args = append(args, "--image-feature", features) } output, err = p.rbdMounter.plugin.execCommand("rbd", args) if err == nil {