@@ -22,6 +22,7 @@ import (
2222 "time"
2323
2424 "github.com/go-logr/logr"
25+ "github.com/google/go-cmp/cmp"
2526 "k8s.io/apimachinery/pkg/runtime"
2627 "k8s.io/apimachinery/pkg/watch"
2728
@@ -65,6 +66,7 @@ func NewPoller[T any, PT Object[T], L client.ObjectList](
6566 equality : eq ,
6667 logger : logger ,
6768 refreshCh : make (chan struct {}, bufSize ),
69+ typeName : fmt .Sprintf ("%T" , new (T )),
6870 }
6971}
7072
@@ -86,6 +88,8 @@ type poller[T any, PT Object[T], L client.ObjectList] struct {
8688
8789 lister Lister [T , PT , L ]
8890 equality Equality [T , PT ]
91+
92+ typeName string
8993}
9094
9195func (p * poller [T , PT , L ]) renew (ctx context.Context ) context.Context {
@@ -99,6 +103,7 @@ func (p *poller[T, PT, L]) renew(ctx context.Context) context.Context {
99103}
100104
101105func (p * poller [T , PT , L ]) Sync (ctx context.Context ) (runtime.Object , error ) {
106+ p .logger .Info ("poller sync" , "cluster" , p .name , "kind" , p .typeName )
102107 p .lock .Lock ()
103108 defer p .lock .Unlock ()
104109
@@ -154,11 +159,13 @@ func (p *poller[T, PT, L]) Run(ctx context.Context, ch chan<- watch.Event) {
154159 for {
155160 select {
156161 case <- nctx .Done ():
157- p .logger .Info ("poller is stopped" , "cluster" , p .name , "type " , new ( T ) )
162+ p .logger .Info ("poller is stopped" , "cluster" , p .name , "kind " , p . typeName )
158163 return
159164 case <- p .refreshCh :
165+ p .logger .Info ("poller refresh" , "cluster" , p .name , "kind" , p .typeName )
160166 p .poll (ctx )
161167 case <- timer .C :
168+ p .logger .Info ("poller poll" , "cluster" , p .name , "kind" , p .typeName )
162169 p .poll (ctx )
163170 }
164171 timer .Reset (p .interval )
@@ -241,17 +248,31 @@ func (p *poller[T, PT, L]) generateEvents(ctx context.Context, prevState, curSta
241248func (p * poller [T , PT , L ]) sendEvent (ctx context.Context , e * watch.Event ) {
242249 select {
243250 case p .resultCh <- * e :
244- p .logger .Info ("poller send event" , "type" , e .Type , "object" , e .Object )
251+ p .logger .Info ("poller sent event" , "type" , e .Type , "object" , e .Object , "kind" , p . typeName )
245252 case <- ctx .Done ():
246253 }
247254}
248255
249- type deepEquality [T any , PT Object [T ]] struct {}
256+ type deepEquality [T any , PT Object [T ]] struct {
257+ logger logr.Logger
258+ }
250259
251- func (* deepEquality [T , PT ]) Equal (preObj , curObj PT ) bool {
252- return reflect .DeepEqual (preObj , curObj )
260+ func (e * deepEquality [T , PT ]) Equal (preObj , curObj PT ) bool {
261+ if reflect .DeepEqual (preObj , curObj ) {
262+ return true
263+ }
264+
265+ e .logger .Info ("poll obj is changed" ,
266+ "namespace" , curObj .GetNamespace (),
267+ "name" , curObj .GetName (),
268+ "diff" , cmp .Diff (preObj , curObj ),
269+ )
270+
271+ return false
253272}
254273
255- func NewDeepEquality [T any , PT Object [T ]]() Equality [T , PT ] {
256- return & deepEquality [T , PT ]{}
274+ func NewDeepEquality [T any , PT Object [T ]](logger logr.Logger ) Equality [T , PT ] {
275+ return & deepEquality [T , PT ]{
276+ logger : logger ,
277+ }
257278}
0 commit comments