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
44808c64
Commit
44808c64
authored
Aug 18, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
only compute delta on non-creating updates
parent
9d2a5fe5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
admission_test.go
plugin/pkg/admission/resourcequota/admission_test.go
+3
-3
controller.go
plugin/pkg/admission/resourcequota/controller.go
+6
-0
No files found.
plugin/pkg/admission/resourcequota/admission_test.go
View file @
44808c64
...
@@ -295,8 +295,8 @@ func TestAdmitHandlesOldObjects(t *testing.T) {
...
@@ -295,8 +295,8 @@ func TestAdmitHandlesOldObjects(t *testing.T) {
indexer
.
Add
(
resourceQuota
)
indexer
.
Add
(
resourceQuota
)
// old service was a load balancer, but updated version is a node port.
// old service was a load balancer, but updated version is a node port.
old
Service
:=
&
api
.
Service
{
existing
Service
:=
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"service"
,
Namespace
:
"test"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"service"
,
Namespace
:
"test"
,
ResourceVersion
:
"1"
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeLoadBalancer
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeLoadBalancer
},
}
}
newService
:=
&
api
.
Service
{
newService
:=
&
api
.
Service
{
...
@@ -306,7 +306,7 @@ func TestAdmitHandlesOldObjects(t *testing.T) {
...
@@ -306,7 +306,7 @@ func TestAdmitHandlesOldObjects(t *testing.T) {
Ports
:
[]
api
.
ServicePort
{{
Port
:
1234
}},
Ports
:
[]
api
.
ServicePort
{{
Port
:
1234
}},
},
},
}
}
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
newService
,
old
Service
,
api
.
Kind
(
"Service"
)
.
WithVersion
(
"version"
),
newService
.
Namespace
,
newService
.
Name
,
api
.
Resource
(
"services"
)
.
WithVersion
(
"version"
),
""
,
admission
.
Update
,
nil
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
newService
,
existing
Service
,
api
.
Kind
(
"Service"
)
.
WithVersion
(
"version"
),
newService
.
Namespace
,
newService
.
Name
,
api
.
Resource
(
"services"
)
.
WithVersion
(
"version"
),
""
,
admission
.
Update
,
nil
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
}
...
...
plugin/pkg/admission/resourcequota/controller.go
View file @
44808c64
...
@@ -369,9 +369,15 @@ func (e *quotaEvaluator) checkRequest(quotas []api.ResourceQuota, a admission.At
...
@@ -369,9 +369,15 @@ func (e *quotaEvaluator) checkRequest(quotas []api.ResourceQuota, a admission.At
if
prevItem
==
nil
{
if
prevItem
==
nil
{
return
nil
,
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"unable to get previous usage since prior version of object was not found"
))
return
nil
,
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"unable to get previous usage since prior version of object was not found"
))
}
}
// if we can definitively determine that this is not a case of "create on update",
// then charge based on the delta. Otherwise, bill the maximum
metadata
,
err
:=
meta
.
Accessor
(
prevItem
)
if
err
==
nil
&&
len
(
metadata
.
GetResourceVersion
())
>
0
{
prevUsage
:=
evaluator
.
Usage
(
prevItem
)
prevUsage
:=
evaluator
.
Usage
(
prevItem
)
deltaUsage
=
quota
.
Subtract
(
deltaUsage
,
prevUsage
)
deltaUsage
=
quota
.
Subtract
(
deltaUsage
,
prevUsage
)
}
}
}
if
quota
.
IsZero
(
deltaUsage
)
{
if
quota
.
IsZero
(
deltaUsage
)
{
return
quotas
,
nil
return
quotas
,
nil
}
}
...
...
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