Merge pull request #51 from sngchlko/support-image-features

support image features for csi-rbdplugin
This commit is contained in:
Huamin Chen 2018-07-20 18:18:43 -04:00 committed by GitHub
commit 9adf908d38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 14 deletions

View File

@ -8,4 +8,6 @@ parameters:
pool: kubernetes
csiProvisionerSecretName: csi-ceph-secret
csiProvisionerSecretNamespace: default
imageFormat: "2"
imageFeatures: layering
reclaimPolicy: Delete

View File

@ -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