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
9ce6ef87
Commit
9ce6ef87
authored
Nov 10, 2015
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unnecessary updates to ResourceQuota when doing UPDATE to non-pod resources
parent
1407fd20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
admission.go
plugin/pkg/admission/resourcequota/admission.go
+6
-0
admission_test.go
plugin/pkg/admission/resourcequota/admission_test.go
+57
-0
No files found.
plugin/pkg/admission/resourcequota/admission.go
View file @
9ce6ef87
...
@@ -168,6 +168,12 @@ func (q *quota) Admit(a admission.Attributes) (err error) {
...
@@ -168,6 +168,12 @@ func (q *quota) Admit(a admission.Attributes) (err error) {
// Return true if the usage must be recorded prior to admitting the new resource
// Return true if the usage must be recorded prior to admitting the new resource
// Return an error if the operation should not pass admission control
// Return an error if the operation should not pass admission control
func
IncrementUsage
(
a
admission
.
Attributes
,
status
*
api
.
ResourceQuotaStatus
,
client
client
.
Interface
)
(
bool
,
error
)
{
func
IncrementUsage
(
a
admission
.
Attributes
,
status
*
api
.
ResourceQuotaStatus
,
client
client
.
Interface
)
(
bool
,
error
)
{
// on update, the only resource that can modify the value of a quota is pods
// so if your not a pod, we exit quickly
if
a
.
GetOperation
()
==
admission
.
Update
&&
a
.
GetResource
()
!=
"pods"
{
return
false
,
nil
}
var
errs
[]
error
var
errs
[]
error
dirty
:=
true
dirty
:=
true
set
:=
map
[
api
.
ResourceName
]
bool
{}
set
:=
map
[
api
.
ResourceName
]
bool
{}
...
...
plugin/pkg/admission/resourcequota/admission_test.go
View file @
9ce6ef87
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
resourcequotacontroller
"k8s.io/kubernetes/pkg/controller/resourcequota"
resourcequotacontroller
"k8s.io/kubernetes/pkg/controller/resourcequota"
"k8s.io/kubernetes/pkg/runtime"
)
)
func
getResourceList
(
cpu
,
memory
string
)
api
.
ResourceList
{
func
getResourceList
(
cpu
,
memory
string
)
api
.
ResourceList
{
...
@@ -388,3 +389,59 @@ func TestExceedUsagePersistentVolumeClaims(t *testing.T) {
...
@@ -388,3 +389,59 @@ func TestExceedUsagePersistentVolumeClaims(t *testing.T) {
t
.
Errorf
(
"Expected error for exceeding hard limits"
)
t
.
Errorf
(
"Expected error for exceeding hard limits"
)
}
}
}
}
func
TestIncrementUsageOnUpdateIgnoresNonPodResources
(
t
*
testing
.
T
)
{
testCase
:=
[]
struct
{
kind
string
resource
string
subresource
string
object
runtime
.
Object
}{
{
kind
:
"Service"
,
resource
:
"services"
,
object
:
&
api
.
Service
{},
},
{
kind
:
"ReplicationController"
,
resource
:
"replicationcontrollers"
,
object
:
&
api
.
ReplicationController
{},
},
{
kind
:
"ResourceQuota"
,
resource
:
"resourcequotas"
,
object
:
&
api
.
ResourceQuota
{},
},
{
kind
:
"Secret"
,
resource
:
"secrets"
,
object
:
&
api
.
Secret
{},
},
{
kind
:
"PersistentVolumeClaim"
,
resource
:
"persistentvolumeclaims"
,
object
:
&
api
.
PersistentVolumeClaim
{},
},
}
for
_
,
testCase
:=
range
testCase
{
client
:=
testclient
.
NewSimpleFake
()
status
:=
&
api
.
ResourceQuotaStatus
{
Hard
:
api
.
ResourceList
{},
Used
:
api
.
ResourceList
{},
}
r
:=
api
.
ResourceName
(
testCase
.
resource
)
status
.
Hard
[
r
]
=
resource
.
MustParse
(
"2"
)
status
.
Used
[
r
]
=
resource
.
MustParse
(
"1"
)
attributesRecord
:=
admission
.
NewAttributesRecord
(
testCase
.
object
,
testCase
.
kind
,
"my-ns"
,
"new-thing"
,
testCase
.
resource
,
testCase
.
subresource
,
admission
.
Update
,
nil
)
dirty
,
err
:=
IncrementUsage
(
attributesRecord
,
status
,
client
)
if
err
!=
nil
{
t
.
Errorf
(
"Increment usage of resource %v had unexpected error: %v"
,
testCase
.
resource
,
err
)
}
if
dirty
{
t
.
Errorf
(
"Increment usage of resource %v should not result in a dirty quota on update"
,
testCase
.
resource
)
}
}
}
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