mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #121039 from josselin-c/master
hpa: always update status metrics when updating the replica count
This commit is contained in:
commit
99bf6a674c
@ -836,7 +836,7 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare
|
|||||||
// computeReplicasForMetrics may return both non-zero metricDesiredReplicas and an error.
|
// computeReplicasForMetrics may return both non-zero metricDesiredReplicas and an error.
|
||||||
// That means some metrics still work and HPA should perform scaling based on them.
|
// That means some metrics still work and HPA should perform scaling based on them.
|
||||||
if err != nil && metricDesiredReplicas == -1 {
|
if err != nil && metricDesiredReplicas == -1 {
|
||||||
a.setCurrentReplicasInStatus(hpa, currentReplicas)
|
a.setCurrentReplicasAndMetricsInStatus(hpa, currentReplicas, metricStatuses)
|
||||||
if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil {
|
if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil {
|
||||||
utilruntime.HandleError(err)
|
utilruntime.HandleError(err)
|
||||||
}
|
}
|
||||||
@ -879,7 +879,7 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
a.eventRecorder.Eventf(hpa, v1.EventTypeWarning, "FailedRescale", "New size: %d; reason: %s; error: %v", desiredReplicas, rescaleReason, err.Error())
|
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)
|
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 {
|
if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil {
|
||||||
utilruntime.HandleError(err)
|
utilruntime.HandleError(err)
|
||||||
}
|
}
|
||||||
@ -1357,9 +1357,9 @@ func (a *HorizontalController) scaleForResourceMappings(ctx context.Context, nam
|
|||||||
return nil, schema.GroupResource{}, firstErr
|
return nil, schema.GroupResource{}, firstErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// setCurrentReplicasInStatus sets the current replica count in the status of the HPA.
|
// setCurrentReplicasAndMetricsInStatus sets the current replica count and metrics in the status of the HPA.
|
||||||
func (a *HorizontalController) setCurrentReplicasInStatus(hpa *autoscalingv2.HorizontalPodAutoscaler, currentReplicas int32) {
|
func (a *HorizontalController) setCurrentReplicasAndMetricsInStatus(hpa *autoscalingv2.HorizontalPodAutoscaler, currentReplicas int32, metricStatuses []autoscalingv2.MetricStatus) {
|
||||||
a.setStatus(hpa, currentReplicas, hpa.Status.DesiredReplicas, hpa.Status.CurrentMetrics, false)
|
a.setStatus(hpa, currentReplicas, hpa.Status.DesiredReplicas, metricStatuses, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// setStatus recreates the status of the given HPA, updating the current and
|
// setStatus recreates the status of the given HPA, updating the current and
|
||||||
|
Loading…
Reference in New Issue
Block a user