From 81a4721f513a6e1919d6c080e60ce5f9754648d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Wr=C3=B3blewski?= Date: Fri, 6 Oct 2023 13:24:14 +0000 Subject: [PATCH] Extend BinpackingLimiter interface --- .../core/scaleup/orchestrator/orchestrator.go | 3 +++ cluster-autoscaler/core/test/common.go | 9 ++++++--- .../processors/binpacking/binpacking_limiter.go | 11 ++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cluster-autoscaler/core/scaleup/orchestrator/orchestrator.go b/cluster-autoscaler/core/scaleup/orchestrator/orchestrator.go index a9d5ed1e9592..542e45c2d540 100644 --- a/cluster-autoscaler/core/scaleup/orchestrator/orchestrator.go +++ b/cluster-autoscaler/core/scaleup/orchestrator/orchestrator.go @@ -164,6 +164,9 @@ func (o *ScaleUpOrchestrator) ScaleUp( } } + // Finalize binpacking limiter. + o.processors.BinpackingLimiter.FinalizeBinpacking(o.autoscalingContext, options) + if len(options) == 0 { klog.V(1).Info("No expansion options") return &status.ScaleUpStatus{ diff --git a/cluster-autoscaler/core/test/common.go b/cluster-autoscaler/core/test/common.go index 78247b927927..35c582f5d127 100644 --- a/cluster-autoscaler/core/test/common.go +++ b/cluster-autoscaler/core/test/common.go @@ -357,14 +357,17 @@ func (p *MockBinpackingLimiter) InitBinpacking(context *context.AutoscalingConte p.requiredExpansionOptions = 1 } +// MarkProcessed is here to satisfy the interface. +func (p *MockBinpackingLimiter) MarkProcessed(context *context.AutoscalingContext, nodegroupId string) { +} + // StopBinpacking stops the binpacking early, if we already have requiredExpansionOptions i.e. 1. func (p *MockBinpackingLimiter) StopBinpacking(context *context.AutoscalingContext, evaluatedOptions []expander.Option) bool { return len(evaluatedOptions) == p.requiredExpansionOptions } -// MarkProcessed is here to satisfy the interface. -func (p *MockBinpackingLimiter) MarkProcessed(context *context.AutoscalingContext, nodegroupId string) { - +// FinalizeBinpacking is here to satisfy the interface. +func (p *MockBinpackingLimiter) FinalizeBinpacking(context *context.AutoscalingContext, finalOptions []expander.Option) { } // NewBackoff creates a new backoff object diff --git a/cluster-autoscaler/processors/binpacking/binpacking_limiter.go b/cluster-autoscaler/processors/binpacking/binpacking_limiter.go index 3b3ab61ba3f1..e1396ecf79c7 100644 --- a/cluster-autoscaler/processors/binpacking/binpacking_limiter.go +++ b/cluster-autoscaler/processors/binpacking/binpacking_limiter.go @@ -25,8 +25,9 @@ import ( // BinpackingLimiter processes expansion options to stop binpacking early. type BinpackingLimiter interface { InitBinpacking(context *context.AutoscalingContext, nodeGroups []cloudprovider.NodeGroup) - StopBinpacking(context *context.AutoscalingContext, evaluatedOptions []expander.Option) bool MarkProcessed(context *context.AutoscalingContext, nodegroupId string) + StopBinpacking(context *context.AutoscalingContext, evaluatedOptions []expander.Option) bool + FinalizeBinpacking(context *context.AutoscalingContext, finalOptions []expander.Option) } // NoOpBinpackingLimiter returns true without processing expansion options. @@ -42,11 +43,15 @@ func NewDefaultBinpackingLimiter() BinpackingLimiter { func (p *NoOpBinpackingLimiter) InitBinpacking(context *context.AutoscalingContext, nodeGroups []cloudprovider.NodeGroup) { } +// MarkProcessed marks the nodegroup as processed. +func (p *NoOpBinpackingLimiter) MarkProcessed(context *context.AutoscalingContext, nodegroupId string) { +} + // StopBinpacking is used to make decsions on the evaluated expansion options. func (p *NoOpBinpackingLimiter) StopBinpacking(context *context.AutoscalingContext, evaluatedOptions []expander.Option) bool { return false } -// MarkProcessed marks the nodegroup as processed. -func (p *NoOpBinpackingLimiter) MarkProcessed(context *context.AutoscalingContext, nodegroupId string) { +// FinalizeBinpacking is called to finalize the BinpackingLimiter. +func (p *NoOpBinpackingLimiter) FinalizeBinpacking(context *context.AutoscalingContext, finalOptions []expander.Option) { }