fix goroutine leak on legacy-cloud-provider gce

Change-Id: Ice7f66683785d60ce9d09201d557a0438743ec72
This commit is contained in:
Antonio Ojea 2024-02-16 15:57:12 +00:00
parent 50b4cfc414
commit 08f8be9903
2 changed files with 11 additions and 6 deletions

View File

@ -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)
}

View File

@ -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.