diff --git a/kubernetes/eventhandler.go b/kubernetes/eventhandler.go index e35c3b015..0d866d067 100644 --- a/kubernetes/eventhandler.go +++ b/kubernetes/eventhandler.go @@ -138,22 +138,22 @@ type podUpdaterStore interface { List() []interface{} } -// OldObjectWatcher is the interface that an object needs to implement to be -// able to use Oldobject cache event function from watcher. -type oldObjectWatcher interface { - Oldobject() runtime.Object +// CachedObjectWatcher is the interface that an object needs to implement to be +// able to use CachedObject cache event function from watcher. +type cachedObjectWatcher interface { + CachedObject() runtime.Object } // namespacePodUpdater notifies updates on pods when their namespaces are updated. type namespacePodUpdater struct { handler podUpdaterHandlerFunc store podUpdaterStore - namespaceWatcher oldObjectWatcher + namespaceWatcher cachedObjectWatcher locker sync.Locker } // NewNamespacePodUpdater creates a namespacePodUpdater -func NewNamespacePodUpdater(handler podUpdaterHandlerFunc, store podUpdaterStore, namespaceWatcher oldObjectWatcher, locker sync.Locker) *namespacePodUpdater { +func NewNamespacePodUpdater(handler podUpdaterHandlerFunc, store podUpdaterStore, namespaceWatcher cachedObjectWatcher, locker sync.Locker) *namespacePodUpdater { return &namespacePodUpdater{ handler: handler, store: store, @@ -177,7 +177,7 @@ func (n *namespacePodUpdater) OnUpdate(obj interface{}) { n.locker.Lock() defer n.locker.Unlock() } - cachedObject := n.namespaceWatcher.Oldobject() + cachedObject := n.namespaceWatcher.CachedObject() cachedNamespace, ok := cachedObject.(*Namespace) if ok && ns.Name == cachedNamespace.Name { @@ -208,12 +208,12 @@ func (*namespacePodUpdater) OnDelete(interface{}) {} type nodePodUpdater struct { handler podUpdaterHandlerFunc store podUpdaterStore - nodeWatcher oldObjectWatcher + nodeWatcher cachedObjectWatcher locker sync.Locker } // NewNodePodUpdater creates a nodePodUpdater -func NewNodePodUpdater(handler podUpdaterHandlerFunc, store podUpdaterStore, nodeWatcher oldObjectWatcher, locker sync.Locker) *nodePodUpdater { +func NewNodePodUpdater(handler podUpdaterHandlerFunc, store podUpdaterStore, nodeWatcher cachedObjectWatcher, locker sync.Locker) *nodePodUpdater { return &nodePodUpdater{ handler: handler, store: store, @@ -237,7 +237,7 @@ func (n *nodePodUpdater) OnUpdate(obj interface{}) { n.locker.Lock() defer n.locker.Unlock() } - cachedObject := n.nodeWatcher.Oldobject() + cachedObject := n.nodeWatcher.CachedObject() cachedNode, ok := cachedObject.(*Node) if ok && node.Name == cachedNode.Name { diff --git a/kubernetes/watcher.go b/kubernetes/watcher.go index e5f7d7fc3..ac16f4ad6 100644 --- a/kubernetes/watcher.go +++ b/kubernetes/watcher.go @@ -60,8 +60,8 @@ type Watcher interface { // Client returns the kubernetes client object used by the watcher Client() kubernetes.Interface - // Oldobject returns the old object before change during the last updated event - Oldobject() runtime.Object + // CachedObject returns the old object before change during the last updated event + CachedObject() runtime.Object } // WatchOptions controls watch behaviors @@ -86,15 +86,15 @@ type item struct { } type watcher struct { - client kubernetes.Interface - informer cache.SharedInformer - store cache.Store - queue workqueue.Interface - ctx context.Context - stop context.CancelFunc - handler ResourceEventHandler - logger *logp.Logger - oldobject runtime.Object + client kubernetes.Interface + informer cache.SharedInformer + store cache.Store + queue workqueue.Interface + ctx context.Context + stop context.CancelFunc + handler ResourceEventHandler + logger *logp.Logger + cachedObject runtime.Object } // NewWatcher initializes the watcher client to provide a events handler for @@ -110,7 +110,7 @@ func NewWatcher(client kubernetes.Interface, resource Resource, opts WatchOption func NewNamedWatcher(name string, client kubernetes.Interface, resource Resource, opts WatchOptions, indexers cache.Indexers) (Watcher, error) { var store cache.Store var queue workqueue.Interface - var oldobject runtime.Object + var cachedObject runtime.Object informer, _, err := NewInformer(client, resource, opts, indexers) if err != nil { return nil, err @@ -131,15 +131,15 @@ func NewNamedWatcher(name string, client kubernetes.Interface, resource Resource ctx, cancel := context.WithCancel(context.TODO()) w := &watcher{ - client: client, - informer: informer, - store: store, - queue: queue, - ctx: ctx, - oldobject: oldobject, - stop: cancel, - logger: logp.NewLogger("kubernetes"), - handler: NoOpEventHandlerFuncs{}, + client: client, + informer: informer, + store: store, + queue: queue, + ctx: ctx, + cachedObject: cachedObject, + stop: cancel, + logger: logp.NewLogger("kubernetes"), + handler: NoOpEventHandlerFuncs{}, } w.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ @@ -186,8 +186,8 @@ func (w *watcher) Client() kubernetes.Interface { } // Oldbject returns the old object in cache during the last updated event -func (w *watcher) Oldobject() runtime.Object { - return w.oldobject +func (w *watcher) CachedObject() runtime.Object { + return w.cachedObject } // Start watching pods @@ -234,7 +234,7 @@ func (w *watcher) cacheObject(o interface{}) { if old, ok := o.(runtime.Object); !ok { utilruntime.HandleError(fmt.Errorf("expected object in cache got %#v", o)) } else { - w.oldobject = old + w.cachedObject = old } }