From bc76a18d83b6db24fb0b9d195b91aa9c017f6cce Mon Sep 17 00:00:00 2001 From: Shintaro Murakami Date: Wed, 8 May 2019 15:11:10 +0900 Subject: [PATCH] Clean up code in proxy/config --- pkg/proxy/config/BUILD | 1 - pkg/proxy/config/config.go | 22 ++-------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/pkg/proxy/config/BUILD b/pkg/proxy/config/BUILD index b68b6f036e..ccf8a0e4d1 100644 --- a/pkg/proxy/config/BUILD +++ b/pkg/proxy/config/BUILD @@ -18,7 +18,6 @@ go_library( "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library", "//staging/src/k8s.io/client-go/informers/core/v1:go_default_library", - "//staging/src/k8s.io/client-go/listers/core/v1:go_default_library", "//staging/src/k8s.io/client-go/tools/cache:go_default_library", "//vendor/k8s.io/klog:go_default_library", ], diff --git a/pkg/proxy/config/config.go b/pkg/proxy/config/config.go index 2b22e643b9..039eabacbd 100644 --- a/pkg/proxy/config/config.go +++ b/pkg/proxy/config/config.go @@ -23,7 +23,6 @@ import ( "k8s.io/api/core/v1" utilruntime "k8s.io/apimachinery/pkg/util/runtime" coreinformers "k8s.io/client-go/informers/core/v1" - listers "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/klog" "k8s.io/kubernetes/pkg/controller" @@ -64,9 +63,7 @@ type EndpointsHandler interface { } // EndpointsConfig tracks a set of endpoints configurations. -// It accepts "set", "add" and "remove" operations of endpoints via channels, and invokes registered handlers on change. type EndpointsConfig struct { - lister listers.EndpointsLister listerSynced cache.InformerSynced eventHandlers []EndpointsHandler } @@ -74,7 +71,6 @@ type EndpointsConfig struct { // NewEndpointsConfig creates a new EndpointsConfig. func NewEndpointsConfig(endpointsInformer coreinformers.EndpointsInformer, resyncPeriod time.Duration) *EndpointsConfig { result := &EndpointsConfig{ - lister: endpointsInformer.Lister(), listerSynced: endpointsInformer.Informer().HasSynced, } @@ -95,12 +91,9 @@ func (c *EndpointsConfig) RegisterEventHandler(handler EndpointsHandler) { c.eventHandlers = append(c.eventHandlers, handler) } -// Run starts the goroutine responsible for calling registered handlers. +// Run waits for cache synced and invokes handlers after syncing. func (c *EndpointsConfig) Run(stopCh <-chan struct{}) { - defer utilruntime.HandleCrash() - klog.Info("Starting endpoints config controller") - defer klog.Info("Shutting down endpoints config controller") if !controller.WaitForCacheSync("endpoints config", stopCh, c.listerSynced) { return @@ -110,8 +103,6 @@ func (c *EndpointsConfig) Run(stopCh <-chan struct{}) { klog.V(3).Infof("Calling handler.OnEndpointsSynced()") c.eventHandlers[i].OnEndpointsSynced() } - - <-stopCh } func (c *EndpointsConfig) handleAddEndpoints(obj interface{}) { @@ -163,9 +154,7 @@ func (c *EndpointsConfig) handleDeleteEndpoints(obj interface{}) { } // ServiceConfig tracks a set of service configurations. -// It accepts "set", "add" and "remove" operations of services via channels, and invokes registered handlers on change. type ServiceConfig struct { - lister listers.ServiceLister listerSynced cache.InformerSynced eventHandlers []ServiceHandler } @@ -173,7 +162,6 @@ type ServiceConfig struct { // NewServiceConfig creates a new ServiceConfig. func NewServiceConfig(serviceInformer coreinformers.ServiceInformer, resyncPeriod time.Duration) *ServiceConfig { result := &ServiceConfig{ - lister: serviceInformer.Lister(), listerSynced: serviceInformer.Informer().HasSynced, } @@ -194,13 +182,9 @@ func (c *ServiceConfig) RegisterEventHandler(handler ServiceHandler) { c.eventHandlers = append(c.eventHandlers, handler) } -// Run starts the goroutine responsible for calling -// registered handlers. +// Run waits for cache synced and invokes handlers after syncing. func (c *ServiceConfig) Run(stopCh <-chan struct{}) { - defer utilruntime.HandleCrash() - klog.Info("Starting service config controller") - defer klog.Info("Shutting down service config controller") if !controller.WaitForCacheSync("service config", stopCh, c.listerSynced) { return @@ -210,8 +194,6 @@ func (c *ServiceConfig) Run(stopCh <-chan struct{}) { klog.V(3).Info("Calling handler.OnServiceSynced()") c.eventHandlers[i].OnServiceSynced() } - - <-stopCh } func (c *ServiceConfig) handleAddService(obj interface{}) {