Skip to content

Commit 678b79a

Browse files
committed
Add WithCluster and WithNamespace
Signed-off-by: Nelo-T. Wallus <[email protected]>
1 parent 5457a0f commit 678b79a

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

third_party/k8s.io/client-go/listers/generic_helpers.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ func (l ResourceClusterIndexer[T]) List(selector labels.Selector) (ret []T, err
4949
return ret, err
5050
}
5151

52+
// WithCluster returns a ResourceIndexer with the specified cluster.
53+
func (l ResourceClusterIndexer[T]) WithCluster(cluster logicalcluster.Name) ResourceIndexer[T] {
54+
ret := New[T](l.indexer, l.resource)
55+
ret.cluster = cluster
56+
return ret
57+
}
58+
5259
// ResourceIndexer wraps an indexer, resource, and optional namespace for a given type.
5360
// This is intended for use by listers (generated by lister-gen) only.
5461
type ResourceIndexer[T runtime.Object] struct {
@@ -60,12 +67,35 @@ type ResourceIndexer[T runtime.Object] struct {
6067

6168
// New returns a new instance of a lister (resource indexer) wrapping the given indexer and resource for the specified type.
6269
// This is intended for use by listers (generated by lister-gen) only.
63-
func New[T runtime.Object](indexer cache.Indexer, cluster logicalcluster.Name, resource schema.GroupResource) ResourceIndexer[T] {
64-
return ResourceIndexer[T]{indexer: indexer, cluster: cluster, resource: resource}
70+
func New[T runtime.Object](indexer cache.Indexer, resource schema.GroupResource) ResourceIndexer[T] {
71+
return ResourceIndexer[T]{indexer: indexer, resource: resource}
72+
}
73+
74+
// WithCluster returns a new copy of the ResourceIndexer with the
75+
// specified cluster.
76+
func (l ResourceIndexer[T]) WithCluster(cluster logicalcluster.Name) ResourceIndexer[T] {
77+
return ResourceIndexer[T]{
78+
indexer: l.indexer,
79+
cluster: cluster,
80+
resource: l.resource,
81+
namespace: l.namespace,
82+
}
83+
}
84+
85+
// WithNamespace returns a new copy of the ResourceIndexer with the
86+
// specified namespace.
87+
func (l ResourceIndexer[T]) WithNamespace(namespace string) ResourceIndexer[T] {
88+
return ResourceIndexer[T]{
89+
indexer: l.indexer,
90+
cluster: l.cluster,
91+
resource: l.resource,
92+
namespace: namespace,
93+
}
6594
}
6695

6796
// NewNamespaced returns a new instance of a namespaced lister (resource indexer) wrapping the given parent and namespace for the specified type.
6897
// This is intended for use by listers (generated by lister-gen) only.
98+
// Deprecated: Use ResourceIndexer.WithNamespace instead.
6999
func NewNamespaced[T runtime.Object](parent ResourceIndexer[T], namespace string) ResourceIndexer[T] {
70100
return ResourceIndexer[T]{indexer: parent.indexer, resource: parent.resource, namespace: namespace}
71101
}

0 commit comments

Comments
 (0)