use status.DesiredReplicas instead of status.CurrentReplicas of HPA to update resource scale
Signed-off-by: lxtywypc <lxtywypc@gmail.com>
This commit is contained in:
parent
681515fbf6
commit
8a56a8dc34
|
@ -126,19 +126,19 @@ func (r *HPAReplicasSyncer) updateScaleIfNeed(ctx context.Context, workloadGR sc
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if scale.Spec.Replicas != hpa.Status.CurrentReplicas {
|
if scale.Spec.Replicas != hpa.Status.DesiredReplicas {
|
||||||
oldReplicas := scale.Spec.Replicas
|
oldReplicas := scale.Spec.Replicas
|
||||||
|
|
||||||
scale.Spec.Replicas = hpa.Status.CurrentReplicas
|
scale.Spec.Replicas = hpa.Status.DesiredReplicas
|
||||||
_, err := r.ScaleClient.Scales(hpa.Namespace).Update(ctx, workloadGR, scale, metav1.UpdateOptions{})
|
_, err := r.ScaleClient.Scales(hpa.Namespace).Update(ctx, workloadGR, scale, metav1.UpdateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to try to sync scale for resource(kind=%s, %s/%s) from %d to %d: %v",
|
klog.Errorf("Failed to try to sync scale for resource(kind=%s, %s/%s) from %d to %d: %v",
|
||||||
hpa.Spec.ScaleTargetRef.Kind, hpa.Namespace, hpa.Spec.ScaleTargetRef.Name, oldReplicas, hpa.Status.CurrentReplicas, err)
|
hpa.Spec.ScaleTargetRef.Kind, hpa.Namespace, hpa.Spec.ScaleTargetRef.Name, oldReplicas, hpa.Status.DesiredReplicas, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.V(4).Infof("Successfully synced scale for resource(kind=%s, %s/%s) from %d to %d",
|
klog.V(4).Infof("Successfully synced scale for resource(kind=%s, %s/%s) from %d to %d",
|
||||||
hpa.Spec.ScaleTargetRef.Kind, hpa.Namespace, hpa.Spec.ScaleTargetRef.Name, oldReplicas, hpa.Status.CurrentReplicas)
|
hpa.Spec.ScaleTargetRef.Kind, hpa.Namespace, hpa.Spec.ScaleTargetRef.Name, oldReplicas, hpa.Status.DesiredReplicas)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -147,7 +147,7 @@ func TestUpdateScaleIfNeed(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, tt.hpa.Status.CurrentReplicas, scale.Spec.Replicas)
|
assert.Equal(t, tt.hpa.Status.DesiredReplicas, scale.Spec.Replicas)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,7 +307,7 @@ func newHPA(apiVersion, kind, name string, replicas int32) *autoscalingv2.Horizo
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Status: autoscalingv2.HorizontalPodAutoscalerStatus{
|
Status: autoscalingv2.HorizontalPodAutoscalerStatus{
|
||||||
CurrentReplicas: replicas,
|
DesiredReplicas: replicas,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (r *HPAReplicasSyncer) Update(e event.UpdateEvent) bool {
|
||||||
r.scaleRefWorker.Add(labelEvent{addLabelEvent, newHPA})
|
r.scaleRefWorker.Add(labelEvent{addLabelEvent, newHPA})
|
||||||
}
|
}
|
||||||
|
|
||||||
return oldHPA.Status.CurrentReplicas != newHPA.Status.CurrentReplicas
|
return oldHPA.Status.DesiredReplicas != newHPA.Status.DesiredReplicas
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HPAReplicasSyncer) Delete(e event.DeleteEvent) bool {
|
func (r *HPAReplicasSyncer) Delete(e event.DeleteEvent) bool {
|
||||||
|
|
Loading…
Reference in New Issue