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
1388efe6
Commit
1388efe6
authored
May 25, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make quota validation re-useable
parent
6ebf168b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
37 deletions
+46
-37
validation.go
pkg/api/validation/validation.go
+46
-37
No files found.
pkg/api/validation/validation.go
View file @
1388efe6
...
...
@@ -2413,7 +2413,7 @@ func validateContainerResourceName(value string, fldPath *field.Path) field.Erro
// Validate resource names that can go in a resource quota
// Refer to docs/design/resources.md for more details.
func
v
alidateResourceQuotaResourceName
(
value
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
func
V
alidateResourceQuotaResourceName
(
value
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
validateResourceName
(
value
,
fldPath
)
if
len
(
strings
.
Split
(
value
,
"/"
))
==
1
{
if
!
api
.
IsStandardQuotaResourceName
(
value
)
{
...
...
@@ -2759,24 +2759,24 @@ func ValidateResourceRequirements(requirements *api.ResourceRequirements, fldPat
}
// validateResourceQuotaScopes ensures that each enumerated hard resource constraint is valid for set of scopes
func
validateResourceQuotaScopes
(
resourceQuota
*
api
.
ResourceQuota
)
field
.
ErrorList
{
func
validateResourceQuotaScopes
(
resourceQuota
Spec
*
api
.
ResourceQuotaSpec
,
fld
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
if
len
(
resourceQuota
.
Spec
.
Scopes
)
==
0
{
if
len
(
resourceQuotaSpec
.
Scopes
)
==
0
{
return
allErrs
}
hardLimits
:=
sets
.
NewString
()
for
k
:=
range
resourceQuota
.
Spec
.
Hard
{
for
k
:=
range
resourceQuotaSpec
.
Hard
{
hardLimits
.
Insert
(
string
(
k
))
}
fldPath
:=
f
ield
.
NewPath
(
"spec"
,
"scopes"
)
fldPath
:=
f
ld
.
Child
(
"scopes"
)
scopeSet
:=
sets
.
NewString
()
for
_
,
scope
:=
range
resourceQuota
.
Spec
.
Scopes
{
for
_
,
scope
:=
range
resourceQuotaSpec
.
Scopes
{
if
!
api
.
IsStandardResourceQuotaScope
(
string
(
scope
))
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
resourceQuota
.
Spec
.
Scopes
,
"unsupported scope"
))
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
resourceQuotaSpec
.
Scopes
,
"unsupported scope"
))
}
for
_
,
k
:=
range
hardLimits
.
List
()
{
if
api
.
IsStandardQuotaResourceName
(
k
)
&&
!
api
.
IsResourceQuotaScopeValidForResource
(
scope
,
k
)
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
resourceQuota
.
Spec
.
Scopes
,
"unsupported scope applied to resource"
))
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
resourceQuotaSpec
.
Scopes
,
"unsupported scope applied to resource"
))
}
}
scopeSet
.
Insert
(
string
(
scope
))
...
...
@@ -2787,7 +2787,7 @@ func validateResourceQuotaScopes(resourceQuota *api.ResourceQuota) field.ErrorLi
}
for
_
,
invalidScopePair
:=
range
invalidScopePairs
{
if
scopeSet
.
HasAll
(
invalidScopePair
.
List
()
...
)
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
resourceQuota
.
Spec
.
Scopes
,
"conflicting scopes"
))
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
resourceQuotaSpec
.
Scopes
,
"conflicting scopes"
))
}
}
return
allErrs
...
...
@@ -2797,32 +2797,47 @@ func validateResourceQuotaScopes(resourceQuota *api.ResourceQuota) field.ErrorLi
func
ValidateResourceQuota
(
resourceQuota
*
api
.
ResourceQuota
)
field
.
ErrorList
{
allErrs
:=
ValidateObjectMeta
(
&
resourceQuota
.
ObjectMeta
,
true
,
ValidateResourceQuotaName
,
field
.
NewPath
(
"metadata"
))
fldPath
:=
field
.
NewPath
(
"spec"
,
"hard"
)
for
k
,
v
:=
range
resourceQuota
.
Spec
.
Hard
{
allErrs
=
append
(
allErrs
,
ValidateResourceQuotaSpec
(
&
resourceQuota
.
Spec
,
field
.
NewPath
(
"spec"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateResourceQuotaStatus
(
&
resourceQuota
.
Status
,
field
.
NewPath
(
"status"
))
...
)
return
allErrs
}
func
ValidateResourceQuotaStatus
(
status
*
api
.
ResourceQuotaStatus
,
fld
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
fldPath
:=
fld
.
Child
(
"hard"
)
for
k
,
v
:=
range
status
.
Hard
{
resPath
:=
fldPath
.
Key
(
string
(
k
))
allErrs
=
append
(
allErrs
,
v
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
v
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
}
allErrs
=
append
(
allErrs
,
validateResourceQuotaScopes
(
resourceQuota
)
...
)
fldPath
=
field
.
NewPath
(
"status"
,
"hard"
)
for
k
,
v
:=
range
resourceQuota
.
Status
.
Hard
{
fldPath
=
fld
.
Child
(
"used"
)
for
k
,
v
:=
range
status
.
Used
{
resPath
:=
fldPath
.
Key
(
string
(
k
))
allErrs
=
append
(
allErrs
,
v
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
v
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
}
fldPath
=
field
.
NewPath
(
"status"
,
"used"
)
for
k
,
v
:=
range
resourceQuota
.
Status
.
Used
{
return
allErrs
}
func
ValidateResourceQuotaSpec
(
resourceQuotaSpec
*
api
.
ResourceQuotaSpec
,
fld
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
fldPath
:=
fld
.
Child
(
"hard"
)
for
k
,
v
:=
range
resourceQuotaSpec
.
Hard
{
resPath
:=
fldPath
.
Key
(
string
(
k
))
allErrs
=
append
(
allErrs
,
v
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
v
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
}
allErrs
=
append
(
allErrs
,
validateResourceQuotaScopes
(
resourceQuotaSpec
,
fld
)
...
)
return
allErrs
}
//
v
alidateResourceQuantityValue enforces that specified quantity is valid for specified resource
func
v
alidateResourceQuantityValue
(
resource
string
,
value
resource
.
Quantity
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
//
V
alidateResourceQuantityValue enforces that specified quantity is valid for specified resource
func
V
alidateResourceQuantityValue
(
resource
string
,
value
resource
.
Quantity
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
allErrs
=
append
(
allErrs
,
ValidateNonnegativeQuantity
(
value
,
fldPath
)
...
)
if
api
.
IsIntegerResourceName
(
resource
)
{
...
...
@@ -2837,15 +2852,10 @@ func validateResourceQuantityValue(resource string, value resource.Quantity, fld
// newResourceQuota is updated with fields that cannot be changed.
func
ValidateResourceQuotaUpdate
(
newResourceQuota
,
oldResourceQuota
*
api
.
ResourceQuota
)
field
.
ErrorList
{
allErrs
:=
ValidateObjectMetaUpdate
(
&
newResourceQuota
.
ObjectMeta
,
&
oldResourceQuota
.
ObjectMeta
,
field
.
NewPath
(
"metadata"
))
fldPath
:=
field
.
NewPath
(
"spec"
,
"hard"
)
for
k
,
v
:=
range
newResourceQuota
.
Spec
.
Hard
{
resPath
:=
fldPath
.
Key
(
string
(
k
))
allErrs
=
append
(
allErrs
,
validateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
validateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
}
allErrs
=
append
(
allErrs
,
ValidateResourceQuotaSpec
(
&
newResourceQuota
.
Spec
,
field
.
NewPath
(
"spec"
))
...
)
// ensure scopes cannot change, and that resources are still valid for scope
fldPath
=
field
.
NewPath
(
"spec"
,
"scopes"
)
fldPath
:
=
field
.
NewPath
(
"spec"
,
"scopes"
)
oldScopes
:=
sets
.
NewString
()
newScopes
:=
sets
.
NewString
()
for
_
,
scope
:=
range
newResourceQuota
.
Spec
.
Scopes
{
...
...
@@ -2857,7 +2867,6 @@ func ValidateResourceQuotaUpdate(newResourceQuota, oldResourceQuota *api.Resourc
if
!
oldScopes
.
Equal
(
newScopes
)
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
,
newResourceQuota
.
Spec
.
Scopes
,
"field is immutable"
))
}
allErrs
=
append
(
allErrs
,
validateResourceQuotaScopes
(
newResourceQuota
)
...
)
newResourceQuota
.
Status
=
oldResourceQuota
.
Status
return
allErrs
...
...
@@ -2873,14 +2882,14 @@ func ValidateResourceQuotaStatusUpdate(newResourceQuota, oldResourceQuota *api.R
fldPath
:=
field
.
NewPath
(
"status"
,
"hard"
)
for
k
,
v
:=
range
newResourceQuota
.
Status
.
Hard
{
resPath
:=
fldPath
.
Key
(
string
(
k
))
allErrs
=
append
(
allErrs
,
v
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
v
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
}
fldPath
=
field
.
NewPath
(
"status"
,
"used"
)
for
k
,
v
:=
range
newResourceQuota
.
Status
.
Used
{
resPath
:=
fldPath
.
Key
(
string
(
k
))
allErrs
=
append
(
allErrs
,
v
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
v
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuotaResourceName
(
string
(
k
),
resPath
)
...
)
allErrs
=
append
(
allErrs
,
V
alidateResourceQuantityValue
(
string
(
k
),
v
,
resPath
)
...
)
}
newResourceQuota
.
Spec
=
oldResourceQuota
.
Spec
return
allErrs
...
...
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