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
786a0c62
Commit
786a0c62
authored
Aug 01, 2018
by
Karol Gołąb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor checkRequest to allow it to be called from outside of admission controller
parent
8e2d37ee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
+8
-3
controller.go
plugin/pkg/admission/resourcequota/controller.go
+8
-3
No files found.
plugin/pkg/admission/resourcequota/controller.go
View file @
786a0c62
...
...
@@ -386,12 +386,16 @@ func getMatchedLimitedScopes(evaluator quota.Evaluator, inputObject runtime.Obje
// checkRequest verifies that the request does not exceed any quota constraint. it returns a copy of quotas not yet persisted
// that capture what the usage would be if the request succeeded. It return an error if there is insufficient quota to satisfy the request
func
(
e
*
quotaEvaluator
)
checkRequest
(
quotas
[]
api
.
ResourceQuota
,
a
admission
.
Attributes
)
([]
api
.
ResourceQuota
,
error
)
{
namespace
:=
a
.
GetNamespace
()
evaluator
:=
e
.
registry
.
Get
(
a
.
GetResource
()
.
GroupResource
())
if
evaluator
==
nil
{
return
quotas
,
nil
}
return
CheckRequest
(
quotas
,
a
,
evaluator
,
e
.
config
.
LimitedResources
)
}
// CheckRequest is a static version of quotaEvaluator.checkRequest, possible to be called from outside.
func
CheckRequest
(
quotas
[]
api
.
ResourceQuota
,
a
admission
.
Attributes
,
evaluator
quota
.
Evaluator
,
limited
[]
resourcequotaapi
.
LimitedResource
)
([]
api
.
ResourceQuota
,
error
)
{
if
!
evaluator
.
Handles
(
a
)
{
return
quotas
,
nil
}
...
...
@@ -400,14 +404,14 @@ func (e *quotaEvaluator) checkRequest(quotas []api.ResourceQuota, a admission.At
inputObject
:=
a
.
GetObject
()
// Check if object matches AdmissionConfiguration matchScopes
limitedScopes
,
err
:=
getMatchedLimitedScopes
(
evaluator
,
inputObject
,
e
.
config
.
LimitedResources
)
limitedScopes
,
err
:=
getMatchedLimitedScopes
(
evaluator
,
inputObject
,
limited
)
if
err
!=
nil
{
return
quotas
,
nil
}
// determine the set of resource names that must exist in a covering quota
limitedResourceNames
:=
[]
api
.
ResourceName
{}
limitedResources
:=
filterLimitedResourcesByGroupResource
(
e
.
config
.
LimitedResources
,
a
.
GetResource
()
.
GroupResource
())
limitedResources
:=
filterLimitedResourcesByGroupResource
(
limited
,
a
.
GetResource
()
.
GroupResource
())
if
len
(
limitedResources
)
>
0
{
deltaUsage
,
err
:=
evaluator
.
Usage
(
inputObject
)
if
err
!=
nil
{
...
...
@@ -487,6 +491,7 @@ func (e *quotaEvaluator) checkRequest(quotas []api.ResourceQuota, a admission.At
// the resource represents a number of unique references to external
// resource. In such a case an evaluator needs to process other objects in
// the same namespace which needs to be known.
namespace
:=
a
.
GetNamespace
()
if
accessor
,
err
:=
meta
.
Accessor
(
inputObject
);
namespace
!=
""
&&
err
==
nil
{
if
accessor
.
GetNamespace
()
==
""
{
accessor
.
SetNamespace
(
namespace
)
...
...
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