Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostPackingFunc to be run at the end of the estimation logic #5974

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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