Mark BasicEstimator as deprecated

This commit is contained in:
Aleksandra Malinowska 2018-07-20 18:09:44 +02:00
parent bf6ff4be8e
commit d9f804c686
2 changed files with 24 additions and 6 deletions

View File

@ -21,14 +21,20 @@ import (
"fmt"
"math"
"github.com/golang/glog"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
schedulercache "k8s.io/kubernetes/pkg/scheduler/cache"
)
const basicEstimatorDeprecationMessage = "WARNING: basic estimator is deprecated. It will be removed in Cluster Autoscaler 1.5."
// BasicNodeEstimator estimates the number of needed nodes to handle the given amount of pods.
// It will never overestimate the number of nodes but is quite likely to provide a number that
// is too small.
//
// Deprecated.
// TODO(aleksandra-malinowska): remove this in 1.5.
type BasicNodeEstimator struct {
cpuSum resource.Quantity
memorySum resource.Quantity
@ -38,6 +44,7 @@ type BasicNodeEstimator struct {
// NewBasicNodeEstimator builds BasicNodeEstimator.
func NewBasicNodeEstimator() *BasicNodeEstimator {
glog.Warning(basicEstimatorDeprecationMessage)
return &BasicNodeEstimator{
portSum: make(map[int32]int),
FittingPods: make(map[*apiv1.Pod]struct{}),

View File

@ -19,6 +19,7 @@ package estimator
import (
"fmt"
"github.com/golang/glog"
apiv1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/cluster-autoscaler/simulator"
schedulercache "k8s.io/kubernetes/pkg/scheduler/cache"
@ -31,25 +32,35 @@ const (
BinpackingEstimatorName = "binpacking"
)
// AvailableEstimators is a list of available estimators.
var AvailableEstimators = []string{BasicEstimatorName, BinpackingEstimatorName}
func deprecated(name string) string {
return fmt.Sprintf("%s (DEPRECATED)", name)
}
// AvailableEstimators is a list of available estimators.
var AvailableEstimators = []string{BinpackingEstimatorName, deprecated(BasicEstimatorName)}
// Estimator calculates the number of nodes of given type needed to schedule pods.
type Estimator interface {
Estimate([]*apiv1.Pod, *schedulercache.NodeInfo, []*schedulercache.NodeInfo) int
}
// EstimatorBuilder creates a new estimator object.
type EstimatorBuilder func(*simulator.PredicateChecker) Estimator
// NewEstimatorBuilder creates a new estimator object from flag.
func NewEstimatorBuilder(name string) (EstimatorBuilder, error) {
switch name {
case BasicEstimatorName:
return func(_ *simulator.PredicateChecker) Estimator {
return NewBasicNodeEstimator()
}, nil
case BinpackingEstimatorName:
return func(predicateChecker *simulator.PredicateChecker) Estimator {
return NewBinpackingNodeEstimator(predicateChecker)
}, nil
// Deprecated.
// TODO(aleksandra-malinowska): remove in 1.5.
case BasicEstimatorName:
glog.Warning(basicEstimatorDeprecationMessage)
return func(_ *simulator.PredicateChecker) Estimator {
return NewBasicNodeEstimator()
}, nil
}
return nil, fmt.Errorf("Unknown estimator: %s", name)
}