mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
Merge pull request #51 from sngchlko/support-image-features
support image features for csi-rbdplugin
This commit is contained in:
commit
9adf908d38
@ -8,4 +8,6 @@ parameters:
|
|||||||
pool: kubernetes
|
pool: kubernetes
|
||||||
csiProvisionerSecretName: csi-ceph-secret
|
csiProvisionerSecretName: csi-ceph-secret
|
||||||
csiProvisionerSecretNamespace: default
|
csiProvisionerSecretNamespace: default
|
||||||
|
imageFormat: "2"
|
||||||
|
imageFeatures: layering
|
||||||
reclaimPolicy: Delete
|
reclaimPolicy: Delete
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/kubernetes/pkg/util/keymutex"
|
"k8s.io/kubernetes/pkg/util/keymutex"
|
||||||
)
|
)
|
||||||
@ -51,12 +52,14 @@ type rbdVolume struct {
|
|||||||
Monitors string `json:"monitors"`
|
Monitors string `json:"monitors"`
|
||||||
Pool string `json:"pool"`
|
Pool string `json:"pool"`
|
||||||
ImageFormat string `json:"imageFormat"`
|
ImageFormat string `json:"imageFormat"`
|
||||||
// TODO (sbezverk) check if it is used and how
|
ImageFeatures string `json:"imageFeatures"`
|
||||||
ImageFeatures []string `json:"imageFeatures"`
|
|
||||||
VolSize int64 `json:"volSize"`
|
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) {
|
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}
|
args := []string{"create", image, "--size", volSzGB, "--pool", pOpts.Pool, "--id", RBDUserID, "-m", mon, "--key=" + key, "--image-format", pOpts.ImageFormat}
|
||||||
if pOpts.ImageFormat == rbdImageFormat2 {
|
if pOpts.ImageFormat == rbdImageFormat2 {
|
||||||
// if no image features is provided, it results in empty string
|
args = append(args, "--image-feature", pOpts.ImageFeatures)
|
||||||
// which disable all RBD image format 2 features as we expected
|
|
||||||
features := strings.Join(pOpts.ImageFeatures, ",")
|
|
||||||
args = append(args, "--image-feature", features)
|
|
||||||
}
|
}
|
||||||
output, err = execCommand("rbd", args)
|
output, err = execCommand("rbd", args)
|
||||||
|
|
||||||
@ -187,7 +187,22 @@ func getRBDVolumeOptions(volOptions map[string]string) (*rbdVolume, error) {
|
|||||||
}
|
}
|
||||||
rbdVol.ImageFormat, ok = volOptions["imageFormat"]
|
rbdVol.ImageFormat, ok = volOptions["imageFormat"]
|
||||||
if !ok {
|
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
|
return rbdVol, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user