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
a6d855bf
Commit
a6d855bf
authored
Feb 20, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21149 from mwielgus/hpa-rescale
Auto commit by PR queue bot
parents
93eb6d1f
1d389128
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
4 deletions
+52
-4
horizontal.go
pkg/controller/podautoscaler/horizontal.go
+13
-4
horizontal_test.go
pkg/controller/podautoscaler/horizontal_test.go
+39
-0
No files found.
pkg/controller/podautoscaler/horizontal.go
View file @
a6d855bf
...
@@ -161,7 +161,6 @@ func (a *HorizontalController) computeReplicasForCustomMetrics(hpa extensions.Ho
...
@@ -161,7 +161,6 @@ func (a *HorizontalController) computeReplicasForCustomMetrics(hpa extensions.Ho
}
}
return
replicas
,
string
(
byteStatusList
),
timestamp
,
nil
return
replicas
,
string
(
byteStatusList
),
timestamp
,
nil
}
}
func
(
a
*
HorizontalController
)
reconcileAutoscaler
(
hpa
extensions
.
HorizontalPodAutoscaler
)
error
{
func
(
a
*
HorizontalController
)
reconcileAutoscaler
(
hpa
extensions
.
HorizontalPodAutoscaler
)
error
{
...
@@ -182,6 +181,18 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
...
@@ -182,6 +181,18 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
cmStatus
:=
""
cmStatus
:=
""
cmTimestamp
:=
time
.
Time
{}
cmTimestamp
:=
time
.
Time
{}
desiredReplicas
:=
0
timestamp
:=
time
.
Now
()
if
currentReplicas
>
hpa
.
Spec
.
MaxReplicas
{
desiredReplicas
=
hpa
.
Spec
.
MaxReplicas
}
else
if
hpa
.
Spec
.
MinReplicas
!=
nil
&&
currentReplicas
<
*
hpa
.
Spec
.
MinReplicas
{
desiredReplicas
=
*
hpa
.
Spec
.
MinReplicas
}
else
if
currentReplicas
==
0
{
desiredReplicas
=
1
}
else
{
// All basic scenarios covered, the state should be sane, lets use metrics.
if
hpa
.
Spec
.
CPUUtilization
!=
nil
{
if
hpa
.
Spec
.
CPUUtilization
!=
nil
{
cpuDesiredReplicas
,
cpuCurrentUtilization
,
cpuTimestamp
,
err
=
a
.
computeReplicasForCPUUtilization
(
hpa
,
scale
)
cpuDesiredReplicas
,
cpuCurrentUtilization
,
cpuTimestamp
,
err
=
a
.
computeReplicasForCPUUtilization
(
hpa
,
scale
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -198,9 +209,6 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
...
@@ -198,9 +209,6 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
}
}
}
}
desiredReplicas
:=
0
timestamp
:=
time
.
Time
{}
if
cpuDesiredReplicas
>
desiredReplicas
{
if
cpuDesiredReplicas
>
desiredReplicas
{
desiredReplicas
=
cpuDesiredReplicas
desiredReplicas
=
cpuDesiredReplicas
timestamp
=
cpuTimestamp
timestamp
=
cpuTimestamp
...
@@ -222,6 +230,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
...
@@ -222,6 +230,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
if
desiredReplicas
>
hpa
.
Spec
.
MaxReplicas
{
if
desiredReplicas
>
hpa
.
Spec
.
MaxReplicas
{
desiredReplicas
=
hpa
.
Spec
.
MaxReplicas
desiredReplicas
=
hpa
.
Spec
.
MaxReplicas
}
}
}
rescale
:=
false
rescale
:=
false
if
desiredReplicas
!=
currentReplicas
{
if
desiredReplicas
!=
currentReplicas
{
...
...
pkg/controller/podautoscaler/horizontal_test.go
View file @
a6d855bf
...
@@ -333,6 +333,45 @@ func TestMinReplicas(t *testing.T) {
...
@@ -333,6 +333,45 @@ func TestMinReplicas(t *testing.T) {
tc
.
runTest
(
t
)
tc
.
runTest
(
t
)
}
}
func
TestZeroReplicas
(
t
*
testing
.
T
)
{
tc
:=
testCase
{
minReplicas
:
3
,
maxReplicas
:
5
,
initialReplicas
:
0
,
desiredReplicas
:
3
,
CPUTarget
:
90
,
reportedLevels
:
[]
uint64
{},
reportedCPURequests
:
[]
resource
.
Quantity
{},
}
tc
.
runTest
(
t
)
}
func
TestToFewReplicas
(
t
*
testing
.
T
)
{
tc
:=
testCase
{
minReplicas
:
3
,
maxReplicas
:
5
,
initialReplicas
:
2
,
desiredReplicas
:
3
,
CPUTarget
:
90
,
reportedLevels
:
[]
uint64
{},
reportedCPURequests
:
[]
resource
.
Quantity
{},
}
tc
.
runTest
(
t
)
}
func
TestTooManyReplicas
(
t
*
testing
.
T
)
{
tc
:=
testCase
{
minReplicas
:
3
,
maxReplicas
:
5
,
initialReplicas
:
10
,
desiredReplicas
:
5
,
CPUTarget
:
90
,
reportedLevels
:
[]
uint64
{},
reportedCPURequests
:
[]
resource
.
Quantity
{},
}
tc
.
runTest
(
t
)
}
func
TestMaxReplicas
(
t
*
testing
.
T
)
{
func
TestMaxReplicas
(
t
*
testing
.
T
)
{
tc
:=
testCase
{
tc
:=
testCase
{
minReplicas
:
2
,
minReplicas
:
2
,
...
...
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