Skip to content

Commit

Permalink
Merge pull request #5974 from azylinski/add-estimator-PostPackingFunc
Browse files Browse the repository at this point in the history
Add PostPackingFunc to be run at the end of the estimation logic
  • Loading branch information
k8s-ci-robot authored Jul 26, 2023
2 parents 8c749fc + 21229d3 commit 63eab4e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions cluster-autoscaler/core/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func initializeDefaultOptions(opts *AutoscalerOptions) error {
opts.EstimatorName,
estimator.NewThresholdBasedEstimationLimiter(thresholds),
estimator.NewDecreasingPodOrderer(),
/* EstimationAnalyserFunc */ nil,
)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cluster-autoscaler/core/test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func NewScaleTestAutoscalingContext(
options.EstimatorName,
estimator.NewThresholdBasedEstimationLimiter(nil),
estimator.NewDecreasingPodOrderer(),
/* EstimationAnalyserFunc */ nil,
)
predicateChecker, err := predicatechecker.NewTestPredicateChecker()
if err != nil {
Expand Down
28 changes: 18 additions & 10 deletions cluster-autoscaler/estimator/binpacking_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import (

// BinpackingNodeEstimator estimates the number of needed nodes to handle the given amount of pods.
type BinpackingNodeEstimator struct {
predicateChecker predicatechecker.PredicateChecker
clusterSnapshot clustersnapshot.ClusterSnapshot
limiter EstimationLimiter
podOrderer EstimationPodOrderer
context EstimationContext
predicateChecker predicatechecker.PredicateChecker
clusterSnapshot clustersnapshot.ClusterSnapshot
limiter EstimationLimiter
podOrderer EstimationPodOrderer
context EstimationContext
estimationAnalyserFunc EstimationAnalyserFunc // optional
}

// NewBinpackingNodeEstimator builds a new BinpackingNodeEstimator.
Expand All @@ -44,13 +45,15 @@ func NewBinpackingNodeEstimator(
limiter EstimationLimiter,
podOrderer EstimationPodOrderer,
context EstimationContext,
estimationAnalyserFunc EstimationAnalyserFunc,
) *BinpackingNodeEstimator {
return &BinpackingNodeEstimator{
predicateChecker: predicateChecker,
clusterSnapshot: clusterSnapshot,
limiter: limiter,
podOrderer: podOrderer,
context: context,
predicateChecker: predicateChecker,
clusterSnapshot: clusterSnapshot,
limiter: limiter,
podOrderer: podOrderer,
context: context,
estimationAnalyserFunc: estimationAnalyserFunc,
}
}

Expand Down Expand Up @@ -141,6 +144,11 @@ func (e *BinpackingNodeEstimator) Estimate(
scheduledPods = append(scheduledPods, pod)
}
}

if e.estimationAnalyserFunc != nil {
e.estimationAnalyserFunc(e.clusterSnapshot, nodeGroup, newNodesWithPods)
}

return len(newNodesWithPods), scheduledPods
}

Expand Down
3 changes: 1 addition & 2 deletions cluster-autoscaler/estimator/binpacking_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ func TestBinpackingEstimate(t *testing.T) {
assert.NoError(t, err)
limiter := NewThresholdBasedEstimationLimiter([]Threshold{NewStaticThreshold(tc.maxNodes, time.Duration(0))})
processor := NewDecreasingPodOrderer()
estimator := NewBinpackingNodeEstimator(predicateChecker, clusterSnapshot, limiter, processor, nil)

estimator := NewBinpackingNodeEstimator(predicateChecker, clusterSnapshot, limiter, processor, nil /* EstimationContext */, nil /* EstimationAnalyserFunc */)
node := makeNode(tc.millicores, tc.memory, "template", "zone-mars")
nodeInfo := schedulerframework.NewNodeInfo()
nodeInfo.SetNode(node)
Expand Down
7 changes: 5 additions & 2 deletions cluster-autoscaler/estimator/estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ type Estimator interface {
// EstimatorBuilder creates a new estimator object.
type EstimatorBuilder func(predicatechecker.PredicateChecker, clustersnapshot.ClusterSnapshot, EstimationContext) Estimator

// EstimationAnalyserFunc to be run at the end of the estimation logic.
type EstimationAnalyserFunc func(clustersnapshot.ClusterSnapshot, cloudprovider.NodeGroup, map[string]bool)

// NewEstimatorBuilder creates a new estimator object from flag.
func NewEstimatorBuilder(name string, limiter EstimationLimiter, orderer EstimationPodOrderer) (EstimatorBuilder, error) {
func NewEstimatorBuilder(name string, limiter EstimationLimiter, orderer EstimationPodOrderer, estimationAnalyserFunc EstimationAnalyserFunc) (EstimatorBuilder, error) {
switch name {
case BinpackingEstimatorName:
return func(
predicateChecker predicatechecker.PredicateChecker,
clusterSnapshot clustersnapshot.ClusterSnapshot,
context EstimationContext) Estimator {
return NewBinpackingNodeEstimator(predicateChecker, clusterSnapshot, limiter, orderer, context)
return NewBinpackingNodeEstimator(predicateChecker, clusterSnapshot, limiter, orderer, context, estimationAnalyserFunc)
}, nil
}
return nil, fmt.Errorf("unknown estimator: %s", name)
Expand Down

0 comments on commit 63eab4e

Please sign in to comment.