Add new method 'ReachedLimit' to EstimationLimiter
This method will allow CA to check if any the limiter blocked addition of any new Node.
This commit is contained in:
parent
1009797f55
commit
3ad77e8341
|
|
@ -71,4 +71,7 @@ type EstimationLimiter interface {
|
||||||
// There is no requirement for the Estimator to stop calculations, it's
|
// There is no requirement for the Estimator to stop calculations, it's
|
||||||
// just not expected to add any more nodes.
|
// just not expected to add any more nodes.
|
||||||
PermissionToAddNode() bool
|
PermissionToAddNode() bool
|
||||||
|
// ReachedLimit returns true if the limiter blocked addition of the new node.
|
||||||
|
// Otherwise returns false.
|
||||||
|
ReachedLimit() bool
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,13 @@ type thresholdBasedEstimationLimiter struct {
|
||||||
maxNodes int
|
maxNodes int
|
||||||
nodes int
|
nodes int
|
||||||
start time.Time
|
start time.Time
|
||||||
|
reachedLimit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tbel *thresholdBasedEstimationLimiter) StartEstimation([]*apiv1.Pod, cloudprovider.NodeGroup) {
|
func (tbel *thresholdBasedEstimationLimiter) StartEstimation([]*apiv1.Pod, cloudprovider.NodeGroup) {
|
||||||
tbel.start = time.Now()
|
tbel.start = time.Now()
|
||||||
tbel.nodes = 0
|
tbel.nodes = 0
|
||||||
|
tbel.reachedLimit = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*thresholdBasedEstimationLimiter) EndEstimation() {}
|
func (*thresholdBasedEstimationLimiter) EndEstimation() {}
|
||||||
|
|
@ -41,17 +43,23 @@ func (*thresholdBasedEstimationLimiter) EndEstimation() {}
|
||||||
func (tbel *thresholdBasedEstimationLimiter) PermissionToAddNode() bool {
|
func (tbel *thresholdBasedEstimationLimiter) PermissionToAddNode() bool {
|
||||||
if tbel.maxNodes > 0 && tbel.nodes >= tbel.maxNodes {
|
if tbel.maxNodes > 0 && tbel.nodes >= tbel.maxNodes {
|
||||||
klog.V(4).Infof("Capping binpacking after exceeding threshold of %d nodes", tbel.maxNodes)
|
klog.V(4).Infof("Capping binpacking after exceeding threshold of %d nodes", tbel.maxNodes)
|
||||||
|
tbel.reachedLimit = true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
timeDefined := tbel.maxDuration > 0 && tbel.start != time.Time{}
|
timeDefined := tbel.maxDuration > 0 && tbel.start != time.Time{}
|
||||||
if timeDefined && time.Now().After(tbel.start.Add(tbel.maxDuration)) {
|
if timeDefined && time.Now().After(tbel.start.Add(tbel.maxDuration)) {
|
||||||
klog.V(4).Infof("Capping binpacking after exceeding max duration of %v", tbel.maxDuration)
|
klog.V(4).Infof("Capping binpacking after exceeding max duration of %v", tbel.maxDuration)
|
||||||
|
tbel.reachedLimit = true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
tbel.nodes++
|
tbel.nodes++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tbel *thresholdBasedEstimationLimiter) ReachedLimit() bool {
|
||||||
|
return tbel.reachedLimit
|
||||||
|
}
|
||||||
|
|
||||||
// NewThresholdBasedEstimationLimiter returns an EstimationLimiter that will prevent estimation
|
// NewThresholdBasedEstimationLimiter returns an EstimationLimiter that will prevent estimation
|
||||||
// after either a node count- of time-based threshold is reached. This is meant to prevent cases
|
// after either a node count- of time-based threshold is reached. This is meant to prevent cases
|
||||||
// where binpacking of hundreds or thousands of nodes takes extremely long time rendering CA
|
// where binpacking of hundreds or thousands of nodes takes extremely long time rendering CA
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ func TestThresholdBasedLimiter(t *testing.T) {
|
||||||
startDelta time.Duration
|
startDelta time.Duration
|
||||||
operations []limiterOperation
|
operations []limiterOperation
|
||||||
expectNodeCount int
|
expectNodeCount int
|
||||||
|
expectedReachedLimit bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no limiting happens",
|
name: "no limiting happens",
|
||||||
|
|
@ -69,6 +70,7 @@ func TestThresholdBasedLimiter(t *testing.T) {
|
||||||
expectDeny,
|
expectDeny,
|
||||||
},
|
},
|
||||||
expectNodeCount: 0,
|
expectNodeCount: 0,
|
||||||
|
expectedReachedLimit: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "sequence of additions works until the threshold is hit",
|
name: "sequence of additions works until the threshold is hit",
|
||||||
|
|
@ -80,6 +82,7 @@ func TestThresholdBasedLimiter(t *testing.T) {
|
||||||
expectDeny,
|
expectDeny,
|
||||||
},
|
},
|
||||||
expectNodeCount: 3,
|
expectNodeCount: 3,
|
||||||
|
expectedReachedLimit: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "node counter is reset",
|
name: "node counter is reset",
|
||||||
|
|
@ -123,6 +126,7 @@ func TestThresholdBasedLimiter(t *testing.T) {
|
||||||
op(t, limiter)
|
op(t, limiter)
|
||||||
}
|
}
|
||||||
assert.Equal(t, tc.expectNodeCount, limiter.nodes)
|
assert.Equal(t, tc.expectNodeCount, limiter.nodes)
|
||||||
|
assert.Equal(t, tc.expectedReachedLimit, limiter.reachedLimit)
|
||||||
limiter.EndEstimation()
|
limiter.EndEstimation()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue