<p>I am looking at following 2 examples, in the first <a href="https://github.com/aaronlevy/kube-controller-demo/blob/master/reboot-controller/main.go#L155" rel="nofollow noreferrer">example</a> A lister is used to retrieve the item.</p>

<p>In the <a href="https://github.com/trstringer/k8s-controller-core-resource/blob/master/controller.go#L102" rel="nofollow noreferrer">second example</a> , an index is used.</p>

<p>I am wondering which is the preferred way and way to retrieve an element from the local cache.</p>

Always_Beginner
<p>The examples you showed above, they both use <strong>indexer</strong>, if you go deeper you will see it.</p>

<p>For <a href="https://github.com/aaronlevy/kube-controller-demo/blob/master/reboot-controller/main.go#L155" rel="nofollow noreferrer">First example</a> (see <a href="https://github.com/aaronlevy/kube-controller-demo/blob/7a6784a5953931c5b95896ad218760db893d2d29/vendor/k8s.io/client-go/listers/core/v1/node.go#L56" rel="nofollow noreferrer">here</a>)</p>

<pre><code>// Get retrieves the Node from the index for a given name.
func (s *nodeLister) Get(name string) (*v1.Node, error) {
    obj, exists, err := s.indexer.GetByKey(name)
    if err != nil {
        return nil, err
    }
    if !exists {
        return nil, errors.NewNotFound(v1.Resource("node"), name)
    }
    return obj.(*v1.Node), nil
}
</code></pre>

<p>For <a href="https://github.com/trstringer/k8s-controller-core-resource/blob/master/controller.go#L102" rel="nofollow noreferrer">second example</a></p>

<pre><code>item, exists, err := c.informer.GetIndexer().GetByKey(keyRaw)
</code></pre>
