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
ca7a8b50
Commit
ca7a8b50
authored
May 04, 2016
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort resources in quota errors to avoid duplicate events
parent
8bebc448
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
2 deletions
+50
-2
admission.go
plugin/pkg/admission/resourcequota/admission.go
+10
-2
admission_test.go
plugin/pkg/admission/resourcequota/admission_test.go
+40
-0
No files found.
plugin/pkg/admission/resourcequota/admission.go
View file @
ca7a8b50
...
@@ -18,6 +18,7 @@ package resourcequota
...
@@ -18,6 +18,7 @@ package resourcequota
import
(
import
(
"io"
"io"
"sort"
"strings"
"strings"
"time"
"time"
...
@@ -91,10 +92,17 @@ func (q *quotaAdmission) Admit(a admission.Attributes) (err error) {
...
@@ -91,10 +92,17 @@ func (q *quotaAdmission) Admit(a admission.Attributes) (err error) {
}
}
// prettyPrint formats a resource list for usage in errors
// prettyPrint formats a resource list for usage in errors
// it outputs resources sorted in increasing order
func
prettyPrint
(
item
api
.
ResourceList
)
string
{
func
prettyPrint
(
item
api
.
ResourceList
)
string
{
parts
:=
[]
string
{}
parts
:=
[]
string
{}
for
key
,
value
:=
range
item
{
keys
:=
[]
string
{}
constraint
:=
string
(
key
)
+
"="
+
value
.
String
()
for
key
:=
range
item
{
keys
=
append
(
keys
,
string
(
key
))
}
sort
.
Strings
(
keys
)
for
_
,
key
:=
range
keys
{
value
:=
item
[
api
.
ResourceName
(
key
)]
constraint
:=
key
+
"="
+
value
.
String
()
parts
=
append
(
parts
,
constraint
)
parts
=
append
(
parts
,
constraint
)
}
}
return
strings
.
Join
(
parts
,
","
)
return
strings
.
Join
(
parts
,
","
)
...
...
plugin/pkg/admission/resourcequota/admission_test.go
View file @
ca7a8b50
...
@@ -72,6 +72,46 @@ func validPod(name string, numContainers int, resources api.ResourceRequirements
...
@@ -72,6 +72,46 @@ func validPod(name string, numContainers int, resources api.ResourceRequirements
return
pod
return
pod
}
}
func
TestPrettyPrint
(
t
*
testing
.
T
)
{
toResourceList
:=
func
(
resources
map
[
api
.
ResourceName
]
string
)
api
.
ResourceList
{
resourceList
:=
api
.
ResourceList
{}
for
key
,
value
:=
range
resources
{
resourceList
[
key
]
=
resource
.
MustParse
(
value
)
}
return
resourceList
}
testCases
:=
[]
struct
{
input
api
.
ResourceList
expected
string
}{
{
input
:
toResourceList
(
map
[
api
.
ResourceName
]
string
{
api
.
ResourceCPU
:
"100m"
,
}),
expected
:
"cpu=100m"
,
},
{
input
:
toResourceList
(
map
[
api
.
ResourceName
]
string
{
api
.
ResourcePods
:
"10"
,
api
.
ResourceServices
:
"10"
,
api
.
ResourceReplicationControllers
:
"10"
,
api
.
ResourceServicesNodePorts
:
"10"
,
api
.
ResourceRequestsCPU
:
"100m"
,
api
.
ResourceRequestsMemory
:
"100Mi"
,
api
.
ResourceLimitsCPU
:
"100m"
,
api
.
ResourceLimitsMemory
:
"100Mi"
,
}),
expected
:
"limits.cpu=100m,limits.memory=100Mi,pods=10,replicationcontrollers=10,requests.cpu=100m,requests.memory=100Mi,services=10,services.nodeports=10"
,
},
}
for
i
,
testCase
:=
range
testCases
{
result
:=
prettyPrint
(
testCase
.
input
)
if
result
!=
testCase
.
expected
{
t
.
Errorf
(
"Pretty print did not give stable sorted output[%d], expected %v, but got %v"
,
i
,
testCase
.
expected
,
result
)
}
}
}
// TestAdmissionIgnoresDelete verifies that the admission controller ignores delete operations
// TestAdmissionIgnoresDelete verifies that the admission controller ignores delete operations
func
TestAdmissionIgnoresDelete
(
t
*
testing
.
T
)
{
func
TestAdmissionIgnoresDelete
(
t
*
testing
.
T
)
{
kubeClient
:=
fake
.
NewSimpleClientset
()
kubeClient
:=
fake
.
NewSimpleClientset
()
...
...
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