Skip to content

Commit 013bcb5

Browse files
committed
refactor core.AutoscalerOptions in a new package
This change helps to prevent circular dependencies between the core and builder packages as we start to pass the AutoscalerOptions to the cloud provider builder functions.
1 parent 94637a2 commit 013bcb5

File tree

2 files changed

+63
-33
lines changed

2 files changed

+63
-33
lines changed

cluster-autoscaler/core/autoscaler.go

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,24 @@ import (
2020
"strings"
2121
"time"
2222

23-
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
2423
cloudBuilder "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/builder"
25-
"k8s.io/autoscaler/cluster-autoscaler/config"
2624
"k8s.io/autoscaler/cluster-autoscaler/context"
25+
"k8s.io/autoscaler/cluster-autoscaler/core/options"
2726
"k8s.io/autoscaler/cluster-autoscaler/core/scaledown/pdb"
28-
"k8s.io/autoscaler/cluster-autoscaler/core/scaleup"
29-
"k8s.io/autoscaler/cluster-autoscaler/debuggingsnapshot"
3027
"k8s.io/autoscaler/cluster-autoscaler/estimator"
31-
"k8s.io/autoscaler/cluster-autoscaler/expander"
3228
"k8s.io/autoscaler/cluster-autoscaler/expander/factory"
3329
"k8s.io/autoscaler/cluster-autoscaler/observers/loopstart"
3430
ca_processors "k8s.io/autoscaler/cluster-autoscaler/processors"
35-
"k8s.io/autoscaler/cluster-autoscaler/simulator/clustersnapshot"
3631
"k8s.io/autoscaler/cluster-autoscaler/simulator/clustersnapshot/predicate"
3732
"k8s.io/autoscaler/cluster-autoscaler/simulator/clustersnapshot/store"
3833
"k8s.io/autoscaler/cluster-autoscaler/simulator/drainability/rules"
3934
draprovider "k8s.io/autoscaler/cluster-autoscaler/simulator/dynamicresources/provider"
4035
"k8s.io/autoscaler/cluster-autoscaler/simulator/framework"
41-
"k8s.io/autoscaler/cluster-autoscaler/simulator/options"
4236
"k8s.io/autoscaler/cluster-autoscaler/utils/backoff"
4337
"k8s.io/autoscaler/cluster-autoscaler/utils/errors"
4438
"k8s.io/client-go/informers"
45-
kube_client "k8s.io/client-go/kubernetes"
4639
)
4740

48-
// AutoscalerOptions is the whole set of options for configuring an autoscaler
49-
type AutoscalerOptions struct {
50-
config.AutoscalingOptions
51-
KubeClient kube_client.Interface
52-
InformerFactory informers.SharedInformerFactory
53-
AutoscalingKubeClients *context.AutoscalingKubeClients
54-
CloudProvider cloudprovider.CloudProvider
55-
FrameworkHandle *framework.Handle
56-
ClusterSnapshot clustersnapshot.ClusterSnapshot
57-
ExpanderStrategy expander.Strategy
58-
EstimatorBuilder estimator.EstimatorBuilder
59-
Processors *ca_processors.AutoscalingProcessors
60-
LoopStartNotifier *loopstart.ObserversList
61-
Backoff backoff.Backoff
62-
DebuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter
63-
RemainingPdbTracker pdb.RemainingPdbTracker
64-
ScaleUpOrchestrator scaleup.Orchestrator
65-
DeleteOptions options.NodeDeleteOptions
66-
DrainabilityRules rules.Rules
67-
DraProvider *draprovider.Provider
68-
}
69-
7041
// Autoscaler is the main component of CA which scales up/down node groups according to its configuration
7142
// The configuration can be injected at the creation of an autoscaler
7243
type Autoscaler interface {
@@ -83,7 +54,7 @@ type Autoscaler interface {
8354
}
8455

8556
// NewAutoscaler creates an autoscaler of an appropriate type according to the parameters
86-
func NewAutoscaler(opts AutoscalerOptions, informerFactory informers.SharedInformerFactory) (Autoscaler, errors.AutoscalerError) {
57+
func NewAutoscaler(opts options.AutoscalerOptions, informerFactory informers.SharedInformerFactory) (Autoscaler, errors.AutoscalerError) {
8758
err := initializeDefaultOptions(&opts, informerFactory)
8859
if err != nil {
8960
return nil, errors.ToAutoscalerError(errors.InternalError, err)
@@ -109,7 +80,7 @@ func NewAutoscaler(opts AutoscalerOptions, informerFactory informers.SharedInfor
10980
}
11081

11182
// Initialize default options if not provided.
112-
func initializeDefaultOptions(opts *AutoscalerOptions, informerFactory informers.SharedInformerFactory) error {
83+
func initializeDefaultOptions(opts *options.AutoscalerOptions, informerFactory informers.SharedInformerFactory) error {
11384
if opts.Processors == nil {
11485
opts.Processors = ca_processors.DefaultProcessors(opts.AutoscalingOptions)
11586
}
@@ -133,7 +104,7 @@ func initializeDefaultOptions(opts *AutoscalerOptions, informerFactory informers
133104
opts.RemainingPdbTracker = pdb.NewBasicRemainingPdbTracker()
134105
}
135106
if opts.CloudProvider == nil {
136-
opts.CloudProvider = cloudBuilder.NewCloudProvider(opts.AutoscalingOptions, informerFactory)
107+
opts.CloudProvider = cloudBuilder.NewCloudProvider(opts, informerFactory)
137108
}
138109
if opts.ExpanderStrategy == nil {
139110
expanderFactory := factory.NewFactory()
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package options
17+
18+
import (
19+
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
20+
"k8s.io/autoscaler/cluster-autoscaler/config"
21+
"k8s.io/autoscaler/cluster-autoscaler/context"
22+
"k8s.io/autoscaler/cluster-autoscaler/core/scaledown/pdb"
23+
"k8s.io/autoscaler/cluster-autoscaler/core/scaleup"
24+
"k8s.io/autoscaler/cluster-autoscaler/debuggingsnapshot"
25+
"k8s.io/autoscaler/cluster-autoscaler/estimator"
26+
"k8s.io/autoscaler/cluster-autoscaler/expander"
27+
"k8s.io/autoscaler/cluster-autoscaler/observers/loopstart"
28+
ca_processors "k8s.io/autoscaler/cluster-autoscaler/processors"
29+
"k8s.io/autoscaler/cluster-autoscaler/simulator/clustersnapshot"
30+
"k8s.io/autoscaler/cluster-autoscaler/simulator/drainability/rules"
31+
draprovider "k8s.io/autoscaler/cluster-autoscaler/simulator/dynamicresources/provider"
32+
"k8s.io/autoscaler/cluster-autoscaler/simulator/framework"
33+
"k8s.io/autoscaler/cluster-autoscaler/simulator/options"
34+
"k8s.io/autoscaler/cluster-autoscaler/utils/backoff"
35+
"k8s.io/client-go/informers"
36+
kube_client "k8s.io/client-go/kubernetes"
37+
)
38+
39+
// AutoscalerOptions is the whole set of options for configuring an autoscaler
40+
type AutoscalerOptions struct {
41+
config.AutoscalingOptions
42+
KubeClient kube_client.Interface
43+
InformerFactory informers.SharedInformerFactory
44+
AutoscalingKubeClients *context.AutoscalingKubeClients
45+
CloudProvider cloudprovider.CloudProvider
46+
FrameworkHandle *framework.Handle
47+
ClusterSnapshot clustersnapshot.ClusterSnapshot
48+
ExpanderStrategy expander.Strategy
49+
EstimatorBuilder estimator.EstimatorBuilder
50+
Processors *ca_processors.AutoscalingProcessors
51+
LoopStartNotifier *loopstart.ObserversList
52+
Backoff backoff.Backoff
53+
DebuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter
54+
RemainingPdbTracker pdb.RemainingPdbTracker
55+
ScaleUpOrchestrator scaleup.Orchestrator
56+
DeleteOptions options.NodeDeleteOptions
57+
DrainabilityRules rules.Rules
58+
DraProvider *draprovider.Provider
59+
}

0 commit comments

Comments
 (0)