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
ff758bec
Commit
ff758bec
authored
Feb 28, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21750 from piosz/hpa-status-current-utilization
Auto commit by PR queue bot
parents
6f8a951f
4d1367c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
1 deletion
+25
-1
horizontal_test.go
pkg/controller/podautoscaler/horizontal_test.go
+25
-1
No files found.
pkg/controller/podautoscaler/horizontal_test.go
View file @
ff758bec
...
...
@@ -62,6 +62,8 @@ type testCase struct {
desiredReplicas
int
// CPU target utilization as a percentage of the requested resources.
CPUTarget
int
CPUCurrent
int
verifyCPUCurrent
bool
reportedLevels
[]
uint64
reportedCPURequests
[]
resource
.
Quantity
cmTarget
*
extensions
.
CustomMetricTargetList
...
...
@@ -71,6 +73,21 @@ type testCase struct {
verifyEvents
bool
}
func
(
tc
*
testCase
)
computeCPUCurrent
()
{
if
len
(
tc
.
reportedLevels
)
!=
len
(
tc
.
reportedCPURequests
)
||
len
(
tc
.
reportedLevels
)
==
0
{
return
}
reported
:=
0
for
_
,
r
:=
range
tc
.
reportedLevels
{
reported
+=
int
(
r
)
}
requested
:=
0
for
_
,
req
:=
range
tc
.
reportedCPURequests
{
requested
+=
int
(
req
.
MilliValue
())
}
tc
.
CPUCurrent
=
100
*
reported
/
requested
}
func
(
tc
*
testCase
)
prepareTestClient
(
t
*
testing
.
T
)
*
fake
.
Clientset
{
namespace
:=
"test-namespace"
hpaName
:=
"test-hpa"
...
...
@@ -80,6 +97,7 @@ func (tc *testCase) prepareTestClient(t *testing.T) *fake.Clientset {
tc
.
scaleUpdated
=
false
tc
.
statusUpdated
=
false
tc
.
eventCreated
=
false
tc
.
computeCPUCurrent
()
fakeClient
:=
&
fake
.
Clientset
{}
fakeClient
.
AddReactor
(
"list"
,
"horizontalpodautoscalers"
,
func
(
action
core
.
Action
)
(
handled
bool
,
ret
runtime
.
Object
,
err
error
)
{
...
...
@@ -198,6 +216,10 @@ func (tc *testCase) prepareTestClient(t *testing.T) *fake.Clientset {
assert
.
Equal
(
t
,
hpaName
,
obj
.
Name
)
assert
.
Equal
(
t
,
tc
.
desiredReplicas
,
obj
.
Status
.
DesiredReplicas
)
tc
.
statusUpdated
=
true
if
tc
.
verifyCPUCurrent
{
assert
.
NotNil
(
t
,
obj
.
Status
.
CurrentCPUUtilizationPercentage
)
assert
.
Equal
(
t
,
tc
.
CPUCurrent
,
*
obj
.
Status
.
CurrentCPUUtilizationPercentage
)
}
return
true
,
obj
,
nil
})
...
...
@@ -242,6 +264,7 @@ func TestScaleUp(t *testing.T) {
initialReplicas
:
3
,
desiredReplicas
:
5
,
CPUTarget
:
30
,
verifyCPUCurrent
:
true
,
reportedLevels
:
[]
uint64
{
300
,
500
,
700
},
reportedCPURequests
:
[]
resource
.
Quantity
{
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
)},
}
...
...
@@ -274,6 +297,7 @@ func TestScaleDown(t *testing.T) {
initialReplicas
:
5
,
desiredReplicas
:
3
,
CPUTarget
:
50
,
verifyCPUCurrent
:
true
,
reportedLevels
:
[]
uint64
{
100
,
300
,
500
,
250
,
250
},
reportedCPURequests
:
[]
resource
.
Quantity
{
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
)},
}
...
...
@@ -354,7 +378,7 @@ func TestZeroReplicas(t *testing.T) {
tc
.
runTest
(
t
)
}
func
TestToFewReplicas
(
t
*
testing
.
T
)
{
func
TestTo
o
FewReplicas
(
t
*
testing
.
T
)
{
tc
:=
testCase
{
minReplicas
:
3
,
maxReplicas
:
5
,
...
...
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