@@ -305,42 +305,63 @@ type multiNamespaceInformer struct {
305305 namespaceToInformer map [string ]Informer
306306}
307307
308+ type handlerRegistration struct {
309+ handles map [string ]toolscache.ResourceEventHandlerRegistration
310+ }
311+
312+ type syncer interface {
313+ HasSynced () bool
314+ }
315+
316+ // HasSynced asserts that the handler has been called for the full initial state of the informer.
317+ // This uses syncer to be compatible between client-go 1.27+ and older versions when the interface changed.
318+ func (h handlerRegistration ) HasSynced () bool {
319+ for _ , reg := range h .handles {
320+ if s , ok := reg .(syncer ); ok {
321+ if ! s .HasSynced () {
322+ return false
323+ }
324+ }
325+ }
326+ return true
327+ }
328+
308329var _ Informer = & multiNamespaceInformer {}
309330
310331// AddEventHandler adds the handler to each namespaced informer.
311332func (i * multiNamespaceInformer ) AddEventHandler (handler toolscache.ResourceEventHandler ) (toolscache.ResourceEventHandlerRegistration , error ) {
312- handles := make (map [string ]toolscache.ResourceEventHandlerRegistration , len (i .namespaceToInformer ))
333+ handles := handlerRegistration { handles : make (map [string ]toolscache.ResourceEventHandlerRegistration , len (i .namespaceToInformer ))}
313334 for ns , informer := range i .namespaceToInformer {
314335 registration , err := informer .AddEventHandler (handler )
315336 if err != nil {
316337 return nil , err
317338 }
318- handles [ns ] = registration
339+ handles . handles [ns ] = registration
319340 }
320341 return handles , nil
321342}
322343
323344// AddEventHandlerWithResyncPeriod adds the handler with a resync period to each namespaced informer.
324345func (i * multiNamespaceInformer ) AddEventHandlerWithResyncPeriod (handler toolscache.ResourceEventHandler , resyncPeriod time.Duration ) (toolscache.ResourceEventHandlerRegistration , error ) {
325- handles := make (map [string ]toolscache.ResourceEventHandlerRegistration , len (i .namespaceToInformer ))
346+ handles := handlerRegistration { handles : make (map [string ]toolscache.ResourceEventHandlerRegistration , len (i .namespaceToInformer ))}
326347 for ns , informer := range i .namespaceToInformer {
327348 registration , err := informer .AddEventHandlerWithResyncPeriod (handler , resyncPeriod )
328349 if err != nil {
329350 return nil , err
330351 }
331- handles [ns ] = registration
352+ handles . handles [ns ] = registration
332353 }
333354 return handles , nil
334355}
335356
336357// RemoveEventHandler removes a formerly added event handler given by its registration handle.
337358func (i * multiNamespaceInformer ) RemoveEventHandler (h toolscache.ResourceEventHandlerRegistration ) error {
338- handles , ok := h .(map [ string ]toolscache. ResourceEventHandlerRegistration )
359+ handles , ok := h .(handlerRegistration )
339360 if ! ok {
340361 return fmt .Errorf ("it is not the registration returned by multiNamespaceInformer" )
341362 }
342363 for ns , informer := range i .namespaceToInformer {
343- registration , ok := handles [ns ]
364+ registration , ok := handles . handles [ns ]
344365 if ! ok {
345366 continue
346367 }
0 commit comments