Merge pull request #45805 from weiwei04/ceph-imageformat-2
Automatic merge from submit-queue storageclass ceph add imageformat parameter **What this PR does / why we need it**: Add a imageformat parameter for StorageClass(ceph rbd) k8s hard coded ceph imageformat 1, according to [ceph manual](http://docs.ceph.com/docs/master/man/8/rbd/), imageformat 1 was deprecated, we should add an extra ceph parameter to set ceph rbd imageformat. Ceph rbd imageformat can only be 1 or 2, set the default value to 1. **Release note**: ```release-note Allow StorageClass Ceph RBD to specify image format and image features. ```
This commit is contained in:
@@ -25,6 +25,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/client/clientset_generated/clientset"
|
||||
"k8s.io/kubernetes/pkg/util/exec"
|
||||
@@ -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()}}
|
||||
@@ -51,8 +56,10 @@ var _ volume.DeletableVolumePlugin = &rbdPlugin{}
|
||||
var _ volume.ProvisionableVolumePlugin = &rbdPlugin{}
|
||||
|
||||
const (
|
||||
rbdPluginName = "kubernetes.io/rbd"
|
||||
secretKeyName = "key" // key name used in secret
|
||||
rbdPluginName = "kubernetes.io/rbd"
|
||||
secretKeyName = "key" // key name used in secret
|
||||
rbdImageFormat1 = "1"
|
||||
rbdImageFormat2 = "2"
|
||||
)
|
||||
|
||||
func (plugin *rbdPlugin) Init(host volume.VolumeHost) error {
|
||||
@@ -267,6 +274,7 @@ func (r *rbdVolumeProvisioner) Provision() (*v1.PersistentVolume, error) {
|
||||
adminSecretNamespace := "default"
|
||||
secretName := ""
|
||||
secret := ""
|
||||
imageFormat := rbdImageFormat1
|
||||
|
||||
for k, v := range r.options.Parameters {
|
||||
switch dstrings.ToLower(k) {
|
||||
@@ -287,11 +295,27 @@ func (r *rbdVolumeProvisioner) Provision() (*v1.PersistentVolume, error) {
|
||||
r.Pool = v
|
||||
case "usersecretname":
|
||||
secretName = v
|
||||
case "imageformat":
|
||||
imageFormat = v
|
||||
case "imagefeatures":
|
||||
arr := dstrings.Split(v, ",")
|
||||
for _, f := range arr {
|
||||
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())
|
||||
}
|
||||
}
|
||||
// sanity check
|
||||
if imageFormat != rbdImageFormat1 && imageFormat != rbdImageFormat2 {
|
||||
return nil, fmt.Errorf("invalid ceph imageformat %s, expecting %s or %s",
|
||||
imageFormat, rbdImageFormat1, rbdImageFormat2)
|
||||
}
|
||||
r.imageFormat = imageFormat
|
||||
if adminSecretName == "" {
|
||||
return nil, fmt.Errorf("missing Ceph admin secret name")
|
||||
}
|
||||
@@ -376,14 +400,16 @@ func (rbd *rbd) GetPath() string {
|
||||
type rbdMounter struct {
|
||||
*rbd
|
||||
// capitalized so they can be exported in persistRBD()
|
||||
Mon []string
|
||||
Id string
|
||||
Keyring string
|
||||
Secret string
|
||||
fsType string
|
||||
adminSecret string
|
||||
adminId string
|
||||
mountOptions []string
|
||||
Mon []string
|
||||
Id string
|
||||
Keyring string
|
||||
Secret string
|
||||
fsType string
|
||||
adminSecret string
|
||||
adminId string
|
||||
mountOptions []string
|
||||
imageFormat string
|
||||
imageFeatures []string
|
||||
}
|
||||
|
||||
var _ volume.Mounter = &rbdMounter{}
|
||||
|
||||
Reference in New Issue
Block a user