Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
6ec1ebd6
Commit
6ec1ebd6
authored
Sep 07, 2018
by
Xing Yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make APIGroup optional and modify validation
parent
ae8a0469
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
11 deletions
+27
-11
types.go
pkg/apis/core/types.go
+5
-2
validation.go
pkg/apis/core/validation/validation.go
+16
-6
validation_test.go
pkg/apis/core/validation/validation_test.go
+1
-1
types.go
staging/src/k8s.io/api/core/v1/types.go
+5
-2
No files found.
pkg/apis/core/types.go
View file @
6ec1ebd6
...
@@ -3976,8 +3976,11 @@ type LocalObjectReference struct {
...
@@ -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
...
...
pkg/apis/core/validation/validation.go
View file @
6ec1ebd6
...
@@ -36,6 +36,7 @@ import (
...
@@ -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
...
@@ -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
...
@@ -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
))
}
}
}
}
...
...
pkg/apis/core/validation/validation_test.go
View file @
6ec1ebd6
...
@@ -726,7 +726,7 @@ func testVolumeSnapshotDataSourceInSpec(name string, kind string, apiGroup strin
...
@@ -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
,
},
},
...
...
staging/src/k8s.io/api/core/v1/types.go
View file @
6ec1ebd6
...
@@ -4495,8 +4495,11 @@ type LocalObjectReference struct {
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment