Skip to content

Commit

Permalink
refactor: pass informer instead of lister to cloud provider builder fn
Browse files Browse the repository at this point in the history
Signed-off-by: vadasambar <[email protected]>
  • Loading branch information
vadasambar committed Nov 24, 2023
1 parent 5cb9aec commit 2b27633
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cluster-autoscaler/cloudprovider/builder/builder_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/volcengine"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/vultr"
"k8s.io/autoscaler/cluster-autoscaler/config"
listersv1 "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/informers"
)

// AvailableCloudProviders supported by the cloud provider builder.
Expand Down Expand Up @@ -93,7 +93,7 @@ const DefaultCloudProvider = cloudprovider.GceProviderName
func buildCloudProvider(opts config.AutoscalingOptions,
do cloudprovider.NodeGroupDiscoveryOptions,
rl *cloudprovider.ResourceLimiter,
allNodesLister listersv1.NodeLister) cloudprovider.CloudProvider {
informerFactory informers.SharedInformerFactory) cloudprovider.CloudProvider {
switch opts.CloudProviderName {
case cloudprovider.BizflyCloudProviderName:
return bizflycloud.BuildBizflyCloud(opts, do, rl)
Expand Down Expand Up @@ -136,7 +136,7 @@ func buildCloudProvider(opts config.AutoscalingOptions,
case cloudprovider.KamateraProviderName:
return kamatera.BuildKamatera(opts, do, rl)
case cloudprovider.KwokProviderName:
return kwok.BuildKwok(opts, do, rl, allNodesLister)
return kwok.BuildKwok(opts, do, rl, informerFactory)
case cloudprovider.LinodeProviderName:
return linode.BuildLinode(opts, do, rl)
case cloudprovider.OracleCloudProviderName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/config"
"k8s.io/autoscaler/cluster-autoscaler/context"
listersv1 "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/informers"

klog "k8s.io/klog/v2"
)

// NewCloudProvider builds a cloud provider from provided parameters.
func NewCloudProvider(opts config.AutoscalingOptions, allNodesLister listersv1.NodeLister) cloudprovider.CloudProvider {
func NewCloudProvider(opts config.AutoscalingOptions, informerFactory informers.SharedInformerFactory) cloudprovider.CloudProvider {
klog.V(1).Infof("Building %s cloud provider.", opts.CloudProviderName)

do := cloudprovider.NodeGroupDiscoveryOptions{
Expand All @@ -43,7 +43,7 @@ func NewCloudProvider(opts config.AutoscalingOptions, allNodesLister listersv1.N
return nil
}

provider := buildCloudProvider(opts, do, rl, allNodesLister)
provider := buildCloudProvider(opts, do, rl, informerFactory)
if provider != nil {
return provider
}
Expand Down
6 changes: 3 additions & 3 deletions cluster-autoscaler/cloudprovider/kwok/kwok_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/utils/errors"
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
kube_util "k8s.io/autoscaler/cluster-autoscaler/utils/kubernetes"
"k8s.io/client-go/informers"
kubeclient "k8s.io/client-go/kubernetes"
listersv1 "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
klog "k8s.io/klog/v2"
Expand Down Expand Up @@ -168,7 +168,7 @@ func (kwok *KwokCloudProvider) Cleanup() error {
func BuildKwok(opts config.AutoscalingOptions,
do cloudprovider.NodeGroupDiscoveryOptions,
rl *cloudprovider.ResourceLimiter,
allNodesLister listersv1.NodeLister) cloudprovider.CloudProvider {
informerFactory informers.SharedInformerFactory) cloudprovider.CloudProvider {

var restConfig *rest.Config
var err error
Expand Down Expand Up @@ -202,7 +202,7 @@ func BuildKwok(opts config.AutoscalingOptions,
discoveryOpts: &do,
resourceLimiter: rl,
ngNodeListerFn: kube_util.NewNodeLister,
allNodesLister: allNodesLister})
allNodesLister: informerFactory.Core().V1().Nodes().Lister()})

if err != nil {
klog.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion cluster-autoscaler/core/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func initializeDefaultOptions(opts *AutoscalerOptions, informerFactory informers
opts.RemainingPdbTracker = pdb.NewBasicRemainingPdbTracker()
}
if opts.CloudProvider == nil {
opts.CloudProvider = cloudBuilder.NewCloudProvider(opts.AutoscalingOptions, informerFactory.Core().V1().Nodes().Lister())
opts.CloudProvider = cloudBuilder.NewCloudProvider(opts.AutoscalingOptions, informerFactory)
}
if opts.ExpanderStrategy == nil {
expanderFactory := factory.NewFactory()
Expand Down

0 comments on commit 2b27633

Please sign in to comment.