From 2908174517cc1ded8a3dc283d2e8e34d7ad9be7a Mon Sep 17 00:00:00 2001 From: andrewsykim Date: Fri, 19 Oct 2018 17:00:43 -0400 Subject: [PATCH] pass in stopCh to cloud provider Initialize method for custom controllers --- cmd/cloud-controller-manager/app/controllermanager.go | 2 +- cmd/kube-controller-manager/app/controllermanager.go | 2 +- pkg/cloudprovider/providers/aws/aws.go | 2 +- pkg/cloudprovider/providers/azure/azure.go | 2 +- pkg/cloudprovider/providers/cloudstack/cloudstack.go | 3 ++- pkg/cloudprovider/providers/fake/fake.go | 3 ++- pkg/cloudprovider/providers/gce/gce.go | 2 +- pkg/cloudprovider/providers/openstack/openstack.go | 3 ++- pkg/cloudprovider/providers/ovirt/ovirt.go | 3 ++- pkg/cloudprovider/providers/photon/photon.go | 3 ++- pkg/cloudprovider/providers/vsphere/vsphere.go | 2 +- staging/src/k8s.io/cloud-provider/cloud.go | 5 +++-- 12 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cmd/cloud-controller-manager/app/controllermanager.go b/cmd/cloud-controller-manager/app/controllermanager.go index d01600646f..4fa93a65b2 100644 --- a/cmd/cloud-controller-manager/app/controllermanager.go +++ b/cmd/cloud-controller-manager/app/controllermanager.go @@ -202,7 +202,7 @@ func startControllers(c *cloudcontrollerconfig.CompletedConfig, stop <-chan stru } if cloud != nil { // Initialize the cloud provider with a reference to the clientBuilder - cloud.Initialize(c.ClientBuilder) + cloud.Initialize(c.ClientBuilder, stop) } // Start the CloudNodeController nodeController := cloudcontrollers.NewCloudNodeController( diff --git a/cmd/kube-controller-manager/app/controllermanager.go b/cmd/kube-controller-manager/app/controllermanager.go index 1dab046122..b417071c5f 100644 --- a/cmd/kube-controller-manager/app/controllermanager.go +++ b/cmd/kube-controller-manager/app/controllermanager.go @@ -468,7 +468,7 @@ func StartControllers(ctx ControllerContext, startSATokenController InitFunc, co // Initialize the cloud provider with a reference to the clientBuilder only after token controller // has started in case the cloud provider uses the client builder. if ctx.Cloud != nil { - ctx.Cloud.Initialize(ctx.ClientBuilder) + ctx.Cloud.Initialize(ctx.ClientBuilder, ctx.Stop) } for controllerName, initFn := range controllers { diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index 02f7c783b2..dbad7cdd75 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -1159,7 +1159,7 @@ func newAWSCloud(cfg CloudConfig, awsServices Services) (*Cloud, error) { } // Initialize passes a Kubernetes clientBuilder interface to the cloud provider -func (c *Cloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder) { +func (c *Cloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { c.clientBuilder = clientBuilder c.kubeClient = clientBuilder.ClientOrDie("aws-cloud-provider") c.eventBroadcaster = record.NewBroadcaster() diff --git a/pkg/cloudprovider/providers/azure/azure.go b/pkg/cloudprovider/providers/azure/azure.go index 59115591c2..c80859926e 100644 --- a/pkg/cloudprovider/providers/azure/azure.go +++ b/pkg/cloudprovider/providers/azure/azure.go @@ -390,7 +390,7 @@ func parseConfig(configReader io.Reader) (*Config, error) { } // Initialize passes a Kubernetes clientBuilder interface to the cloud provider -func (az *Cloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder) { +func (az *Cloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { az.kubeClient = clientBuilder.ClientOrDie("azure-cloud-provider") az.eventBroadcaster = record.NewBroadcaster() az.eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: az.kubeClient.CoreV1().Events("")}) diff --git a/pkg/cloudprovider/providers/cloudstack/cloudstack.go b/pkg/cloudprovider/providers/cloudstack/cloudstack.go index 24846525ed..f0a08b77bd 100644 --- a/pkg/cloudprovider/providers/cloudstack/cloudstack.go +++ b/pkg/cloudprovider/providers/cloudstack/cloudstack.go @@ -121,7 +121,8 @@ func newCSCloud(cfg *CSConfig) (*CSCloud, error) { } // Initialize passes a Kubernetes clientBuilder interface to the cloud provider -func (cs *CSCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder) {} +func (cs *CSCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { +} // LoadBalancer returns an implementation of LoadBalancer for CloudStack. func (cs *CSCloud) LoadBalancer() (cloudprovider.LoadBalancer, bool) { diff --git a/pkg/cloudprovider/providers/fake/fake.go b/pkg/cloudprovider/providers/fake/fake.go index 4d125fa0f4..8adf2fed21 100644 --- a/pkg/cloudprovider/providers/fake/fake.go +++ b/pkg/cloudprovider/providers/fake/fake.go @@ -97,7 +97,8 @@ func (f *FakeCloud) ClearCalls() { } // Initialize passes a Kubernetes clientBuilder interface to the cloud provider -func (f *FakeCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder) {} +func (f *FakeCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { +} func (f *FakeCloud) ListClusters(ctx context.Context) ([]string, error) { return f.ClusterList, f.Err diff --git a/pkg/cloudprovider/providers/gce/gce.go b/pkg/cloudprovider/providers/gce/gce.go index aac5468a96..857c266fcf 100644 --- a/pkg/cloudprovider/providers/gce/gce.go +++ b/pkg/cloudprovider/providers/gce/gce.go @@ -610,7 +610,7 @@ func tryConvertToProjectNames(configProject, configNetworkProject string, servic // Initialize takes in a clientBuilder and spawns a goroutine for watching the clusterid configmap. // This must be called before utilizing the funcs of gce.ClusterID -func (gce *GCECloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder) { +func (gce *GCECloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { gce.clientBuilder = clientBuilder gce.client = clientBuilder.ClientOrDie("cloud-provider") diff --git a/pkg/cloudprovider/providers/openstack/openstack.go b/pkg/cloudprovider/providers/openstack/openstack.go index f1cf73146e..fbcee0f42a 100644 --- a/pkg/cloudprovider/providers/openstack/openstack.go +++ b/pkg/cloudprovider/providers/openstack/openstack.go @@ -367,7 +367,8 @@ func newOpenStack(cfg Config) (*OpenStack, error) { } // Initialize passes a Kubernetes clientBuilder interface to the cloud provider -func (os *OpenStack) Initialize(clientBuilder cloudprovider.ControllerClientBuilder) {} +func (os *OpenStack) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { +} // mapNodeNameToServerName maps a k8s NodeName to an OpenStack Server Name // This is a simple string cast. diff --git a/pkg/cloudprovider/providers/ovirt/ovirt.go b/pkg/cloudprovider/providers/ovirt/ovirt.go index ae3fb862dd..9937919ed1 100644 --- a/pkg/cloudprovider/providers/ovirt/ovirt.go +++ b/pkg/cloudprovider/providers/ovirt/ovirt.go @@ -117,7 +117,8 @@ func newOVirtCloud(config io.Reader) (*OVirtCloud, error) { } // Initialize passes a Kubernetes clientBuilder interface to the cloud provider -func (v *OVirtCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder) {} +func (v *OVirtCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { +} func (v *OVirtCloud) Clusters() (cloudprovider.Clusters, bool) { return nil, false diff --git a/pkg/cloudprovider/providers/photon/photon.go b/pkg/cloudprovider/providers/photon/photon.go index 583a00b309..bcf5e31344 100644 --- a/pkg/cloudprovider/providers/photon/photon.go +++ b/pkg/cloudprovider/providers/photon/photon.go @@ -286,7 +286,8 @@ func newPCCloud(cfg PCConfig) (*PCCloud, error) { } // Initialize passes a Kubernetes clientBuilder interface to the cloud provider -func (pc *PCCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder) {} +func (pc *PCCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { +} // Instances returns an implementation of Instances for Photon Controller. func (pc *PCCloud) Instances() (cloudprovider.Instances, bool) { diff --git a/pkg/cloudprovider/providers/vsphere/vsphere.go b/pkg/cloudprovider/providers/vsphere/vsphere.go index 02589b7a03..7e22407ed5 100644 --- a/pkg/cloudprovider/providers/vsphere/vsphere.go +++ b/pkg/cloudprovider/providers/vsphere/vsphere.go @@ -241,7 +241,7 @@ func init() { } // Initialize passes a Kubernetes clientBuilder interface to the cloud provider -func (vs *VSphere) Initialize(clientBuilder cloudprovider.ControllerClientBuilder) { +func (vs *VSphere) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) { } // Initialize Node Informers diff --git a/staging/src/k8s.io/cloud-provider/cloud.go b/staging/src/k8s.io/cloud-provider/cloud.go index 50a30f3106..6db0219520 100644 --- a/staging/src/k8s.io/cloud-provider/cloud.go +++ b/staging/src/k8s.io/cloud-provider/cloud.go @@ -42,8 +42,9 @@ type ControllerClientBuilder interface { // Interface is an abstract, pluggable interface for cloud providers. type Interface interface { // Initialize provides the cloud with a kubernetes client builder and may spawn goroutines - // to perform housekeeping activities within the cloud provider. - Initialize(clientBuilder ControllerClientBuilder) + // to perform housekeeping or run custom controllers specific to the cloud provider. + // Any tasks started here should be cleaned up when the stop channel closes. + Initialize(clientBuilder ControllerClientBuilder, stop <-chan struct{}) // LoadBalancer returns a balancer interface. Also returns true if the interface is supported, false otherwise. LoadBalancer() (LoadBalancer, bool) // Instances returns an instances interface. Also returns true if the interface is supported, false otherwise.