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
333f6391
Commit
333f6391
authored
May 28, 2019
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apiextensions: add validation of webhook conversion & preserveUnknownFields
parent
1e559129
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
validation.go
...apiserver/pkg/apis/apiextensions/validation/validation.go
+10
-3
validation_test.go
...rver/pkg/apis/apiextensions/validation/validation_test.go
+0
-0
No files found.
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go
View file @
333f6391
...
...
@@ -121,10 +121,10 @@ func ValidateCustomResourceDefinitionVersion(version *apiextensions.CustomResour
// ValidateCustomResourceDefinitionSpec statically validates
func
ValidateCustomResourceDefinitionSpec
(
spec
*
apiextensions
.
CustomResourceDefinitionSpec
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allowDefaults
:=
utilfeature
.
DefaultFeatureGate
.
Enabled
(
apiextensionsfeatures
.
CustomResourceDefaulting
)
return
validateCustomResourceDefinitionSpec
(
spec
,
true
,
allowDefaults
,
fldPath
)
return
validateCustomResourceDefinitionSpec
(
spec
,
true
,
allowDefaults
,
f
alse
,
f
ldPath
)
}
func
validateCustomResourceDefinitionSpec
(
spec
*
apiextensions
.
CustomResourceDefinitionSpec
,
requireRecognizedVersion
,
allowDefaults
bool
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
validateCustomResourceDefinitionSpec
(
spec
*
apiextensions
.
CustomResourceDefinitionSpec
,
requireRecognizedVersion
,
allowDefaults
,
allowConversionWithPreserveUnknownFields
bool
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
if
len
(
spec
.
Group
)
==
0
{
...
...
@@ -237,11 +237,18 @@ func validateCustomResourceDefinitionSpec(spec *apiextensions.CustomResourceDefi
}
}
if
!
allowConversionWithPreserveUnknownFields
&&
conversionAndPreserveUnknownFields
(
spec
)
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"conversion"
)
.
Child
(
"strategy"
),
spec
.
Conversion
.
Strategy
,
"must be None if spec.preserveUnknownFields is true"
))
}
allErrs
=
append
(
allErrs
,
validateCustomResourceConversion
(
spec
.
Conversion
,
requireRecognizedVersion
,
fldPath
.
Child
(
"conversion"
))
...
)
return
allErrs
}
func
conversionAndPreserveUnknownFields
(
spec
*
apiextensions
.
CustomResourceDefinitionSpec
)
bool
{
return
(
spec
.
Conversion
!=
nil
&&
spec
.
Conversion
.
Strategy
!=
apiextensions
.
NoneConverter
)
&&
(
spec
.
PreserveUnknownFields
==
nil
||
*
spec
.
PreserveUnknownFields
)
}
func
validateEnumStrings
(
fldPath
*
field
.
Path
,
value
string
,
accepted
[]
string
,
required
bool
)
field
.
ErrorList
{
if
value
==
""
{
if
required
{
...
...
@@ -359,7 +366,7 @@ func ValidateCustomResourceDefinitionSpecUpdate(spec, oldSpec *apiextensions.Cus
// find out whether any schema had default before. Then we keep allowing it.
allowDefaults
:=
utilfeature
.
DefaultFeatureGate
.
Enabled
(
apiextensionsfeatures
.
CustomResourceDefaulting
)
||
specHasDefaults
(
oldSpec
)
allErrs
:=
validateCustomResourceDefinitionSpec
(
spec
,
requireRecognizedVersion
,
allowDefaults
,
fldPath
)
allErrs
:=
validateCustomResourceDefinitionSpec
(
spec
,
requireRecognizedVersion
,
allowDefaults
,
conversionAndPreserveUnknownFields
(
oldSpec
),
fldPath
)
if
established
{
// these effect the storage and cannot be changed therefore
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation_test.go
View file @
333f6391
This diff is collapsed.
Click to expand it.
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