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
7bc35868
Commit
7bc35868
authored
Nov 07, 2016
by
Kubernetes Submit Queue
Committed by
GitHub
Nov 07, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #36235 from jszczepkowski/hpa-events-fix
Automatic merge from submit-queue Improved event generation for HPA.
parents
dc37723c
6adc18ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
6 deletions
+41
-6
horizontal.go
pkg/controller/podautoscaler/horizontal.go
+41
-6
No files found.
pkg/controller/podautoscaler/horizontal.go
View file @
7bc35868
...
...
@@ -136,6 +136,15 @@ func (a *HorizontalController) Run(stopCh <-chan struct{}) {
glog
.
Infof
(
"Shutting down HPA Controller"
)
}
// getLastScaleTime returns the hpa's last scale time or the hpa's creation time if the last scale time is nil.
func
getLastScaleTime
(
hpa
*
autoscaling
.
HorizontalPodAutoscaler
)
time
.
Time
{
lastScaleTime
:=
hpa
.
Status
.
LastScaleTime
if
lastScaleTime
==
nil
{
lastScaleTime
=
&
hpa
.
CreationTimestamp
}
return
lastScaleTime
.
Time
}
func
(
a
*
HorizontalController
)
computeReplicasForCPUUtilization
(
hpa
*
autoscaling
.
HorizontalPodAutoscaler
,
scale
*
extensions
.
Scale
)
(
int32
,
*
int32
,
time
.
Time
,
error
)
{
targetUtilization
:=
int32
(
defaultTargetCPUUtilizationPercentage
)
if
hpa
.
Spec
.
TargetCPUUtilizationPercentage
!=
nil
{
...
...
@@ -159,7 +168,13 @@ func (a *HorizontalController) computeReplicasForCPUUtilization(hpa *autoscaling
// TODO: what to do on partial errors (like metrics obtained for 75% of pods).
if
err
!=
nil
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeWarning
,
"FailedGetMetrics"
,
err
.
Error
())
lastScaleTime
:=
getLastScaleTime
(
hpa
)
if
time
.
Now
()
.
After
(
lastScaleTime
.
Add
(
upscaleForbiddenWindow
))
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeWarning
,
"FailedGetMetrics"
,
err
.
Error
())
}
else
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeNormal
,
"MetricsNotAvailableYet"
,
err
.
Error
())
}
return
0
,
nil
,
time
.
Time
{},
fmt
.
Errorf
(
"failed to get CPU utilization: %v"
,
err
)
}
...
...
@@ -179,8 +194,8 @@ func (a *HorizontalController) computeReplicasForCPUUtilization(hpa *autoscaling
return
int32
(
desiredReplicas
),
&
utilization
,
timestamp
,
nil
}
//
Computes the desired number of replicas based on the CustomMetrics passed in cmAnnotation as json-serialized
// extensions.CustomMetricsTargetList.
//
computeReplicasForCustomMetrics computes the desired number of replicas based on the CustomMetrics passed in cmAnnotation
//
as json-serialized
extensions.CustomMetricsTargetList.
// Returns number of replicas, metric which required highest number of replicas,
// status string (also json-serialized extensions.CustomMetricsCurrentStatusList),
// last timestamp of the metrics involved in computations or error, if occurred.
...
...
@@ -221,7 +236,13 @@ func (a *HorizontalController) computeReplicasForCustomMetrics(hpa *autoscaling.
value
,
currentTimestamp
,
err
:=
a
.
metricsClient
.
GetCustomMetric
(
customMetricTarget
.
Name
,
hpa
.
Namespace
,
selector
)
// TODO: what to do on partial errors (like metrics obtained for 75% of pods).
if
err
!=
nil
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeWarning
,
"FailedGetCustomMetrics"
,
err
.
Error
())
lastScaleTime
:=
getLastScaleTime
(
hpa
)
if
time
.
Now
()
.
After
(
lastScaleTime
.
Add
(
upscaleForbiddenWindow
))
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeWarning
,
"FailedGetCustomMetrics"
,
err
.
Error
())
}
else
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeNormal
,
"CustomMetricsNotAvailableYet"
,
err
.
Error
())
}
return
0
,
""
,
""
,
time
.
Time
{},
fmt
.
Errorf
(
"failed to get custom metric value: %v"
,
err
)
}
floatTarget
:=
float64
(
customMetricTarget
.
TargetValue
.
MilliValue
())
/
1000.0
...
...
@@ -298,7 +319,14 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
cpuDesiredReplicas
,
cpuCurrentUtilization
,
cpuTimestamp
,
err
=
a
.
computeReplicasForCPUUtilization
(
hpa
,
scale
)
if
err
!=
nil
{
a
.
updateCurrentReplicasInStatus
(
hpa
,
currentReplicas
)
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeWarning
,
"FailedComputeReplicas"
,
err
.
Error
())
lastScaleTime
:=
getLastScaleTime
(
hpa
)
if
time
.
Now
()
.
After
(
lastScaleTime
.
Add
(
upscaleForbiddenWindow
))
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeWarning
,
"FailedComputeReplicas"
,
err
.
Error
())
}
else
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeNormal
,
"FailedComputeReplicas"
,
err
.
Error
())
}
return
fmt
.
Errorf
(
"failed to compute desired number of replicas based on CPU utilization for %s: %v"
,
reference
,
err
)
}
}
...
...
@@ -307,7 +335,14 @@ func (a *HorizontalController) reconcileAutoscaler(hpa *autoscaling.HorizontalPo
cmDesiredReplicas
,
cmMetric
,
cmStatus
,
cmTimestamp
,
err
=
a
.
computeReplicasForCustomMetrics
(
hpa
,
scale
,
cmAnnotation
)
if
err
!=
nil
{
a
.
updateCurrentReplicasInStatus
(
hpa
,
currentReplicas
)
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeWarning
,
"FailedComputeCMReplicas"
,
err
.
Error
())
lastScaleTime
:=
getLastScaleTime
(
hpa
)
if
time
.
Now
()
.
After
(
lastScaleTime
.
Add
(
upscaleForbiddenWindow
))
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeWarning
,
"FailedComputeCMReplicas"
,
err
.
Error
())
}
else
{
a
.
eventRecorder
.
Event
(
hpa
,
api
.
EventTypeNormal
,
"FailedComputeCMReplicas"
,
err
.
Error
())
}
return
fmt
.
Errorf
(
"failed to compute desired number of replicas based on Custom Metrics for %s: %v"
,
reference
,
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