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
e4034e2b
Commit
e4034e2b
authored
Aug 23, 2018
by
Xing Yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add validation for feature gate
parent
34f62ae4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
0 deletions
+77
-0
validation.go
pkg/apis/core/validation/validation.go
+16
-0
validation_test.go
pkg/apis/core/validation/validation_test.go
+61
-0
No files found.
pkg/apis/core/validation/validation.go
View file @
e4034e2b
...
...
@@ -1824,6 +1824,22 @@ func ValidatePersistentVolumeClaimSpec(spec *core.PersistentVolumeClaimSpec, fld
}
else
if
spec
.
VolumeMode
!=
nil
&&
!
supportedVolumeModes
.
Has
(
string
(
*
spec
.
VolumeMode
))
{
allErrs
=
append
(
allErrs
,
field
.
NotSupported
(
fldPath
.
Child
(
"volumeMode"
),
*
spec
.
VolumeMode
,
supportedVolumeModes
.
List
()))
}
if
spec
.
DataSource
!=
nil
&&
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
VolumeSnapshotDataSource
)
{
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
fldPath
.
Child
(
"dataSource"
),
"VolumeSnapshotDataSource is disabled by feature-gate"
))
spec
.
DataSource
=
nil
}
else
if
spec
.
DataSource
!=
nil
{
if
len
(
spec
.
DataSource
.
Name
)
==
0
{
allErrs
=
append
(
allErrs
,
field
.
Required
(
fldPath
.
Child
(
"dataSource"
)
.
Key
(
string
(
"Name"
)),
"VolumeSnapshotDataSource Name cannot be empty"
))
}
if
spec
.
DataSource
.
Kind
!=
"VolumeSnapshot"
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"dataSource"
),
spec
.
DataSource
.
Kind
,
"expected DataSource Kind is VolumeSnapshot"
))
}
if
spec
.
DataSource
.
APIGroup
!=
"snapshot.storage.k8s.io"
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"dataSource"
),
spec
.
DataSource
.
APIGroup
,
"expected DataSource APIGroup is snapshot.storage.k8s.io"
))
}
}
return
allErrs
}
...
...
pkg/apis/core/validation/validation_test.go
View file @
e4034e2b
...
...
@@ -713,6 +713,67 @@ func testVolumeClaimStorageClassInSpec(name, namespace, scName string, spec core
}
}
func
testVolumeSnapshotDataSourceInSpec
(
name
string
,
kind
string
,
apiGroup
string
)
*
core
.
PersistentVolumeClaimSpec
{
scName
:=
"csi-plugin"
dataSourceInSpec
:=
core
.
PersistentVolumeClaimSpec
{
AccessModes
:
[]
core
.
PersistentVolumeAccessMode
{
core
.
ReadOnlyMany
,
},
Resources
:
core
.
ResourceRequirements
{
Requests
:
core
.
ResourceList
{
core
.
ResourceName
(
core
.
ResourceStorage
)
:
resource
.
MustParse
(
"10G"
),
},
},
StorageClassName
:
&
scName
,
DataSource
:
&
core
.
TypedLocalObjectReference
{
APIGroup
:
apiGroup
,
Kind
:
kind
,
Name
:
name
,
},
}
return
&
dataSourceInSpec
}
func
TestAlphaVolumeSnapshotDataSource
(
t
*
testing
.
T
)
{
successTestCases
:=
[]
core
.
PersistentVolumeClaimSpec
{
*
testVolumeSnapshotDataSourceInSpec
(
"test_snapshot"
,
"VolumeSnapshot"
,
"snapshot.storage.k8s.io"
),
}
failedTestCases
:=
[]
core
.
PersistentVolumeClaimSpec
{
*
testVolumeSnapshotDataSourceInSpec
(
""
,
"VolumeSnapshot"
,
"snapshot.storage.k8s.io"
),
*
testVolumeSnapshotDataSourceInSpec
(
"test_snapshot"
,
"PersistentVolumeClaim"
,
"snapshot.storage.k8s.io"
),
*
testVolumeSnapshotDataSourceInSpec
(
"test_snapshot"
,
"VolumeSnapshot"
,
"storage.k8s.io"
),
}
// Enable alpha feature VolumeSnapshotDataSource
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeSnapshotDataSource=true"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to enable feature gate for VolumeSnapshotDataSource: %v"
,
err
)
return
}
for
_
,
tc
:=
range
successTestCases
{
if
errs
:=
ValidatePersistentVolumeClaimSpec
(
&
tc
,
field
.
NewPath
(
"spec"
));
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
}
}
for
_
,
tc
:=
range
failedTestCases
{
if
errs
:=
ValidatePersistentVolumeClaimSpec
(
&
tc
,
field
.
NewPath
(
"spec"
));
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure: %v"
,
errs
)
}
}
// Disable alpha feature VolumeSnapshotDataSource
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeSnapshotDataSource=false"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to disable feature gate for VolumeSnapshotDataSource: %v"
,
err
)
return
}
for
_
,
tc
:=
range
successTestCases
{
if
errs
:=
ValidatePersistentVolumeClaimSpec
(
&
tc
,
field
.
NewPath
(
"spec"
));
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure: %v"
,
errs
)
}
}
}
func
testVolumeClaimStorageClassInAnnotationAndSpec
(
name
,
namespace
,
scNameInAnn
,
scName
string
,
spec
core
.
PersistentVolumeClaimSpec
)
*
core
.
PersistentVolumeClaim
{
spec
.
StorageClassName
=
&
scName
return
&
core
.
PersistentVolumeClaim
{
...
...
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