diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go index fe5f24a76fe..739827fda8a 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go @@ -43,7 +43,7 @@ import ( "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/informers" @@ -655,6 +655,11 @@ func (g *Cloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, g.eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: g.client.CoreV1().Events("")}) g.eventRecorder = g.eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "g-cloudprovider"}) + go func() { + defer g.eventBroadcaster.Shutdown() + <-stop + }() + go g.watchClusterID(stop) go g.metricsCollector.Run(stop) } diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_metrics.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_metrics.go index 3cdbd9c0c92..8512a839a8b 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_metrics.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_metrics.go @@ -111,12 +111,12 @@ func newLoadBalancerMetrics() loadbalancerMetricsCollector { func (lm *LoadBalancerMetrics) Run(stopCh <-chan struct{}) { klog.V(3).Infof("Loadbalancer Metrics initialized. Metrics will be exported at an interval of %v", metricsInterval) // Compute and export metrics periodically. - go func() { - // Wait for service states to be populated in the cache before computing metrics. - time.Sleep(metricsInterval) + select { + case <-stopCh: + return + case <-time.After(metricsInterval): // Wait for service states to be populated in the cache before computing metrics. wait.Until(lm.export, metricsInterval, stopCh) - }() - <-stopCh + } } // SetL4ILBService implements loadbalancerMetricsCollector.