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
bc393e3f
Commit
bc393e3f
authored
Aug 16, 2017
by
NickrenREN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add feature gate for local storage quota
parent
a3c180e5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
0 deletions
+72
-0
helpers.go
pkg/api/helper/helpers.go
+3
-0
validation.go
pkg/api/validation/validation.go
+13
-0
validation_test.go
pkg/api/validation/validation_test.go
+56
-0
No files found.
pkg/api/helper/helpers.go
View file @
bc393e3f
...
@@ -170,11 +170,14 @@ func IsStandardLimitRangeType(str string) bool {
...
@@ -170,11 +170,14 @@ func IsStandardLimitRangeType(str string) bool {
var
standardQuotaResources
=
sets
.
NewString
(
var
standardQuotaResources
=
sets
.
NewString
(
string
(
api
.
ResourceCPU
),
string
(
api
.
ResourceCPU
),
string
(
api
.
ResourceMemory
),
string
(
api
.
ResourceMemory
),
string
(
api
.
ResourceEphemeralStorage
),
string
(
api
.
ResourceRequestsCPU
),
string
(
api
.
ResourceRequestsCPU
),
string
(
api
.
ResourceRequestsMemory
),
string
(
api
.
ResourceRequestsMemory
),
string
(
api
.
ResourceRequestsStorage
),
string
(
api
.
ResourceRequestsStorage
),
string
(
api
.
ResourceRequestsEphemeralStorage
),
string
(
api
.
ResourceLimitsCPU
),
string
(
api
.
ResourceLimitsCPU
),
string
(
api
.
ResourceLimitsMemory
),
string
(
api
.
ResourceLimitsMemory
),
string
(
api
.
ResourceLimitsEphemeralStorage
),
string
(
api
.
ResourcePods
),
string
(
api
.
ResourcePods
),
string
(
api
.
ResourceQuotas
),
string
(
api
.
ResourceQuotas
),
string
(
api
.
ResourceServices
),
string
(
api
.
ResourceServices
),
...
...
pkg/api/validation/validation.go
View file @
bc393e3f
...
@@ -3493,10 +3493,23 @@ func validateContainerResourceName(value string, fldPath *field.Path) field.Erro
...
@@ -3493,10 +3493,23 @@ func validateContainerResourceName(value string, fldPath *field.Path) field.Erro
return
allErrs
return
allErrs
}
}
// isLocalStorageResource checks whether the resource is local ephemeral storage
func
isLocalStorageResource
(
name
string
)
bool
{
if
name
==
string
(
api
.
ResourceEphemeralStorage
)
||
name
==
string
(
api
.
ResourceRequestsEphemeralStorage
)
||
name
==
string
(
api
.
ResourceLimitsEphemeralStorage
)
{
return
true
}
else
{
return
false
}
}
// Validate resource names that can go in a resource quota
// Validate resource names that can go in a resource quota
// Refer to docs/design/resources.md for more details.
// Refer to docs/design/resources.md for more details.
func
ValidateResourceQuotaResourceName
(
value
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
ValidateResourceQuotaResourceName
(
value
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
validateResourceName
(
value
,
fldPath
)
allErrs
:=
validateResourceName
(
value
,
fldPath
)
if
isLocalStorageResource
(
value
)
&&
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
LocalStorageCapacityIsolation
)
{
return
append
(
allErrs
,
field
.
Forbidden
(
fldPath
,
"ResourceEphemeralStorage field disabled by feature-gate for ResourceQuota"
))
}
if
len
(
strings
.
Split
(
value
,
"/"
))
==
1
{
if
len
(
strings
.
Split
(
value
,
"/"
))
==
1
{
if
!
helper
.
IsStandardQuotaResourceName
(
value
)
{
if
!
helper
.
IsStandardQuotaResourceName
(
value
)
{
return
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
value
,
isInvalidQuotaResource
))
return
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
value
,
isInvalidQuotaResource
))
...
...
pkg/api/validation/validation_test.go
View file @
bc393e3f
...
@@ -2709,6 +2709,62 @@ func TestAlphaLocalStorageCapacityIsolation(t *testing.T) {
...
@@ -2709,6 +2709,62 @@ func TestAlphaLocalStorageCapacityIsolation(t *testing.T) {
}
}
func
TestValidateResourceQuotaWithAlphaLocalStorageCapacityIsolation
(
t
*
testing
.
T
)
{
spec
:=
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceRequestsCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceRequestsMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceLimitsCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceLimitsMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"0"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
api
.
ResourceConfigMaps
:
resource
.
MustParse
(
"10"
),
api
.
ResourceSecrets
:
resource
.
MustParse
(
"10"
),
api
.
ResourceEphemeralStorage
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceRequestsEphemeralStorage
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceLimitsEphemeralStorage
:
resource
.
MustParse
(
"10000"
),
},
}
resourceQuota
:=
&
api
.
ResourceQuota
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
,
},
Spec
:
spec
,
}
// 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
}
if
errs
:=
ValidateResourceQuota
(
resourceQuota
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
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
}
errs
:=
ValidateResourceQuota
(
resourceQuota
)
if
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure for %s"
,
resourceQuota
.
Name
)
}
expectedErrMes
:=
"ResourceEphemeralStorage field disabled by feature-gate for ResourceQuota"
for
i
:=
range
errs
{
if
!
strings
.
Contains
(
errs
[
i
]
.
Detail
,
expectedErrMes
)
{
t
.
Errorf
(
"[%s]: expected error detail either empty or %s, got %s"
,
resourceQuota
.
Name
,
expectedErrMes
,
errs
[
i
]
.
Detail
)
}
}
}
func
TestValidatePorts
(
t
*
testing
.
T
)
{
func
TestValidatePorts
(
t
*
testing
.
T
)
{
successCase
:=
[]
api
.
ContainerPort
{
successCase
:=
[]
api
.
ContainerPort
{
{
Name
:
"abc"
,
ContainerPort
:
80
,
HostPort
:
80
,
Protocol
:
"TCP"
},
{
Name
:
"abc"
,
ContainerPort
:
80
,
HostPort
:
80
,
Protocol
:
"TCP"
},
...
...
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