From 2ea105df63ab0e1d0ec4d94652e32990fc06f66a Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 30 Dec 2022 19:53:33 -0500 Subject: [PATCH] Drop unused EndpointsHandler / EndpointsConfig from pkg/proxy/config (Also NoopEndpointSliceHandler since it's no longer possible for a proxy implementation to no-op EndpointSlice handling.) --- pkg/proxy/config/config.go | 129 ------------------------------------- 1 file changed, 129 deletions(-) diff --git a/pkg/proxy/config/config.go b/pkg/proxy/config/config.go index 065b499c84b..090062c46ba 100644 --- a/pkg/proxy/config/config.go +++ b/pkg/proxy/config/config.go @@ -46,25 +46,6 @@ type ServiceHandler interface { OnServiceSynced() } -// EndpointsHandler is an abstract interface of objects which receive -// notifications about endpoints object changes. This is not a required -// sub-interface of proxy.Provider, and proxy implementations should -// not implement it unless they can't handle EndpointSlices. -type EndpointsHandler interface { - // OnEndpointsAdd is called whenever creation of new endpoints object - // is observed. - OnEndpointsAdd(endpoints *v1.Endpoints) - // OnEndpointsUpdate is called whenever modification of an existing - // endpoints object is observed. - OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) - // OnEndpointsDelete is called whenever deletion of an existing endpoints - // object is observed. - OnEndpointsDelete(endpoints *v1.Endpoints) - // OnEndpointsSynced is called once all the initial event handlers were - // called and the state is fully propagated to local cache. - OnEndpointsSynced() -} - // EndpointSliceHandler is an abstract interface of objects which receive // notifications about endpoint slice object changes. type EndpointSliceHandler interface { @@ -82,116 +63,6 @@ type EndpointSliceHandler interface { OnEndpointSlicesSynced() } -// NoopEndpointSliceHandler is a noop handler for proxiers that have not yet -// implemented a full EndpointSliceHandler. -type NoopEndpointSliceHandler struct{} - -// OnEndpointSliceAdd is a noop handler for EndpointSlice creates. -func (*NoopEndpointSliceHandler) OnEndpointSliceAdd(endpointSlice *discovery.EndpointSlice) {} - -// OnEndpointSliceUpdate is a noop handler for EndpointSlice updates. -func (*NoopEndpointSliceHandler) OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice *discovery.EndpointSlice) { -} - -// OnEndpointSliceDelete is a noop handler for EndpointSlice deletes. -func (*NoopEndpointSliceHandler) OnEndpointSliceDelete(endpointSlice *discovery.EndpointSlice) {} - -// OnEndpointSlicesSynced is a noop handler for EndpointSlice syncs. -func (*NoopEndpointSliceHandler) OnEndpointSlicesSynced() {} - -var _ EndpointSliceHandler = &NoopEndpointSliceHandler{} - -// EndpointsConfig tracks a set of endpoints configurations. -type EndpointsConfig struct { - listerSynced cache.InformerSynced - eventHandlers []EndpointsHandler -} - -// NewEndpointsConfig creates a new EndpointsConfig. -func NewEndpointsConfig(endpointsInformer coreinformers.EndpointsInformer, resyncPeriod time.Duration) *EndpointsConfig { - result := &EndpointsConfig{ - listerSynced: endpointsInformer.Informer().HasSynced, - } - - endpointsInformer.Informer().AddEventHandlerWithResyncPeriod( - cache.ResourceEventHandlerFuncs{ - AddFunc: result.handleAddEndpoints, - UpdateFunc: result.handleUpdateEndpoints, - DeleteFunc: result.handleDeleteEndpoints, - }, - resyncPeriod, - ) - - return result -} - -// RegisterEventHandler registers a handler which is called on every endpoints change. -func (c *EndpointsConfig) RegisterEventHandler(handler EndpointsHandler) { - c.eventHandlers = append(c.eventHandlers, handler) -} - -// Run waits for cache synced and invokes handlers after syncing. -func (c *EndpointsConfig) Run(stopCh <-chan struct{}) { - klog.InfoS("Starting endpoints config controller") - - if !cache.WaitForNamedCacheSync("endpoints config", stopCh, c.listerSynced) { - return - } - - for i := range c.eventHandlers { - klog.V(3).InfoS("Calling handler.OnEndpointsSynced()") - c.eventHandlers[i].OnEndpointsSynced() - } -} - -func (c *EndpointsConfig) handleAddEndpoints(obj interface{}) { - endpoints, ok := obj.(*v1.Endpoints) - if !ok { - utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj)) - return - } - for i := range c.eventHandlers { - klog.V(4).InfoS("Calling handler.OnEndpointsAdd") - c.eventHandlers[i].OnEndpointsAdd(endpoints) - } -} - -func (c *EndpointsConfig) handleUpdateEndpoints(oldObj, newObj interface{}) { - oldEndpoints, ok := oldObj.(*v1.Endpoints) - if !ok { - utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", oldObj)) - return - } - endpoints, ok := newObj.(*v1.Endpoints) - if !ok { - utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj)) - return - } - for i := range c.eventHandlers { - klog.V(4).InfoS("Calling handler.OnEndpointsUpdate") - c.eventHandlers[i].OnEndpointsUpdate(oldEndpoints, endpoints) - } -} - -func (c *EndpointsConfig) handleDeleteEndpoints(obj interface{}) { - endpoints, ok := obj.(*v1.Endpoints) - if !ok { - tombstone, ok := obj.(cache.DeletedFinalStateUnknown) - if !ok { - utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj)) - return - } - if endpoints, ok = tombstone.Obj.(*v1.Endpoints); !ok { - utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj)) - return - } - } - for i := range c.eventHandlers { - klog.V(4).InfoS("Calling handler.OnEndpointsDelete") - c.eventHandlers[i].OnEndpointsDelete(endpoints) - } -} - // EndpointSliceConfig tracks a set of endpoints configurations. type EndpointSliceConfig struct { listerSynced cache.InformerSynced