mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +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.
|
||||
type TypedLocalObjectReference struct {
|
||||
// APIGroup is the group for the resource being referenced
|
||||
APIGroup string
|
||||
// APIGroup is the group for the resource being referenced.
|
||||
// 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 string
|
||||
// Name is the name of resource being referenced
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -726,7 +726,7 @@ func testVolumeSnapshotDataSourceInSpec(name string, kind string, apiGroup strin
|
||||
},
|
||||
StorageClassName: &scName,
|
||||
DataSource: &core.TypedLocalObjectReference{
|
||||
APIGroup: apiGroup,
|
||||
APIGroup: &apiGroup,
|
||||
Kind: kind,
|
||||
Name: name,
|
||||
},
|
||||
|
@ -4495,8 +4495,11 @@ type LocalObjectReference struct {
|
||||
// TypedLocalObjectReference contains enough information to let you locate the
|
||||
// typed referenced object inside the same namespace.
|
||||
type TypedLocalObjectReference struct {
|
||||
// APIGroup is the group for the resource being referenced
|
||||
APIGroup string `json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup"`
|
||||
// APIGroup is the group for the resource being referenced.
|
||||
// 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 string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
|
||||
// Name is the name of resource being referenced
|
||||
|
Loading…
Reference in New Issue
Block a user