Zero placements for rebalancing
@@ -259,14 +259,8 @@ func (s *StatefulSetScheduler) scheduleVPod(vpod scheduler.VPod) ([]duckv1alpha1
}
func (s *StatefulSetScheduler) rebalanceReplicasWithPolicy(vpod scheduler.VPod, diff int32, placements []duckv1alpha1.Placement) ([]duckv1alpha1.Placement, int32) {
- newPlacements := make([]duckv1alpha1.Placement, len(placements))
- for i := 0; i < len(placements); i++ {
- newPlacements[i].PodName = placements[i].PodName
- newPlacements[i].VReplicas = 0
- }
- s.reservePlacements(vpod, newPlacements)
-
- placements, diff = s.addReplicasWithPolicy(vpod, diff, newPlacements)
+ s.makeZeroPlacements(vpod, placements)
+ placements, diff = s.addReplicasWithPolicy(vpod, diff, make([]duckv1alpha1.Placement, 0)) //start fresh with a new placements list
return placements, diff
}
@@ -719,3 +713,14 @@ func (s *StatefulSetScheduler) reservePlacements(vpod scheduler.VPod, placements
}
}
+
+func (s *StatefulSetScheduler) makeZeroPlacements(vpod scheduler.VPod, placements []duckv1alpha1.Placement) {
+ newPlacements := make([]duckv1alpha1.Placement, len(placements))
+ for i := 0; i < len(placements); i++ {
+ newPlacements[i].PodName = placements[i].PodName
+ newPlacements[i].VReplicas = 0
+ }
+ // This is necessary to make sure State() zeroes out initial pod/node/zone spread and
+ // free capacity when there are existing placements for a vpod
+ s.reservePlacements(vpod, newPlacements)
+}
