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
63f88b48
Commit
63f88b48
authored
Jul 10, 2016
by
Xiang Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
controller/podautoscaler: minor cleanup
parent
c12de567
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
26 deletions
+24
-26
horizontal.go
pkg/controller/podautoscaler/horizontal.go
+24
-26
No files found.
pkg/controller/podautoscaler/horizontal.go
View file @
63f88b48
...
@@ -162,9 +162,9 @@ func (a *HorizontalController) computeReplicasForCPUUtilization(hpa *autoscaling
...
@@ -162,9 +162,9 @@ func (a *HorizontalController) computeReplicasForCPUUtilization(hpa *autoscaling
usageRatio
:=
float64
(
utilization
)
/
float64
(
targetUtilization
)
usageRatio
:=
float64
(
utilization
)
/
float64
(
targetUtilization
)
if
math
.
Abs
(
1.0
-
usageRatio
)
>
tolerance
{
if
math
.
Abs
(
1.0
-
usageRatio
)
>
tolerance
{
return
int32
(
math
.
Ceil
(
usageRatio
*
float64
(
currentReplicas
))),
&
utilization
,
timestamp
,
nil
return
int32
(
math
.
Ceil
(
usageRatio
*
float64
(
currentReplicas
))),
&
utilization
,
timestamp
,
nil
}
else
{
return
currentReplicas
,
&
utilization
,
timestamp
,
nil
}
}
return
currentReplicas
,
&
utilization
,
timestamp
,
nil
}
}
// Computes the desired number of replicas based on the CustomMetrics passed in cmAnnotation as json-serialized
// Computes the desired number of replicas based on the CustomMetrics passed in cmAnnotation as json-serialized
...
@@ -175,17 +175,12 @@ func (a *HorizontalController) computeReplicasForCPUUtilization(hpa *autoscaling
...
@@ -175,17 +175,12 @@ func (a *HorizontalController) computeReplicasForCPUUtilization(hpa *autoscaling
func
(
a
*
HorizontalController
)
computeReplicasForCustomMetrics
(
hpa
*
autoscaling
.
HorizontalPodAutoscaler
,
scale
*
extensions
.
Scale
,
func
(
a
*
HorizontalController
)
computeReplicasForCustomMetrics
(
hpa
*
autoscaling
.
HorizontalPodAutoscaler
,
scale
*
extensions
.
Scale
,
cmAnnotation
string
)
(
replicas
int32
,
metric
string
,
status
string
,
timestamp
time
.
Time
,
err
error
)
{
cmAnnotation
string
)
(
replicas
int32
,
metric
string
,
status
string
,
timestamp
time
.
Time
,
err
error
)
{
currentReplicas
:=
scale
.
Status
.
Replicas
replicas
=
0
metric
=
""
status
=
""
timestamp
=
time
.
Time
{}
err
=
nil
if
cmAnnotation
==
""
{
if
cmAnnotation
==
""
{
return
return
}
}
currentReplicas
:=
scale
.
Status
.
Replicas
var
targetList
extensions
.
CustomMetricTargetList
var
targetList
extensions
.
CustomMetricTargetList
if
err
:=
json
.
Unmarshal
([]
byte
(
cmAnnotation
),
&
targetList
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
([]
byte
(
cmAnnotation
),
&
targetList
);
err
!=
nil
{
return
0
,
""
,
""
,
time
.
Time
{},
fmt
.
Errorf
(
"failed to parse custom metrics annotation: %v"
,
err
)
return
0
,
""
,
""
,
time
.
Time
{},
fmt
.
Errorf
(
"failed to parse custom metrics annotation: %v"
,
err
)
...
@@ -259,7 +254,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
...
@@ -259,7 +254,7 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
currentReplicas
:=
scale
.
Status
.
Replicas
currentReplicas
:=
scale
.
Status
.
Replicas
cpuDesiredReplicas
:=
int32
(
0
)
cpuDesiredReplicas
:=
int32
(
0
)
var
cpuCurrentUtilization
*
int32
=
nil
cpuCurrentUtilization
:=
new
(
int32
)
cpuTimestamp
:=
time
.
Time
{}
cpuTimestamp
:=
time
.
Time
{}
cmDesiredReplicas
:=
int32
(
0
)
cmDesiredReplicas
:=
int32
(
0
)
...
@@ -315,7 +310,8 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
...
@@ -315,7 +310,8 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
}
}
if
desiredReplicas
>
currentReplicas
{
if
desiredReplicas
>
currentReplicas
{
rescaleReason
=
fmt
.
Sprintf
(
"%s above target"
,
rescaleMetric
)
rescaleReason
=
fmt
.
Sprintf
(
"%s above target"
,
rescaleMetric
)
}
else
if
desiredReplicas
<
currentReplicas
{
}
if
desiredReplicas
<
currentReplicas
{
rescaleReason
=
"All metrics below target"
rescaleReason
=
"All metrics below target"
}
}
...
@@ -352,22 +348,24 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
...
@@ -352,22 +348,24 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
}
}
func
shouldScale
(
hpa
*
autoscaling
.
HorizontalPodAutoscaler
,
currentReplicas
,
desiredReplicas
int32
,
timestamp
time
.
Time
)
bool
{
func
shouldScale
(
hpa
*
autoscaling
.
HorizontalPodAutoscaler
,
currentReplicas
,
desiredReplicas
int32
,
timestamp
time
.
Time
)
bool
{
if
desiredReplicas
!=
currentReplicas
{
if
desiredReplicas
==
currentReplicas
{
// Going down only if the usageRatio dropped significantly below the target
return
false
// and there was no rescaling in the last downscaleForbiddenWindow.
}
if
desiredReplicas
<
currentReplicas
&&
(
hpa
.
Status
.
LastScaleTime
==
nil
||
hpa
.
Status
.
LastScaleTime
.
Add
(
downscaleForbiddenWindow
)
.
Before
(
timestamp
))
{
return
true
}
// Going up only if the usage ratio increased significantly above the target
// Going down only if the usageRatio dropped significantly below the target
// and there was no rescaling in the last upscaleForbiddenWindow.
// 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
(
upscaleForbiddenWindow
)
.
Before
(
timestamp
))
{
hpa
.
Status
.
LastScaleTime
.
Add
(
downscaleForbiddenWindow
)
.
Before
(
timestamp
))
{
return
true
return
true
}
}
// Going up only if the usage ratio increased significantly above the target
// and there was no rescaling in the last upscaleForbiddenWindow.
if
desiredReplicas
>
currentReplicas
&&
(
hpa
.
Status
.
LastScaleTime
==
nil
||
hpa
.
Status
.
LastScaleTime
.
Add
(
upscaleForbiddenWindow
)
.
Before
(
timestamp
))
{
return
true
}
}
return
false
return
false
}
}
...
...
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