Skip to content

Commit f462434

Browse files
committed
feat: add Lister() to expose informer cache bia GenericLister
Signed-off-by: yeonsoo <[email protected]>
1 parent c893cb2 commit f462434

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/informer/informer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/sirupsen/logrus"
2929
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/runtime"
31+
"k8s.io/apimachinery/pkg/runtime/schema"
3132
"k8s.io/apimachinery/pkg/watch"
3233
"k8s.io/client-go/tools/cache"
3334
)
@@ -57,6 +58,9 @@ type Informer[T runtime.Object] struct {
5758

5859
resType reflect.Type
5960

61+
// groupResource is the group and resource of the watched objects.
62+
groupResource schema.GroupResource
63+
6064
// logger is this informer's logger.
6165
logger *logrus.Entry
6266

@@ -109,6 +113,13 @@ func NewInformer[T runtime.Object](ctx context.Context, opts ...InformerOption[T
109113
i := &Informer[T]{}
110114
var r T
111115
i.resType = reflect.TypeOf(r)
116+
117+
// groupResource is the group and resource of the watched objects.
118+
i.groupResource = schema.GroupResource{
119+
Group: "argoproj.io",
120+
Resource: "applications",
121+
}
122+
112123
i.logger = logrus.NewEntry(logrus.StandardLogger()).WithFields(logrus.Fields{
113124
"type": i.resType,
114125
"module": "Informer",
@@ -287,3 +298,8 @@ func (i *Informer[T]) WaitForSync(ctx context.Context) error {
287298
}
288299
return nil
289300
}
301+
302+
// Lister returns a GenericLister that can be used to list and get cached resources.
303+
func (i *Informer[T]) Lister() cache.GenericLister {
304+
return cache.NewGenericLister(i.informer.GetIndexer(), i.groupResource)
305+
}

0 commit comments

Comments
 (0)