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
370e0bec
Commit
370e0bec
authored
Aug 16, 2017
by
NickrenREN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add feature gate and validate test for local storage limitrange
parent
934087a6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
2 deletions
+71
-2
validation.go
pkg/api/validation/validation.go
+4
-0
validation_test.go
pkg/api/validation/validation_test.go
+67
-2
No files found.
pkg/api/validation/validation.go
View file @
370e0bec
...
@@ -3527,6 +3527,10 @@ func validateLimitRangeTypeName(value string, fldPath *field.Path) field.ErrorLi
...
@@ -3527,6 +3527,10 @@ func validateLimitRangeTypeName(value string, fldPath *field.Path) field.ErrorLi
// Validate limit range resource name
// Validate limit range resource name
// limit types (other than Pod/Container) could contain storage not just cpu or memory
// limit types (other than Pod/Container) could contain storage not just cpu or memory
func
validateLimitRangeResourceName
(
limitType
api
.
LimitType
,
value
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
validateLimitRangeResourceName
(
limitType
api
.
LimitType
,
value
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
if
value
==
string
(
api
.
ResourceEphemeralStorage
)
&&
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
LocalStorageCapacityIsolation
)
{
return
append
(
allErrs
,
field
.
Forbidden
(
fldPath
,
"ResourceEphemeralStorage field disabled by feature-gate for Resource LimitRange"
))
}
switch
limitType
{
switch
limitType
{
case
api
.
LimitTypePod
,
api
.
LimitTypeContainer
:
case
api
.
LimitTypePod
,
api
.
LimitTypeContainer
:
return
validateContainerResourceName
(
value
,
fldPath
)
return
validateContainerResourceName
(
value
,
fldPath
)
...
...
pkg/api/validation/validation_test.go
View file @
370e0bec
...
@@ -8609,6 +8609,71 @@ func getStorageResourceList(storage string) api.ResourceList {
...
@@ -8609,6 +8609,71 @@ func getStorageResourceList(storage string) api.ResourceList {
return
res
return
res
}
}
func
getLocalStorageResourceList
(
ephemeralStorage
string
)
api
.
ResourceList
{
res
:=
api
.
ResourceList
{}
if
ephemeralStorage
!=
""
{
res
[
api
.
ResourceEphemeralStorage
]
=
resource
.
MustParse
(
ephemeralStorage
)
}
return
res
}
func
TestValidateLimitRangeForLocalStorage
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
name
string
spec
api
.
LimitRangeSpec
}{
{
name
:
"all-fields-valid"
,
spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
{
Type
:
api
.
LimitTypePod
,
Max
:
getLocalStorageResourceList
(
"10000Mi"
),
Min
:
getLocalStorageResourceList
(
"100Mi"
),
MaxLimitRequestRatio
:
getLocalStorageResourceList
(
""
),
},
{
Type
:
api
.
LimitTypeContainer
,
Max
:
getLocalStorageResourceList
(
"10000Mi"
),
Min
:
getLocalStorageResourceList
(
"100Mi"
),
Default
:
getLocalStorageResourceList
(
"500Mi"
),
DefaultRequest
:
getLocalStorageResourceList
(
"200Mi"
),
MaxLimitRequestRatio
:
getLocalStorageResourceList
(
""
),
},
},
},
},
}
// Enable alpha feature LocalStorageCapacityIsolation
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"LocalStorageCapacityIsolation=true"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to enable feature gate for LocalStorageCapacityIsolation: %v"
,
err
)
return
}
for
_
,
testCase
:=
range
testCases
{
limitRange
:=
&
api
.
LimitRange
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
testCase
.
name
,
Namespace
:
"foo"
},
Spec
:
testCase
.
spec
}
if
errs
:=
ValidateLimitRange
(
limitRange
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"Case %v, unexpected error: %v"
,
testCase
.
name
,
errs
)
}
}
// Disable alpha feature LocalStorageCapacityIsolation
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"LocalStorageCapacityIsolation=false"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to disable feature gate for LocalStorageCapacityIsolation: %v"
,
err
)
return
}
for
_
,
testCase
:=
range
testCases
{
limitRange
:=
&
api
.
LimitRange
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
testCase
.
name
,
Namespace
:
"foo"
},
Spec
:
testCase
.
spec
}
if
errs
:=
ValidateLimitRange
(
limitRange
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"Case %v, expected feature gate unable error but actually no error"
,
testCase
.
name
)
}
}
}
func
TestValidateLimitRange
(
t
*
testing
.
T
)
{
func
TestValidateLimitRange
(
t
*
testing
.
T
)
{
successCases
:=
[]
struct
{
successCases
:=
[]
struct
{
name
string
name
string
...
@@ -8803,7 +8868,7 @@ func TestValidateLimitRange(t *testing.T) {
...
@@ -8803,7 +8868,7 @@ func TestValidateLimitRange(t *testing.T) {
}},
}},
"default value 2 is greater than max value 1"
,
"default value 2 is greater than max value 1"
,
},
},
"invalid spec defaultrequest outside range"
:
{
"invalid spec default
request outside range"
:
{
api
.
LimitRange
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
},
Spec
:
api
.
LimitRangeSpec
{
api
.
LimitRange
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
},
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
...
@@ -8816,7 +8881,7 @@ func TestValidateLimitRange(t *testing.T) {
...
@@ -8816,7 +8881,7 @@ func TestValidateLimitRange(t *testing.T) {
}},
}},
"default request value 2 is greater than max value 1"
,
"default request value 2 is greater than max value 1"
,
},
},
"invalid spec defaultrequest more than default"
:
{
"invalid spec default
request more than default"
:
{
api
.
LimitRange
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
},
Spec
:
api
.
LimitRangeSpec
{
api
.
LimitRange
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
},
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
...
...
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