fix: when matchClusters is empty controller will crash

Signed-off-by: phantooom <xiaorui.zou@gmail.com>
This commit is contained in:
phantooom 2021-09-23 13:20:53 +08:00
parent ebcd58473c
commit b9929128b3
1 changed files with 1 additions and 1 deletions

View File

@ -288,7 +288,7 @@ func calculateReplicas(c client.Client, policy *policyv1alpha1.ReplicaScheduling
allocatedReplicas += int32(desireReplicaInfos[clusterName])
}
if remainReplicas := policy.Spec.TotalReplicas - allocatedReplicas; remainReplicas > 0 {
if remainReplicas := policy.Spec.TotalReplicas - allocatedReplicas; remainReplicas > 0 && len(matchClusters) > 0 {
sortedClusters := helper.SortClusterByWeight(matchClusters)
for i := 0; remainReplicas > 0; i++ {
desireReplicaInfos[sortedClusters[i].ClusterName]++