diff --git a/cmd/cluster-lister-gen/generators/lister.go b/cmd/cluster-lister-gen/generators/lister.go index bcd94793..73dc0a85 100644 --- a/cmd/cluster-lister-gen/generators/lister.go +++ b/cmd/cluster-lister-gen/generators/lister.go @@ -221,7 +221,6 @@ func (g *listerGenerator) Imports(_ *generator.Context) (imports []string) { `kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers"`, `"k8s.io/apimachinery/pkg/labels"`, `"k8s.io/client-go/tools/cache"`, - `"k8s.io/client-go/listers"`, ) return } @@ -264,8 +263,6 @@ func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io if g.singleClusterListersPkg == "" { sw.Do(namespaceListerInterface, m) } - - sw.Do(namespaceListerConstructor, m) } sw.Do(scopedLister, m) @@ -289,7 +286,6 @@ type $.type|public$ClusterLister interface { // $.type|private$ClusterLister implements the $.type|public$ClusterLister interface. type $.type|private$ClusterLister struct { kcplisters.ResourceClusterIndexer[*$.type|raw$] - indexer cache.Indexer } var _ $.type|public$ClusterLister = new($.type|private$ClusterLister) @@ -302,19 +298,16 @@ var _ $.type|public$ClusterLister = new($.type|private$ClusterLister) $if .namespaced -$ // - has the kcpcache.ClusterAndNamespaceIndex as an index $end -$ -func New$.type|public$ClusterLister(indexer cache.Indexer) *$.type|private$ClusterLister { +func New$.type|public$ClusterLister(indexer cache.Indexer) $.type|public$ClusterLister { return &$.type|private$ClusterLister{ kcplisters.NewCluster[*$.type|raw$](indexer, $.Resource|raw$("$.type|lowercaseSingular$")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get $.type|publicPlural$. func (l *$.type|private$ClusterLister) Cluster(clusterName logicalcluster.Name) $.listerInterface|raw$ { return &$.type|private$Lister{ - kcplisters.New[*$.type|raw$](l.indexer, clusterName, $.Resource|raw$("$.type|lowercaseSingular$")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } ` @@ -347,8 +340,6 @@ var typeListerStruct = ` // or scope down to a $.namespaceListerInterface|raw$ for one namespace. type $.type|private$Lister struct { kcplisters.ResourceIndexer[*$.type|raw$] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ $.listerInterface|raw$ = new($.type|private$Lister) @@ -357,7 +348,9 @@ var _ $.listerInterface|raw$ = new($.type|private$Lister) var typeListerNamespaceLister = ` // $.type|publicPlural$ returns an object that can list and get $.type|publicPlural$ in one namespace. func (l *$.type|private$Lister) $.type|publicPlural$(namespace string) $.namespaceListerInterface|raw$ { - return new$.type|public$NamespaceLister(l.ResourceIndexer, namespace) + return &$.type|private$NamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } ` @@ -385,41 +378,33 @@ type $.type|private$NamespaceLister struct { var _ $.namespaceListerInterface|raw$ = new($.type|private$NamespaceLister) ` -var namespaceListerConstructor = ` -// new$.type|public$NamespaceLister returns a new $.namespaceListerInterface|raw$. -func new$.type|public$NamespaceLister(indexer kcplisters.ResourceIndexer[*$.type|raw$], namespace string) $.namespaceListerInterface|raw$ { - return &$.type|private$NamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} -` - var scopedLister = ` -// New$.type|public$Lister returns a new $.listerInterface|raw$. +// New$.type|public$Lister returns a new $.type|public$Lister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index $if .namespaced -$ -// - has the cache.NamespaceIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index $end -$ func New$.type|public$Lister(indexer cache.Indexer) $.listerInterface|raw$ { - return &$.type|private$ScopedLister{ - listers.New[*$.type|raw$](indexer, $.Resource|raw$("$.type|lowercaseSingular$")), - indexer, + return &$.type|private$Lister{ + kcplisters.New[*$.type|raw$](indexer, $.Resource|raw$("$.type|lowercaseSingular$")), } } // $.type|private$ScopedLister can list all $.type|publicPlural$ inside a workspace // or scope down to a $.namespaceListerInterface|raw$$if .namespaced$ for one namespace$end$. type $.type|private$ScopedLister struct { - listers.ResourceIndexer[*$.type|raw$] - indexer cache.Indexer + kcplisters.ResourceIndexer[*$.type|raw$] } $if .namespaced -$ // $.type|publicPlural$ returns an object that can list and get $.type|publicPlural$ in one namespace. -func (l *$.type|private$ScopedLister) $.type|publicPlural$(namespace string) $.namespaceListerInterface|raw$ { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *$.type|private$ScopedLister) $.type|publicPlural$(namespace string) $.listerInterface|raw$ { + return &$.type|private$Lister{ + l.ResourceIndexer.WithNamespace(namespace), + } } $end -$ ` diff --git a/examples/go.mod b/examples/go.mod index 80233b5b..3f021f92 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -8,7 +8,7 @@ replace acme.corp/pkg => ./pkg require ( github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250512171935-ebb573a40077 - github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98 + github.com/kcp-dev/client-go v0.0.0-20250706115143-de95389a5f49 github.com/kcp-dev/logicalcluster/v3 v3.0.5 k8s.io/apimachinery v0.32.3 k8s.io/client-go v0.32.3 diff --git a/examples/go.sum b/examples/go.sum index 17515814..2b5b7fae 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -38,8 +38,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250512171935-ebb573a40077 h1:lDi9nZ75ypmRJwDFXUN70Cdu8+HxAjPU1kcnn+l4MvI= github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250512171935-ebb573a40077/go.mod h1:jnMZxVnCuKlkIXc4J1Qtmy1Lyo171CDF/RQhNAo0tvA= -github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98 h1:A1Hc2zVGd9LRSQqlGGqfzin+4skWJVcsNXw2+MjU6z4= -github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98/go.mod h1:79pmlxmvE/hohqD/qvhKaaoXmNDF/uhKnnAO6Vf5hZk= +github.com/kcp-dev/client-go v0.0.0-20250706115143-de95389a5f49 h1:eCqeB/ddeY5Qow7JUto3rzg1PlBnR/kOu0XlK2SMF/w= +github.com/kcp-dev/client-go v0.0.0-20250706115143-de95389a5f49/go.mod h1:79pmlxmvE/hohqD/qvhKaaoXmNDF/uhKnnAO6Vf5hZk= github.com/kcp-dev/logicalcluster/v3 v3.0.5 h1:JbYakokb+5Uinz09oTXomSUJVQsqfxEvU4RyHUYxHOU= github.com/kcp-dev/logicalcluster/v3 v3.0.5/go.mod h1:EWBUBxdr49fUB1cLMO4nOdBWmYifLbP1LfoL20KkXYY= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= diff --git a/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go index 5607173e..9b21e44d 100644 --- a/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" @@ -44,7 +43,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -54,19 +52,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*examplev1.ClusterTestType](l.indexer, clusterName, examplev1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -74,8 +69,6 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*examplev1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ ClusterTestTypeLister = new(clusterTestTypeLister) @@ -94,18 +87,17 @@ type ClusterTestTypeLister interface { // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*examplev1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example/v1/testtype.go b/examples/pkg/kcp/clients/listers/example/v1/testtype.go index 45e7849b..cd844756 100644 --- a/examples/pkg/kcp/clients/listers/example/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" @@ -44,7 +43,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -55,19 +53,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*examplev1.TestType](indexer, examplev1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { return &testTypeLister{ - kcplisters.New[*examplev1.TestType](l.indexer, clusterName, examplev1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,8 +70,6 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTyp // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*examplev1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ TestTypeLister = new(testTypeLister) @@ -94,7 +87,9 @@ type TestTypeLister interface { // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the TestTypeNamespaceLister @@ -117,33 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1.TestType], namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeScopedLister{ - listers.New[*examplev1.TestType](indexer, examplev1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*examplev1.TestType](indexer, examplev1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*examplev1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcp/clients/listers/example/v1/withoutverbtype.go b/examples/pkg/kcp/clients/listers/example/v1/withoutverbtype.go index 363ee99a..a9ff28b5 100644 --- a/examples/pkg/kcp/clients/listers/example/v1/withoutverbtype.go +++ b/examples/pkg/kcp/clients/listers/example/v1/withoutverbtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" @@ -44,7 +43,6 @@ type WithoutVerbTypeClusterLister interface { // withoutVerbTypeClusterLister implements the WithoutVerbTypeClusterLister interface. type withoutVerbTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1.WithoutVerbType] - indexer cache.Indexer } var _ WithoutVerbTypeClusterLister = new(withoutVerbTypeClusterLister) @@ -55,19 +53,16 @@ var _ WithoutVerbTypeClusterLister = new(withoutVerbTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewWithoutVerbTypeClusterLister(indexer cache.Indexer) *withoutVerbTypeClusterLister { +func NewWithoutVerbTypeClusterLister(indexer cache.Indexer) WithoutVerbTypeClusterLister { return &withoutVerbTypeClusterLister{ kcplisters.NewCluster[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get WithoutVerbTypes. func (l *withoutVerbTypeClusterLister) Cluster(clusterName logicalcluster.Name) WithoutVerbTypeLister { return &withoutVerbTypeLister{ - kcplisters.New[*examplev1.WithoutVerbType](l.indexer, clusterName, examplev1.Resource("withoutverbtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,8 +70,6 @@ func (l *withoutVerbTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a WithoutVerbTypeNamespaceLister for one namespace. type withoutVerbTypeLister struct { kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ WithoutVerbTypeLister = new(withoutVerbTypeLister) @@ -94,7 +87,9 @@ type WithoutVerbTypeLister interface { // WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. func (l *withoutVerbTypeLister) WithoutVerbTypes(namespace string) WithoutVerbTypeNamespaceLister { - return newWithoutVerbTypeNamespaceLister(l.ResourceIndexer, namespace) + return &withoutVerbTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // withoutVerbTypeNamespaceLister implements the WithoutVerbTypeNamespaceLister @@ -117,33 +112,27 @@ type WithoutVerbTypeNamespaceLister interface { WithoutVerbTypeNamespaceListerExpansion } -// newWithoutVerbTypeNamespaceLister returns a new WithoutVerbTypeNamespaceLister. -func newWithoutVerbTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1.WithoutVerbType], namespace string) WithoutVerbTypeNamespaceLister { - return &withoutVerbTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - // NewWithoutVerbTypeLister returns a new WithoutVerbTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewWithoutVerbTypeLister(indexer cache.Indexer) WithoutVerbTypeLister { - return &withoutVerbTypeScopedLister{ - listers.New[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), - indexer, + return &withoutVerbTypeLister{ + kcplisters.New[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), } } // withoutVerbTypeScopedLister can list all WithoutVerbTypes inside a workspace // or scope down to a WithoutVerbTypeNamespaceLister for one namespace. type withoutVerbTypeScopedLister struct { - listers.ResourceIndexer[*examplev1.WithoutVerbType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] } // WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. -func (l *withoutVerbTypeScopedLister) WithoutVerbTypes(namespace string) WithoutVerbTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *withoutVerbTypeScopedLister) WithoutVerbTypes(namespace string) WithoutVerbTypeLister { + return &withoutVerbTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go index 7cc18f8f..746615f2 100644 --- a/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" @@ -44,7 +43,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1alpha1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -54,19 +52,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*examplev1alpha1.ClusterTestType](l.indexer, clusterName, examplev1alpha1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -74,8 +69,6 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*examplev1alpha1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ ClusterTestTypeLister = new(clusterTestTypeLister) @@ -94,18 +87,17 @@ type ClusterTestTypeLister interface { // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*examplev1alpha1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1alpha1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go b/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go index c8bd69d4..b72d06ef 100644 --- a/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" @@ -44,7 +43,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1alpha1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -55,19 +53,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { return &testTypeLister{ - kcplisters.New[*examplev1alpha1.TestType](l.indexer, clusterName, examplev1alpha1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,8 +70,6 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTyp // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*examplev1alpha1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ TestTypeLister = new(testTypeLister) @@ -94,7 +87,9 @@ type TestTypeLister interface { // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the TestTypeNamespaceLister @@ -117,33 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1alpha1.TestType], namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeScopedLister{ - listers.New[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*examplev1alpha1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1alpha1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go index f3661e21..6035fb71 100644 --- a/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -44,7 +43,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1beta1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -54,19 +52,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*examplev1beta1.ClusterTestType](l.indexer, clusterName, examplev1beta1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -74,8 +69,6 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*examplev1beta1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ ClusterTestTypeLister = new(clusterTestTypeLister) @@ -94,18 +87,17 @@ type ClusterTestTypeLister interface { // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*examplev1beta1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1beta1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go b/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go index 8a0b34f7..1d00d48e 100644 --- a/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -44,7 +43,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1beta1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -55,19 +53,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { return &testTypeLister{ - kcplisters.New[*examplev1beta1.TestType](l.indexer, clusterName, examplev1beta1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,8 +70,6 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTyp // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*examplev1beta1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ TestTypeLister = new(testTypeLister) @@ -94,7 +87,9 @@ type TestTypeLister interface { // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the TestTypeNamespaceLister @@ -117,33 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1beta1.TestType], namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeScopedLister{ - listers.New[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*examplev1beta1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1beta1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go index 18bd5c0e..aaa87965 100644 --- a/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev2 "acme.corp/pkg/apis/example/v2" @@ -44,7 +43,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev2.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -54,19 +52,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*examplev2.ClusterTestType](l.indexer, clusterName, examplev2.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -74,8 +69,6 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*examplev2.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ ClusterTestTypeLister = new(clusterTestTypeLister) @@ -94,18 +87,17 @@ type ClusterTestTypeLister interface { // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*examplev2.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev2.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example/v2/testtype.go b/examples/pkg/kcp/clients/listers/example/v2/testtype.go index 0090576e..83751d8f 100644 --- a/examples/pkg/kcp/clients/listers/example/v2/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v2/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev2 "acme.corp/pkg/apis/example/v2" @@ -44,7 +43,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev2.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -55,19 +53,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*examplev2.TestType](indexer, examplev2.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { return &testTypeLister{ - kcplisters.New[*examplev2.TestType](l.indexer, clusterName, examplev2.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,8 +70,6 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTyp // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*examplev2.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ TestTypeLister = new(testTypeLister) @@ -94,7 +87,9 @@ type TestTypeLister interface { // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the TestTypeNamespaceLister @@ -117,33 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev2.TestType], namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeScopedLister{ - listers.New[*examplev2.TestType](indexer, examplev2.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*examplev2.TestType](indexer, examplev2.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*examplev2.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev2.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go index fc7cc37e..6d51f65e 100644 --- a/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" example3v1 "acme.corp/pkg/apis/example3/v1" @@ -44,7 +43,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*example3v1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -54,19 +52,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*example3v1.ClusterTestType](l.indexer, clusterName, example3v1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -74,8 +69,6 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*example3v1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ ClusterTestTypeLister = new(clusterTestTypeLister) @@ -94,18 +87,17 @@ type ClusterTestTypeLister interface { // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*example3v1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*example3v1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example3/v1/testtype.go b/examples/pkg/kcp/clients/listers/example3/v1/testtype.go index feea7d6b..a7ed247e 100644 --- a/examples/pkg/kcp/clients/listers/example3/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example3/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" example3v1 "acme.corp/pkg/apis/example3/v1" @@ -44,7 +43,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*example3v1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -55,19 +53,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*example3v1.TestType](indexer, example3v1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { return &testTypeLister{ - kcplisters.New[*example3v1.TestType](l.indexer, clusterName, example3v1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,8 +70,6 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTyp // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*example3v1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ TestTypeLister = new(testTypeLister) @@ -94,7 +87,9 @@ type TestTypeLister interface { // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the TestTypeNamespaceLister @@ -117,33 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*example3v1.TestType], namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeScopedLister{ - listers.New[*example3v1.TestType](indexer, example3v1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*example3v1.TestType](indexer, example3v1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*example3v1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*example3v1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go index 53dc3500..9c33be44 100644 --- a/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" @@ -44,7 +43,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*exampledashedv1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -54,19 +52,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*exampledashedv1.ClusterTestType](l.indexer, clusterName, exampledashedv1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -74,8 +69,6 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*exampledashedv1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ ClusterTestTypeLister = new(clusterTestTypeLister) @@ -94,18 +87,17 @@ type ClusterTestTypeLister interface { // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*exampledashedv1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*exampledashedv1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go index dbf9f9ab..fa30d605 100644 --- a/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" @@ -44,7 +43,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*exampledashedv1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -55,19 +53,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { return &testTypeLister{ - kcplisters.New[*exampledashedv1.TestType](l.indexer, clusterName, exampledashedv1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,8 +70,6 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTyp // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*exampledashedv1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ TestTypeLister = new(testTypeLister) @@ -94,7 +87,9 @@ type TestTypeLister interface { // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the TestTypeNamespaceLister @@ -117,33 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*exampledashedv1.TestType], namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeScopedLister{ - listers.New[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*exampledashedv1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*exampledashedv1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go index ee8028c2..5b4c5430 100644 --- a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" @@ -44,7 +43,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*existinginterfacesv1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -54,19 +52,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*existinginterfacesv1.ClusterTestType](l.indexer, clusterName, existinginterfacesv1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -74,8 +69,6 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*existinginterfacesv1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ ClusterTestTypeLister = new(clusterTestTypeLister) @@ -94,18 +87,17 @@ type ClusterTestTypeLister interface { // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*existinginterfacesv1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*existinginterfacesv1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go index 649b76c0..517637ec 100644 --- a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" @@ -44,7 +43,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*existinginterfacesv1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -55,19 +53,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { return &testTypeLister{ - kcplisters.New[*existinginterfacesv1.TestType](l.indexer, clusterName, existinginterfacesv1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,8 +70,6 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTyp // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ TestTypeLister = new(testTypeLister) @@ -94,7 +87,9 @@ type TestTypeLister interface { // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the TestTypeNamespaceLister @@ -117,33 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*existinginterfacesv1.TestType], namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeScopedLister{ - listers.New[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*existinginterfacesv1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go index 1afb0c96..f97e118a 100644 --- a/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" @@ -44,7 +43,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*secondexamplev1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -54,19 +52,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*secondexamplev1.ClusterTestType](l.indexer, clusterName, secondexamplev1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -74,8 +69,6 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*secondexamplev1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ ClusterTestTypeLister = new(clusterTestTypeLister) @@ -94,18 +87,17 @@ type ClusterTestTypeLister interface { // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*secondexamplev1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*secondexamplev1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go b/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go index 31441353..106772d5 100644 --- a/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" @@ -44,7 +43,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*secondexamplev1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -55,19 +53,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { return &testTypeLister{ - kcplisters.New[*secondexamplev1.TestType](l.indexer, clusterName, secondexamplev1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,8 +70,6 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTyp // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*secondexamplev1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ TestTypeLister = new(testTypeLister) @@ -94,7 +87,9 @@ type TestTypeLister interface { // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the TestTypeNamespaceLister @@ -117,33 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*secondexamplev1.TestType], namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeScopedLister{ - listers.New[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*secondexamplev1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*secondexamplev1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go index 3ef772d5..a6d5c294 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" @@ -45,7 +44,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -55,19 +53,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1.ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*examplev1.ClusterTestType](l.indexer, clusterName, examplev1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,26 +70,23 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a listersexamplev1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*examplev1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexamplev1.ClusterTestTypeLister = new(clusterTestTypeLister) -// NewClusterTestTypeLister returns a new listersexamplev1.ClusterTestTypeLister. +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) listersexamplev1.ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a listersexamplev1.ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*examplev1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go index 627ae4e8..ff63391b 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" @@ -45,7 +44,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -56,19 +54,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*examplev1.TestType](indexer, examplev1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1.TestTypeLister { return &testTypeLister{ - kcplisters.New[*examplev1.TestType](l.indexer, clusterName, examplev1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -76,15 +71,15 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listers // or scope down to a listersexamplev1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*examplev1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexamplev1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) listersexamplev1.TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the listersexamplev1.TestTypeNamespaceLister @@ -95,33 +90,27 @@ type testTypeNamespaceLister struct { var _ listersexamplev1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// newTestTypeNamespaceLister returns a new listersexamplev1.TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1.TestType], namespace string) listersexamplev1.TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - -// NewTestTypeLister returns a new listersexamplev1.TestTypeLister. +// NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) listersexamplev1.TestTypeLister { - return &testTypeScopedLister{ - listers.New[*examplev1.TestType](indexer, examplev1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*examplev1.TestType](indexer, examplev1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a listersexamplev1.TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*examplev1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1.TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1/withoutverbtype.go b/examples/pkg/kcpexisting/clients/listers/example/v1/withoutverbtype.go index afe42f2d..632caae3 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1/withoutverbtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/withoutverbtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" @@ -45,7 +44,6 @@ type WithoutVerbTypeClusterLister interface { // withoutVerbTypeClusterLister implements the WithoutVerbTypeClusterLister interface. type withoutVerbTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1.WithoutVerbType] - indexer cache.Indexer } var _ WithoutVerbTypeClusterLister = new(withoutVerbTypeClusterLister) @@ -56,19 +54,16 @@ var _ WithoutVerbTypeClusterLister = new(withoutVerbTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewWithoutVerbTypeClusterLister(indexer cache.Indexer) *withoutVerbTypeClusterLister { +func NewWithoutVerbTypeClusterLister(indexer cache.Indexer) WithoutVerbTypeClusterLister { return &withoutVerbTypeClusterLister{ kcplisters.NewCluster[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get WithoutVerbTypes. func (l *withoutVerbTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1.WithoutVerbTypeLister { return &withoutVerbTypeLister{ - kcplisters.New[*examplev1.WithoutVerbType](l.indexer, clusterName, examplev1.Resource("withoutverbtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -76,15 +71,15 @@ func (l *withoutVerbTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a listersexamplev1.WithoutVerbTypeNamespaceLister for one namespace. type withoutVerbTypeLister struct { kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexamplev1.WithoutVerbTypeLister = new(withoutVerbTypeLister) // WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. func (l *withoutVerbTypeLister) WithoutVerbTypes(namespace string) listersexamplev1.WithoutVerbTypeNamespaceLister { - return newWithoutVerbTypeNamespaceLister(l.ResourceIndexer, namespace) + return &withoutVerbTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // withoutVerbTypeNamespaceLister implements the listersexamplev1.WithoutVerbTypeNamespaceLister @@ -95,33 +90,27 @@ type withoutVerbTypeNamespaceLister struct { var _ listersexamplev1.WithoutVerbTypeNamespaceLister = new(withoutVerbTypeNamespaceLister) -// newWithoutVerbTypeNamespaceLister returns a new listersexamplev1.WithoutVerbTypeNamespaceLister. -func newWithoutVerbTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1.WithoutVerbType], namespace string) listersexamplev1.WithoutVerbTypeNamespaceLister { - return &withoutVerbTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - -// NewWithoutVerbTypeLister returns a new listersexamplev1.WithoutVerbTypeLister. +// NewWithoutVerbTypeLister returns a new WithoutVerbTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewWithoutVerbTypeLister(indexer cache.Indexer) listersexamplev1.WithoutVerbTypeLister { - return &withoutVerbTypeScopedLister{ - listers.New[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), - indexer, + return &withoutVerbTypeLister{ + kcplisters.New[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), } } // withoutVerbTypeScopedLister can list all WithoutVerbTypes inside a workspace // or scope down to a listersexamplev1.WithoutVerbTypeNamespaceLister for one namespace. type withoutVerbTypeScopedLister struct { - listers.ResourceIndexer[*examplev1.WithoutVerbType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] } // WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. -func (l *withoutVerbTypeScopedLister) WithoutVerbTypes(namespace string) listersexamplev1.WithoutVerbTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *withoutVerbTypeScopedLister) WithoutVerbTypes(namespace string) listersexamplev1.WithoutVerbTypeLister { + return &withoutVerbTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go index 5e31da5f..c81b2666 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" @@ -45,7 +44,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1alpha1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -55,19 +53,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1alpha1.ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*examplev1alpha1.ClusterTestType](l.indexer, clusterName, examplev1alpha1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,26 +70,23 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a listersexamplev1alpha1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*examplev1alpha1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexamplev1alpha1.ClusterTestTypeLister = new(clusterTestTypeLister) -// NewClusterTestTypeLister returns a new listersexamplev1alpha1.ClusterTestTypeLister. +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) listersexamplev1alpha1.ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a listersexamplev1alpha1.ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*examplev1alpha1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1alpha1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go index aa56bac9..43188a81 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" @@ -45,7 +44,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1alpha1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -56,19 +54,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1alpha1.TestTypeLister { return &testTypeLister{ - kcplisters.New[*examplev1alpha1.TestType](l.indexer, clusterName, examplev1alpha1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -76,15 +71,15 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listers // or scope down to a listersexamplev1alpha1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*examplev1alpha1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexamplev1alpha1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) listersexamplev1alpha1.TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the listersexamplev1alpha1.TestTypeNamespaceLister @@ -95,33 +90,27 @@ type testTypeNamespaceLister struct { var _ listersexamplev1alpha1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// newTestTypeNamespaceLister returns a new listersexamplev1alpha1.TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1alpha1.TestType], namespace string) listersexamplev1alpha1.TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - -// NewTestTypeLister returns a new listersexamplev1alpha1.TestTypeLister. +// NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) listersexamplev1alpha1.TestTypeLister { - return &testTypeScopedLister{ - listers.New[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a listersexamplev1alpha1.TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*examplev1alpha1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1alpha1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1alpha1.TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1alpha1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go index 49b5dcf9..cf92944b 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -45,7 +44,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1beta1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -55,19 +53,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1beta1.ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*examplev1beta1.ClusterTestType](l.indexer, clusterName, examplev1beta1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,26 +70,23 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a listersexamplev1beta1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*examplev1beta1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexamplev1beta1.ClusterTestTypeLister = new(clusterTestTypeLister) -// NewClusterTestTypeLister returns a new listersexamplev1beta1.ClusterTestTypeLister. +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) listersexamplev1beta1.ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a listersexamplev1beta1.ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*examplev1beta1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1beta1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype.go b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype.go index f093c065..f6880ec9 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -45,7 +44,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev1beta1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -56,19 +54,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1beta1.TestTypeLister { return &testTypeLister{ - kcplisters.New[*examplev1beta1.TestType](l.indexer, clusterName, examplev1beta1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -76,15 +71,15 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listers // or scope down to a listersexamplev1beta1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*examplev1beta1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexamplev1beta1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) listersexamplev1beta1.TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the listersexamplev1beta1.TestTypeNamespaceLister @@ -95,33 +90,27 @@ type testTypeNamespaceLister struct { var _ listersexamplev1beta1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// newTestTypeNamespaceLister returns a new listersexamplev1beta1.TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1beta1.TestType], namespace string) listersexamplev1beta1.TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - -// NewTestTypeLister returns a new listersexamplev1beta1.TestTypeLister. +// NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) listersexamplev1beta1.TestTypeLister { - return &testTypeScopedLister{ - listers.New[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a listersexamplev1beta1.TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*examplev1beta1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev1beta1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1beta1.TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1beta1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go index ae29ff4f..0b6b9739 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev2 "acme.corp/pkg/apis/example/v2" @@ -45,7 +44,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev2.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -55,19 +53,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev2.ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*examplev2.ClusterTestType](l.indexer, clusterName, examplev2.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,26 +70,23 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a listersexamplev2.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*examplev2.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexamplev2.ClusterTestTypeLister = new(clusterTestTypeLister) -// NewClusterTestTypeLister returns a new listersexamplev2.ClusterTestTypeLister. +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) listersexamplev2.ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a listersexamplev2.ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*examplev2.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev2.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go b/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go index d8837275..7b4f379d 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev2 "acme.corp/pkg/apis/example/v2" @@ -45,7 +44,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*examplev2.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -56,19 +54,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*examplev2.TestType](indexer, examplev2.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev2.TestTypeLister { return &testTypeLister{ - kcplisters.New[*examplev2.TestType](l.indexer, clusterName, examplev2.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -76,15 +71,15 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listers // or scope down to a listersexamplev2.TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*examplev2.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexamplev2.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) listersexamplev2.TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the listersexamplev2.TestTypeNamespaceLister @@ -95,33 +90,27 @@ type testTypeNamespaceLister struct { var _ listersexamplev2.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// newTestTypeNamespaceLister returns a new listersexamplev2.TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev2.TestType], namespace string) listersexamplev2.TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - -// NewTestTypeLister returns a new listersexamplev2.TestTypeLister. +// NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) listersexamplev2.TestTypeLister { - return &testTypeScopedLister{ - listers.New[*examplev2.TestType](indexer, examplev2.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*examplev2.TestType](indexer, examplev2.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a listersexamplev2.TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*examplev2.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*examplev2.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev2.TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev2.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go index a0abc34e..2e959ae3 100644 --- a/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" example3v1 "acme.corp/pkg/apis/example3/v1" @@ -45,7 +44,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*example3v1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -55,19 +53,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexample3v1.ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*example3v1.ClusterTestType](l.indexer, clusterName, example3v1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,26 +70,23 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a listersexample3v1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*example3v1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexample3v1.ClusterTestTypeLister = new(clusterTestTypeLister) -// NewClusterTestTypeLister returns a new listersexample3v1.ClusterTestTypeLister. +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) listersexample3v1.ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a listersexample3v1.ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*example3v1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*example3v1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go index efe7f81a..bc231922 100644 --- a/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" example3v1 "acme.corp/pkg/apis/example3/v1" @@ -45,7 +44,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*example3v1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -56,19 +54,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*example3v1.TestType](indexer, example3v1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexample3v1.TestTypeLister { return &testTypeLister{ - kcplisters.New[*example3v1.TestType](l.indexer, clusterName, example3v1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -76,15 +71,15 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listers // or scope down to a listersexample3v1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*example3v1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexample3v1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) listersexample3v1.TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the listersexample3v1.TestTypeNamespaceLister @@ -95,33 +90,27 @@ type testTypeNamespaceLister struct { var _ listersexample3v1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// newTestTypeNamespaceLister returns a new listersexample3v1.TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*example3v1.TestType], namespace string) listersexample3v1.TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - -// NewTestTypeLister returns a new listersexample3v1.TestTypeLister. +// NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) listersexample3v1.TestTypeLister { - return &testTypeScopedLister{ - listers.New[*example3v1.TestType](indexer, example3v1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*example3v1.TestType](indexer, example3v1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a listersexample3v1.TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*example3v1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*example3v1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) listersexample3v1.TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) listersexample3v1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go index d046ed95..57a1ca2c 100644 --- a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" @@ -45,7 +44,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*exampledashedv1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -55,19 +53,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexampledashedv1.ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*exampledashedv1.ClusterTestType](l.indexer, clusterName, exampledashedv1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,26 +70,23 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a listersexampledashedv1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*exampledashedv1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexampledashedv1.ClusterTestTypeLister = new(clusterTestTypeLister) -// NewClusterTestTypeLister returns a new listersexampledashedv1.ClusterTestTypeLister. +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) listersexampledashedv1.ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a listersexampledashedv1.ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*exampledashedv1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*exampledashedv1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go index ce12b9eb..31fa3e4e 100644 --- a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" @@ -45,7 +44,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*exampledashedv1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -56,19 +54,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexampledashedv1.TestTypeLister { return &testTypeLister{ - kcplisters.New[*exampledashedv1.TestType](l.indexer, clusterName, exampledashedv1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -76,15 +71,15 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listers // or scope down to a listersexampledashedv1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*exampledashedv1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexampledashedv1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) listersexampledashedv1.TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the listersexampledashedv1.TestTypeNamespaceLister @@ -95,33 +90,27 @@ type testTypeNamespaceLister struct { var _ listersexampledashedv1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// newTestTypeNamespaceLister returns a new listersexampledashedv1.TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*exampledashedv1.TestType], namespace string) listersexampledashedv1.TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - -// NewTestTypeLister returns a new listersexampledashedv1.TestTypeLister. +// NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) listersexampledashedv1.TestTypeLister { - return &testTypeScopedLister{ - listers.New[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a listersexampledashedv1.TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*exampledashedv1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*exampledashedv1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) listersexampledashedv1.TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) listersexampledashedv1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go index 41ed5725..78de56a8 100644 --- a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" @@ -45,7 +44,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*existinginterfacesv1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -55,19 +53,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexistinginterfacesv1.ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*existinginterfacesv1.ClusterTestType](l.indexer, clusterName, existinginterfacesv1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,26 +70,23 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a listersexistinginterfacesv1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*existinginterfacesv1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexistinginterfacesv1.ClusterTestTypeLister = new(clusterTestTypeLister) -// NewClusterTestTypeLister returns a new listersexistinginterfacesv1.ClusterTestTypeLister. +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) listersexistinginterfacesv1.ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a listersexistinginterfacesv1.ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*existinginterfacesv1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*existinginterfacesv1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go index 08a3f515..39ba7666 100644 --- a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" @@ -45,7 +44,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*existinginterfacesv1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -56,19 +54,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexistinginterfacesv1.TestTypeLister { return &testTypeLister{ - kcplisters.New[*existinginterfacesv1.TestType](l.indexer, clusterName, existinginterfacesv1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -76,15 +71,15 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listers // or scope down to a listersexistinginterfacesv1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listersexistinginterfacesv1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) listersexistinginterfacesv1.TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the listersexistinginterfacesv1.TestTypeNamespaceLister @@ -95,33 +90,27 @@ type testTypeNamespaceLister struct { var _ listersexistinginterfacesv1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// newTestTypeNamespaceLister returns a new listersexistinginterfacesv1.TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*existinginterfacesv1.TestType], namespace string) listersexistinginterfacesv1.TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - -// NewTestTypeLister returns a new listersexistinginterfacesv1.TestTypeLister. +// NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) listersexistinginterfacesv1.TestTypeLister { - return &testTypeScopedLister{ - listers.New[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a listersexistinginterfacesv1.TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*existinginterfacesv1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) listersexistinginterfacesv1.TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) listersexistinginterfacesv1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } diff --git a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go index a6c02aa7..6f2c315b 100644 --- a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" @@ -45,7 +44,6 @@ type ClusterTestTypeClusterLister interface { // clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*secondexamplev1.ClusterTestType] - indexer cache.Indexer } var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) @@ -55,19 +53,16 @@ var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { return &clusterTestTypeClusterLister{ kcplisters.NewCluster[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listerssecondexamplev1.ClusterTestTypeLister { return &clusterTestTypeLister{ - kcplisters.New[*secondexamplev1.ClusterTestType](l.indexer, clusterName, secondexamplev1.Resource("clustertesttype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -75,26 +70,23 @@ func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) // or scope down to a listerssecondexamplev1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { kcplisters.ResourceIndexer[*secondexamplev1.ClusterTestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listerssecondexamplev1.ClusterTestTypeLister = new(clusterTestTypeLister) -// NewClusterTestTypeLister returns a new listerssecondexamplev1.ClusterTestTypeLister. +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index func NewClusterTestTypeLister(indexer cache.Indexer) listerssecondexamplev1.ClusterTestTypeLister { - return &clusterTestTypeScopedLister{ - listers.New[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), - indexer, + return &clusterTestTypeLister{ + kcplisters.New[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), } } // clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace // or scope down to a listerssecondexamplev1.ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - listers.ResourceIndexer[*secondexamplev1.ClusterTestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*secondexamplev1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go index 4947cd4e..07236299 100644 --- a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go @@ -23,7 +23,6 @@ import ( kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" @@ -45,7 +44,6 @@ type TestTypeClusterLister interface { // testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { kcplisters.ResourceClusterIndexer[*secondexamplev1.TestType] - indexer cache.Indexer } var _ TestTypeClusterLister = new(testTypeClusterLister) @@ -56,19 +54,16 @@ var _ TestTypeClusterLister = new(testTypeClusterLister) // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { return &testTypeClusterLister{ kcplisters.NewCluster[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), - indexer, } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listerssecondexamplev1.TestTypeLister { return &testTypeLister{ - kcplisters.New[*secondexamplev1.TestType](l.indexer, clusterName, secondexamplev1.Resource("testtype")), - l.indexer, - clusterName, + l.ResourceClusterIndexer.WithCluster(clusterName), } } @@ -76,15 +71,15 @@ func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listers // or scope down to a listerssecondexamplev1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { kcplisters.ResourceIndexer[*secondexamplev1.TestType] - indexer cache.Indexer - clusterName logicalcluster.Name } var _ listerssecondexamplev1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. func (l *testTypeLister) TestTypes(namespace string) listerssecondexamplev1.TestTypeNamespaceLister { - return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } // testTypeNamespaceLister implements the listerssecondexamplev1.TestTypeNamespaceLister @@ -95,33 +90,27 @@ type testTypeNamespaceLister struct { var _ listerssecondexamplev1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// newTestTypeNamespaceLister returns a new listerssecondexamplev1.TestTypeNamespaceLister. -func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*secondexamplev1.TestType], namespace string) listerssecondexamplev1.TestTypeNamespaceLister { - return &testTypeNamespaceLister{ - kcplisters.NewNamespaced(indexer, namespace), - } -} - -// NewTestTypeLister returns a new listerssecondexamplev1.TestTypeLister. +// NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeLister(indexer cache.Indexer) listerssecondexamplev1.TestTypeLister { - return &testTypeScopedLister{ - listers.New[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), - indexer, + return &testTypeLister{ + kcplisters.New[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), } } // testTypeScopedLister can list all TestTypes inside a workspace // or scope down to a listerssecondexamplev1.TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - listers.ResourceIndexer[*secondexamplev1.TestType] - indexer cache.Indexer + kcplisters.ResourceIndexer[*secondexamplev1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (l *testTypeScopedLister) TestTypes(namespace string) listerssecondexamplev1.TestTypeNamespaceLister { - return listers.NewNamespaced(l.ResourceIndexer, namespace) +func (l *testTypeScopedLister) TestTypes(namespace string) listerssecondexamplev1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } }