mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Make APIGroup optional and modify validation
This commit is contained in:
parent
ae8a046985
commit
6ec1ebd6ce
@ -3976,8 +3976,11 @@ type LocalObjectReference struct {
|
|||||||
|
|
||||||
// TypedLocalObjectReference contains enough information to let you locate the typed referenced object inside the same namespace.
|
// TypedLocalObjectReference contains enough information to let you locate the typed referenced object inside the same namespace.
|
||||||
type TypedLocalObjectReference struct {
|
type TypedLocalObjectReference struct {
|
||||||
// APIGroup is the group for the resource being referenced
|
// APIGroup is the group for the resource being referenced.
|
||||||
APIGroup string
|
// If APIGroup is not specified, the specified Kind must be in the core API group.
|
||||||
|
// For any other third-party types, APIGroup is required.
|
||||||
|
// +optional
|
||||||
|
APIGroup *string
|
||||||
// Kind is the type of resource being referenced
|
// Kind is the type of resource being referenced
|
||||||
Kind string
|
Kind string
|
||||||
// Name is the name of resource being referenced
|
// Name is the name of resource being referenced
|
||||||
|
@ -36,6 +36,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
unversionedvalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
unversionedvalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"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 supportedVolumeModes = sets.NewString(string(core.PersistentVolumeBlock), string(core.PersistentVolumeFilesystem))
|
||||||
|
|
||||||
var supportedDataSourceKinds = sets.NewString(string("VolumeSnapshot"))
|
var supportedDataSourceAPIGroupKinds = map[schema.GroupKind]bool{
|
||||||
var supportedDataSourceAPIGroups = sets.NewString(string("snapshot.storage.k8s.io"))
|
{Group: "snapshot.storage.k8s.io", Kind: "VolumeSnapshot"}: true,
|
||||||
|
}
|
||||||
|
|
||||||
func ValidatePersistentVolume(pv *core.PersistentVolume) field.ErrorList {
|
func ValidatePersistentVolume(pv *core.PersistentVolume) field.ErrorList {
|
||||||
metaPath := field.NewPath("metadata")
|
metaPath := field.NewPath("metadata")
|
||||||
@ -1833,10 +1835,18 @@ func ValidatePersistentVolumeClaimSpec(spec *core.PersistentVolumeClaimSpec, fld
|
|||||||
} else if spec.DataSource != nil {
|
} else if spec.DataSource != nil {
|
||||||
if len(spec.DataSource.Name) == 0 {
|
if len(spec.DataSource.Name) == 0 {
|
||||||
allErrs = append(allErrs, field.Required(fldPath.Child("dataSource", "name"), ""))
|
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)) {
|
groupKind := schema.GroupKind{Group: "", Kind: spec.DataSource.Kind}
|
||||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child("dataSource"), spec.DataSource.APIGroup, supportedDataSourceAPIGroups.List()))
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -726,7 +726,7 @@ func testVolumeSnapshotDataSourceInSpec(name string, kind string, apiGroup strin
|
|||||||
},
|
},
|
||||||
StorageClassName: &scName,
|
StorageClassName: &scName,
|
||||||
DataSource: &core.TypedLocalObjectReference{
|
DataSource: &core.TypedLocalObjectReference{
|
||||||
APIGroup: apiGroup,
|
APIGroup: &apiGroup,
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
Name: name,
|
Name: name,
|
||||||
},
|
},
|
||||||
|
@ -4495,8 +4495,11 @@ type LocalObjectReference struct {
|
|||||||
// TypedLocalObjectReference contains enough information to let you locate the
|
// TypedLocalObjectReference contains enough information to let you locate the
|
||||||
// typed referenced object inside the same namespace.
|
// typed referenced object inside the same namespace.
|
||||||
type TypedLocalObjectReference struct {
|
type TypedLocalObjectReference struct {
|
||||||
// APIGroup is the group for the resource being referenced
|
// APIGroup is the group for the resource being referenced.
|
||||||
APIGroup string `json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup"`
|
// If APIGroup is not specified, the specified Kind must be in the core API group.
|
||||||
|
// For any other third-party types, APIGroup is required.
|
||||||
|
// +optional
|
||||||
|
APIGroup *string `json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup"`
|
||||||
// Kind is the type of resource being referenced
|
// Kind is the type of resource being referenced
|
||||||
Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
|
Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
|
||||||
// Name is the name of resource being referenced
|
// Name is the name of resource being referenced
|
||||||
|
Loading…
Reference in New Issue
Block a user