@@ -53,13 +53,22 @@ func getDefaultWeightPreference(clusters []*clusterv1alpha1.Cluster) *policyv1al
5353
5454func calAvailableReplicas (clusters []* clusterv1alpha1.Cluster , spec * workv1alpha2.ResourceBindingSpec ) []workv1alpha2.TargetCluster {
5555 availableTargetClusters := make ([]workv1alpha2.TargetCluster , len (clusters ))
56+ // availableResultPriority indicates which priority Estimator gives the scheduling result for each cluster, respectively
57+ // 1. Higher-priority estimator can directly override the result given by lower-priority estimator
58+ // 2. Lower replicas estimated will be chosen if the priority of estimator are same
59+ // 3. Lower-priority estimator would be ignored if the result was already given by higher-priority estimator
60+ availableResultPriority := make ([]estimatorclient.EstimatorPriority , len (clusters ))
5661
5762 // Set the boundary.
5863 for i := range availableTargetClusters {
5964 availableTargetClusters [i ].Name = clusters [i ].Name
6065 availableTargetClusters [i ].Replicas = math .MaxInt32
6166 }
6267
68+ for i := range availableResultPriority {
69+ availableResultPriority [i ] = estimatorclient .Undefined
70+ }
71+
6372 // For non-workload, like ServiceAccount, ConfigMap, Secret and etc, it's unnecessary to calculate available replicas in member clusters.
6473 // See issue: https://github.com/karmada-io/karmada/issues/3743.
6574 if spec .Replicas == 0 {
@@ -79,11 +88,21 @@ func calAvailableReplicas(clusters []*clusterv1alpha1.Cluster, spec *workv1alpha
7988 continue
8089 }
8190 for i := range res {
91+ if res [i ].Name != availableTargetClusters [i ].Name {
92+ continue
93+ }
8294 if res [i ].Replicas == estimatorclient .UnauthenticReplica {
8395 continue
8496 }
85- if availableTargetClusters [i ].Name == res [i ].Name && availableTargetClusters [i ].Replicas > res [i ].Replicas {
97+ // means there are already replicas calculated by higher-priority estimator
98+ if estimator .GetPriority () < availableResultPriority [i ] {
99+ continue
100+ }
101+ // override if current estimator has higher priority and take lower replicas is estimator priority are same
102+ if (estimator .GetPriority () == availableResultPriority [i ] && res [i ].Replicas < availableTargetClusters [i ].Replicas ) ||
103+ estimator .GetPriority () > availableResultPriority [i ] {
86104 availableTargetClusters [i ].Replicas = res [i ].Replicas
105+ availableResultPriority [i ] = estimator .GetPriority ()
87106 }
88107 }
89108 }
0 commit comments