Regenerate all listers

Signed-off-by: Stephen Kitt <skitt@redhat.com>

Kubernetes-commit: e6f44957cdb961d1ada2ae570d331c6bc0ecc8e2
This commit is contained in:
Stephen Kitt 2023-11-09 17:39:39 +01:00 committed by Kubernetes Publisher
parent 6f2758eb37
commit 6dc1b5cec5

View File

@ -19,8 +19,8 @@ limitations under the License.
package v1alpha1 package v1alpha1
import ( import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/listers"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
v1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" v1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1"
) )
@ -38,25 +38,17 @@ type FooLister interface {
// fooLister implements the FooLister interface. // fooLister implements the FooLister interface.
type fooLister struct { type fooLister struct {
indexer cache.Indexer listers.ResourceIndexer[*v1alpha1.Foo]
} }
// NewFooLister returns a new FooLister. // NewFooLister returns a new FooLister.
func NewFooLister(indexer cache.Indexer) FooLister { func NewFooLister(indexer cache.Indexer) FooLister {
return &fooLister{indexer: indexer} return &fooLister{listers.New[*v1alpha1.Foo](indexer, v1alpha1.Resource("foo"))}
}
// List lists all Foos in the indexer.
func (s *fooLister) List(selector labels.Selector) (ret []*v1alpha1.Foo, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Foo))
})
return ret, err
} }
// Foos returns an object that can list and get Foos. // Foos returns an object that can list and get Foos.
func (s *fooLister) Foos(namespace string) FooNamespaceLister { func (s *fooLister) Foos(namespace string) FooNamespaceLister {
return fooNamespaceLister{indexer: s.indexer, namespace: namespace} return fooNamespaceLister{listers.NewNamespaced[*v1alpha1.Foo](s.ResourceIndexer, namespace)}
} }
// FooNamespaceLister helps list and get Foos. // FooNamespaceLister helps list and get Foos.
@ -74,26 +66,5 @@ type FooNamespaceLister interface {
// fooNamespaceLister implements the FooNamespaceLister // fooNamespaceLister implements the FooNamespaceLister
// interface. // interface.
type fooNamespaceLister struct { type fooNamespaceLister struct {
indexer cache.Indexer listers.ResourceIndexer[*v1alpha1.Foo]
namespace string
}
// List lists all Foos in the indexer for a given namespace.
func (s fooNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Foo, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Foo))
})
return ret, err
}
// Get retrieves the Foo from the indexer for a given namespace and name.
func (s fooNamespaceLister) Get(name string) (*v1alpha1.Foo, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1alpha1.Resource("foo"), name)
}
return obj.(*v1alpha1.Foo), nil
} }