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
762e155f
Commit
762e155f
authored
Feb 23, 2016
by
Piotr Szczesniak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring of pod autoscaler controller
parent
b034050f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
18 deletions
+25
-18
horizontal.go
pkg/controller/podautoscaler/horizontal.go
+25
-18
No files found.
pkg/controller/podautoscaler/horizontal.go
View file @
762e155f
...
@@ -231,15 +231,33 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
...
@@ -231,15 +231,33 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
desiredReplicas
=
hpa
.
Spec
.
MaxReplicas
desiredReplicas
=
hpa
.
Spec
.
MaxReplicas
}
}
}
}
rescale
:=
false
rescale
:=
shouldScale
(
hpa
,
currentReplicas
,
desiredReplicas
,
timestamp
)
if
rescale
{
scale
.
Spec
.
Replicas
=
desiredReplicas
_
,
err
=
a
.
scaleNamespacer
.
Scales
(
hpa
.
Namespace
)
.
Update
(
hpa
.
Spec
.
ScaleRef
.
Kind
,
scale
)
if
err
!=
nil
{
a
.
eventRecorder
.
Eventf
(
&
hpa
,
api
.
EventTypeWarning
,
"FailedRescale"
,
"New size: %d; error: %v"
,
desiredReplicas
,
err
.
Error
())
return
fmt
.
Errorf
(
"failed to rescale %s: %v"
,
reference
,
err
)
}
a
.
eventRecorder
.
Eventf
(
&
hpa
,
api
.
EventTypeNormal
,
"SuccessfulRescale"
,
"New size: %d"
,
desiredReplicas
)
glog
.
Infof
(
"Successfull rescale of %s, old size: %d, new size: %d"
,
hpa
.
Name
,
currentReplicas
,
desiredReplicas
)
}
else
{
desiredReplicas
=
currentReplicas
}
return
a
.
updateStatus
(
hpa
,
currentReplicas
,
desiredReplicas
,
cpuCurrentUtilization
,
cmStatus
,
rescale
)
}
func
shouldScale
(
hpa
extensions
.
HorizontalPodAutoscaler
,
currentReplicas
,
desiredReplicas
int
,
timestamp
time
.
Time
)
bool
{
if
desiredReplicas
!=
currentReplicas
{
if
desiredReplicas
!=
currentReplicas
{
// Going down only if the usageRatio dropped significantly below the target
// Going down only if the usageRatio dropped significantly below the target
// and there was no rescaling in the last downscaleForbiddenWindow.
// and there was no rescaling in the last downscaleForbiddenWindow.
if
desiredReplicas
<
currentReplicas
&&
if
desiredReplicas
<
currentReplicas
&&
(
hpa
.
Status
.
LastScaleTime
==
nil
||
(
hpa
.
Status
.
LastScaleTime
==
nil
||
hpa
.
Status
.
LastScaleTime
.
Add
(
downscaleForbiddenWindow
)
.
Before
(
timestamp
))
{
hpa
.
Status
.
LastScaleTime
.
Add
(
downscaleForbiddenWindow
)
.
Before
(
timestamp
))
{
re
scale
=
true
re
turn
true
}
}
// Going up only if the usage ratio increased significantly above the target
// Going up only if the usage ratio increased significantly above the target
...
@@ -247,24 +265,13 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
...
@@ -247,24 +265,13 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
if
desiredReplicas
>
currentReplicas
&&
if
desiredReplicas
>
currentReplicas
&&
(
hpa
.
Status
.
LastScaleTime
==
nil
||
(
hpa
.
Status
.
LastScaleTime
==
nil
||
hpa
.
Status
.
LastScaleTime
.
Add
(
upscaleForbiddenWindow
)
.
Before
(
timestamp
))
{
hpa
.
Status
.
LastScaleTime
.
Add
(
upscaleForbiddenWindow
)
.
Before
(
timestamp
))
{
re
scale
=
true
re
turn
true
}
}
}
}
return
false
}
if
rescale
{
func
(
a
*
HorizontalController
)
updateStatus
(
hpa
extensions
.
HorizontalPodAutoscaler
,
currentReplicas
,
desiredReplicas
int
,
cpuCurrentUtilization
*
int
,
cmStatus
string
,
rescale
bool
)
error
{
scale
.
Spec
.
Replicas
=
desiredReplicas
_
,
err
=
a
.
scaleNamespacer
.
Scales
(
hpa
.
Namespace
)
.
Update
(
hpa
.
Spec
.
ScaleRef
.
Kind
,
scale
)
if
err
!=
nil
{
a
.
eventRecorder
.
Eventf
(
&
hpa
,
api
.
EventTypeWarning
,
"FailedRescale"
,
"New size: %d; error: %v"
,
desiredReplicas
,
err
.
Error
())
return
fmt
.
Errorf
(
"failed to rescale %s: %v"
,
reference
,
err
)
}
a
.
eventRecorder
.
Eventf
(
&
hpa
,
api
.
EventTypeNormal
,
"SuccessfulRescale"
,
"New size: %d"
,
desiredReplicas
)
glog
.
Infof
(
"Successfull rescale of %s, old size: %d, new size: %d"
,
hpa
.
Name
,
currentReplicas
,
desiredReplicas
)
}
else
{
desiredReplicas
=
currentReplicas
}
hpa
.
Status
=
extensions
.
HorizontalPodAutoscalerStatus
{
hpa
.
Status
=
extensions
.
HorizontalPodAutoscalerStatus
{
CurrentReplicas
:
currentReplicas
,
CurrentReplicas
:
currentReplicas
,
DesiredReplicas
:
desiredReplicas
,
DesiredReplicas
:
desiredReplicas
,
...
@@ -280,7 +287,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
...
@@ -280,7 +287,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa extensions.HorizontalPodA
hpa
.
Status
.
LastScaleTime
=
&
now
hpa
.
Status
.
LastScaleTime
=
&
now
}
}
_
,
err
=
a
.
hpaNamespacer
.
HorizontalPodAutoscalers
(
hpa
.
Namespace
)
.
UpdateStatus
(
&
hpa
)
_
,
err
:
=
a
.
hpaNamespacer
.
HorizontalPodAutoscalers
(
hpa
.
Namespace
)
.
UpdateStatus
(
&
hpa
)
if
err
!=
nil
{
if
err
!=
nil
{
a
.
eventRecorder
.
Event
(
&
hpa
,
api
.
EventTypeWarning
,
"FailedUpdateStatus"
,
err
.
Error
())
a
.
eventRecorder
.
Event
(
&
hpa
,
api
.
EventTypeWarning
,
"FailedUpdateStatus"
,
err
.
Error
())
return
fmt
.
Errorf
(
"failed to update status for %s: %v"
,
hpa
.
Name
,
err
)
return
fmt
.
Errorf
(
"failed to update status for %s: %v"
,
hpa
.
Name
,
err
)
...
...
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