Merge pull request #777 from Garrybest/pr_pod_estimator
add pod constraint in general estimator
This commit is contained in:
commit
b961a7e976
|
@ -1,8 +1,6 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
||||||
|
@ -33,13 +31,19 @@ func (ge *GeneralEstimator) MaxAvailableReplicas(clusters []*clusterv1alpha1.Clu
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ge *GeneralEstimator) maxAvailableReplicas(cluster *clusterv1alpha1.Cluster, replicaRequirements *workv1alpha2.ReplicaRequirements) int32 {
|
func (ge *GeneralEstimator) maxAvailableReplicas(cluster *clusterv1alpha1.Cluster, replicaRequirements *workv1alpha2.ReplicaRequirements) int32 {
|
||||||
var maximumReplicas int64 = math.MaxInt32
|
|
||||||
resourceSummary := cluster.Status.ResourceSummary
|
resourceSummary := cluster.Status.ResourceSummary
|
||||||
|
|
||||||
if resourceSummary == nil {
|
if resourceSummary == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allowedPodNumber := resourceSummary.Allocatable.Pods().Value() - resourceSummary.Allocated.Pods().Value() - resourceSummary.Allocating.Pods().Value()
|
||||||
|
// When too many pods have been created, scheduling will fail so that the allocating pods number may be huge.
|
||||||
|
// If allowedPodNumber is less than 0, we don't allow more pods to be created.
|
||||||
|
if allowedPodNumber <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
maximumReplicas := allowedPodNumber
|
||||||
|
|
||||||
for key, value := range replicaRequirements.ResourceRequest {
|
for key, value := range replicaRequirements.ResourceRequest {
|
||||||
requestedQuantity := value.Value()
|
requestedQuantity := value.Value()
|
||||||
if requestedQuantity <= 0 {
|
if requestedQuantity <= 0 {
|
||||||
|
|
Loading…
Reference in New Issue