mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-22 18:16:52 +00:00
hpa: always update status metrics when updating the replica count
Have hpa always update both the metrics and replica count. This fix an edge case behavior bug where the metrics would not be updated if a custom metrics was unavailable.
This commit is contained in:
parent
9bea6bda05
commit
3c4512c6cc
@ -836,7 +836,7 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare
|
||||
// computeReplicasForMetrics may return both non-zero metricDesiredReplicas and an error.
|
||||
// That means some metrics still work and HPA should perform scaling based on them.
|
||||
if err != nil && metricDesiredReplicas == -1 {
|
||||
a.setCurrentReplicasInStatus(hpa, currentReplicas)
|
||||
a.setCurrentReplicasAndMetricsInStatus(hpa, currentReplicas, metricStatuses)
|
||||
if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil {
|
||||
utilruntime.HandleError(err)
|
||||
}
|
||||
@ -879,7 +879,7 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare
|
||||
if err != nil {
|
||||
a.eventRecorder.Eventf(hpa, v1.EventTypeWarning, "FailedRescale", "New size: %d; reason: %s; error: %v", desiredReplicas, rescaleReason, err.Error())
|
||||
setCondition(hpa, autoscalingv2.AbleToScale, v1.ConditionFalse, "FailedUpdateScale", "the HPA controller was unable to update the target scale: %v", err)
|
||||
a.setCurrentReplicasInStatus(hpa, currentReplicas)
|
||||
a.setCurrentReplicasAndMetricsInStatus(hpa, currentReplicas, metricStatuses)
|
||||
if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil {
|
||||
utilruntime.HandleError(err)
|
||||
}
|
||||
@ -1357,9 +1357,9 @@ func (a *HorizontalController) scaleForResourceMappings(ctx context.Context, nam
|
||||
return nil, schema.GroupResource{}, firstErr
|
||||
}
|
||||
|
||||
// setCurrentReplicasInStatus sets the current replica count in the status of the HPA.
|
||||
func (a *HorizontalController) setCurrentReplicasInStatus(hpa *autoscalingv2.HorizontalPodAutoscaler, currentReplicas int32) {
|
||||
a.setStatus(hpa, currentReplicas, hpa.Status.DesiredReplicas, hpa.Status.CurrentMetrics, false)
|
||||
// setCurrentReplicasAndMetricsInStatus sets the current replica count and metrics in the status of the HPA.
|
||||
func (a *HorizontalController) setCurrentReplicasAndMetricsInStatus(hpa *autoscalingv2.HorizontalPodAutoscaler, currentReplicas int32, metricStatuses []autoscalingv2.MetricStatus) {
|
||||
a.setStatus(hpa, currentReplicas, hpa.Status.DesiredReplicas, metricStatuses, false)
|
||||
}
|
||||
|
||||
// setStatus recreates the status of the given HPA, updating the current and
|
||||
|
Loading…
Reference in New Issue
Block a user