Skip to content

Commit

Permalink
Merge pull request #4082 from ctripcloud/fix-replicas-syncer
Browse files Browse the repository at this point in the history
use status.DesiredReplicas instead of status.CurrentReplicas of HPA to update resource scale
  • Loading branch information
karmada-bot authored Sep 22, 2023
2 parents 681515f + 8a56a8d commit 48b8e9f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ func (r *HPAReplicasSyncer) updateScaleIfNeed(ctx context.Context, workloadGR sc
return nil
}

if scale.Spec.Replicas != hpa.Status.CurrentReplicas {
if scale.Spec.Replicas != hpa.Status.DesiredReplicas {
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{})
if err != nil {
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
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestUpdateScaleIfNeed(t *testing.T) {
return
}

assert.Equal(t, tt.hpa.Status.CurrentReplicas, scale.Spec.Replicas)
assert.Equal(t, tt.hpa.Status.DesiredReplicas, scale.Spec.Replicas)
})
}
}
Expand Down Expand Up @@ -307,7 +307,7 @@ func newHPA(apiVersion, kind, name string, replicas int32) *autoscalingv2.Horizo
},
},
Status: autoscalingv2.HorizontalPodAutoscalerStatus{
CurrentReplicas: replicas,
DesiredReplicas: replicas,
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (r *HPAReplicasSyncer) Update(e event.UpdateEvent) bool {
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 {
Expand Down

0 comments on commit 48b8e9f

Please sign in to comment.