mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
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.)
This commit is contained in:
parent
3da93e1fe4
commit
2ea105df63
@ -46,25 +46,6 @@ type ServiceHandler interface {
|
|||||||
OnServiceSynced()
|
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
|
// EndpointSliceHandler is an abstract interface of objects which receive
|
||||||
// notifications about endpoint slice object changes.
|
// notifications about endpoint slice object changes.
|
||||||
type EndpointSliceHandler interface {
|
type EndpointSliceHandler interface {
|
||||||
@ -82,116 +63,6 @@ type EndpointSliceHandler interface {
|
|||||||
OnEndpointSlicesSynced()
|
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.
|
// EndpointSliceConfig tracks a set of endpoints configurations.
|
||||||
type EndpointSliceConfig struct {
|
type EndpointSliceConfig struct {
|
||||||
listerSynced cache.InformerSynced
|
listerSynced cache.InformerSynced
|
||||||
|
Loading…
Reference in New Issue
Block a user