Merge pull request #5696 from kisieland/orchestrator-update-expansion-build
Extract 'SchedulablePods' method in orchestrator.
This commit is contained in:
commit
fe10c53f9a
|
|
@ -156,11 +156,7 @@ func (o *ScaleUpOrchestrator) ScaleUp(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
option, err := o.ComputeExpansionOption(podEquivalenceGroups, nodeGroup, nodeInfo, upcomingNodes)
|
option := o.ComputeExpansionOption(podEquivalenceGroups, nodeGroup, nodeInfo, upcomingNodes)
|
||||||
if err != nil {
|
|
||||||
return scaleUpError(&status.ScaleUpStatus{}, errors.ToAutoscalerError(errors.InternalError, err))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(option.Pods) > 0 && option.NodeCount > 0 {
|
if len(option.Pods) > 0 && option.NodeCount > 0 {
|
||||||
expansionOptions[nodeGroup.Id()] = option
|
expansionOptions[nodeGroup.Id()] = option
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -236,11 +232,7 @@ func (o *ScaleUpOrchestrator) ScaleUp(
|
||||||
}
|
}
|
||||||
nodeInfos[nodeGroup.Id()] = nodeInfo
|
nodeInfos[nodeGroup.Id()] = nodeInfo
|
||||||
|
|
||||||
option, err := o.ComputeExpansionOption(podEquivalenceGroups, nodeGroup, nodeInfo, upcomingNodes)
|
option := o.ComputeExpansionOption(podEquivalenceGroups, nodeGroup, nodeInfo, upcomingNodes)
|
||||||
if err != nil {
|
|
||||||
return scaleUpError(&status.ScaleUpStatus{PodsTriggeredScaleUp: bestOption.Pods}, errors.ToAutoscalerError(errors.InternalError, err))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(option.Pods) > 0 && option.NodeCount > 0 {
|
if len(option.Pods) > 0 && option.NodeCount > 0 {
|
||||||
expansionOptions[nodeGroup.Id()] = option
|
expansionOptions[nodeGroup.Id()] = option
|
||||||
}
|
}
|
||||||
|
|
@ -436,30 +428,47 @@ func (o *ScaleUpOrchestrator) ComputeExpansionOption(
|
||||||
nodeGroup cloudprovider.NodeGroup,
|
nodeGroup cloudprovider.NodeGroup,
|
||||||
nodeInfo *schedulerframework.NodeInfo,
|
nodeInfo *schedulerframework.NodeInfo,
|
||||||
upcomingNodes []*schedulerframework.NodeInfo,
|
upcomingNodes []*schedulerframework.NodeInfo,
|
||||||
) (expander.Option, error) {
|
) expander.Option {
|
||||||
option := expander.Option{
|
option := expander.Option{
|
||||||
NodeGroup: nodeGroup,
|
NodeGroup: nodeGroup,
|
||||||
Pods: make([]*apiv1.Pod, 0),
|
Pods: make([]*apiv1.Pod, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
option.Pods = o.SchedulablePods(podEquivalenceGroups, nodeGroup, nodeInfo)
|
||||||
|
if len(option.Pods) > 0 {
|
||||||
|
estimator := o.autoscalingContext.EstimatorBuilder(o.autoscalingContext.PredicateChecker, o.autoscalingContext.ClusterSnapshot)
|
||||||
|
option.NodeCount, option.Pods = estimator.Estimate(option.Pods, nodeInfo, option.NodeGroup)
|
||||||
|
}
|
||||||
|
|
||||||
|
return option
|
||||||
|
}
|
||||||
|
|
||||||
|
// SchedulablePods returns a list of pods that could be scheduled
|
||||||
|
// in a given node group after a scale up.
|
||||||
|
func (o *ScaleUpOrchestrator) SchedulablePods(
|
||||||
|
podEquivalenceGroups []*equivalence.PodGroup,
|
||||||
|
nodeGroup cloudprovider.NodeGroup,
|
||||||
|
nodeInfo *schedulerframework.NodeInfo,
|
||||||
|
) []*apiv1.Pod {
|
||||||
o.autoscalingContext.ClusterSnapshot.Fork()
|
o.autoscalingContext.ClusterSnapshot.Fork()
|
||||||
|
defer o.autoscalingContext.ClusterSnapshot.Revert()
|
||||||
|
|
||||||
// Add test node to snapshot.
|
// Add test node to snapshot.
|
||||||
var pods []*apiv1.Pod
|
var allPods []*apiv1.Pod
|
||||||
for _, podInfo := range nodeInfo.Pods {
|
for _, podInfo := range nodeInfo.Pods {
|
||||||
pods = append(pods, podInfo.Pod)
|
allPods = append(allPods, podInfo.Pod)
|
||||||
}
|
}
|
||||||
if err := o.autoscalingContext.ClusterSnapshot.AddNodeWithPods(nodeInfo.Node(), pods); err != nil {
|
if err := o.autoscalingContext.ClusterSnapshot.AddNodeWithPods(nodeInfo.Node(), allPods); err != nil {
|
||||||
klog.Errorf("Error while adding test Node: %v", err)
|
klog.Errorf("Error while adding test Node: %v", err)
|
||||||
o.autoscalingContext.ClusterSnapshot.Revert()
|
return []*apiv1.Pod{}
|
||||||
return expander.Option{}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var schedulablePods []*apiv1.Pod
|
||||||
for _, eg := range podEquivalenceGroups {
|
for _, eg := range podEquivalenceGroups {
|
||||||
samplePod := eg.Pods[0]
|
samplePod := eg.Pods[0]
|
||||||
if err := o.autoscalingContext.PredicateChecker.CheckPredicates(o.autoscalingContext.ClusterSnapshot, samplePod, nodeInfo.Node().Name); err == nil {
|
if err := o.autoscalingContext.PredicateChecker.CheckPredicates(o.autoscalingContext.ClusterSnapshot, samplePod, nodeInfo.Node().Name); err == nil {
|
||||||
// Add pods to option.
|
// Add pods to option.
|
||||||
option.Pods = append(option.Pods, eg.Pods...)
|
schedulablePods = append(schedulablePods, eg.Pods...)
|
||||||
// Mark pod group as (theoretically) schedulable.
|
// Mark pod group as (theoretically) schedulable.
|
||||||
eg.Schedulable = true
|
eg.Schedulable = true
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -471,14 +480,7 @@ func (o *ScaleUpOrchestrator) ComputeExpansionOption(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o.autoscalingContext.ClusterSnapshot.Revert()
|
return schedulablePods
|
||||||
|
|
||||||
if len(option.Pods) > 0 {
|
|
||||||
estimator := o.autoscalingContext.EstimatorBuilder(o.autoscalingContext.PredicateChecker, o.autoscalingContext.ClusterSnapshot)
|
|
||||||
option.NodeCount, option.Pods = estimator.Estimate(option.Pods, nodeInfo, option.NodeGroup)
|
|
||||||
}
|
|
||||||
|
|
||||||
return option, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpcomingNodes returns a list of nodes that are not ready but should be.
|
// UpcomingNodes returns a list of nodes that are not ready but should be.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue