Make APIGroup optional and modify validation
This commit is contained in:
@@ -36,6 +36,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
unversionedvalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
@@ -1501,8 +1502,9 @@ var supportedReclaimPolicy = sets.NewString(string(core.PersistentVolumeReclaimD
|
||||
|
||||
var supportedVolumeModes = sets.NewString(string(core.PersistentVolumeBlock), string(core.PersistentVolumeFilesystem))
|
||||
|
||||
var supportedDataSourceKinds = sets.NewString(string("VolumeSnapshot"))
|
||||
var supportedDataSourceAPIGroups = sets.NewString(string("snapshot.storage.k8s.io"))
|
||||
var supportedDataSourceAPIGroupKinds = map[schema.GroupKind]bool{
|
||||
{Group: "snapshot.storage.k8s.io", Kind: "VolumeSnapshot"}: true,
|
||||
}
|
||||
|
||||
func ValidatePersistentVolume(pv *core.PersistentVolume) field.ErrorList {
|
||||
metaPath := field.NewPath("metadata")
|
||||
@@ -1833,10 +1835,18 @@ func ValidatePersistentVolumeClaimSpec(spec *core.PersistentVolumeClaimSpec, fld
|
||||
} else if spec.DataSource != nil {
|
||||
if len(spec.DataSource.Name) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("dataSource", "name"), ""))
|
||||
} else if !supportedDataSourceKinds.Has(string(spec.DataSource.Kind)) {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("dataSource"), spec.DataSource.Kind, supportedDataSourceKinds.List()))
|
||||
} else if !supportedDataSourceAPIGroups.Has(string(spec.DataSource.APIGroup)) {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("dataSource"), spec.DataSource.APIGroup, supportedDataSourceAPIGroups.List()))
|
||||
}
|
||||
|
||||
groupKind := schema.GroupKind{Group: "", Kind: spec.DataSource.Kind}
|
||||
if spec.DataSource.APIGroup != nil {
|
||||
groupKind.Group = string(*spec.DataSource.APIGroup)
|
||||
}
|
||||
groupKindList := make([]string, 0, len(supportedDataSourceAPIGroupKinds))
|
||||
for grp := range supportedDataSourceAPIGroupKinds {
|
||||
groupKindList = append(groupKindList, grp.String())
|
||||
}
|
||||
if !supportedDataSourceAPIGroupKinds[groupKind] {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("dataSource"), groupKind.String(), groupKindList))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user