@@ -527,153 +527,113 @@ func NewOVNKubeControllerWatchFactory(ovnClientset *util.OVNKubeControllerClient
527527
528528// Start starts the factory and begins processing events
529529func (wf * WatchFactory ) Start () error {
530+ start := time .Now ()
530531 klog .Info ("Starting watch factory" )
531532 wf .iFactory .Start (wf .stopChan )
532- for oType , synced := range waitForCacheSyncWithTimeout (wf .iFactory , wf .stopChan ) {
533- if ! synced {
534- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
535- }
533+ if err := waitForCacheSyncWithTimeout (wf .iFactory , wf .stopChan ); err != nil {
534+ return err
536535 }
537536 if config .OVNKubernetesFeature .EnableAdminNetworkPolicy && wf .anpFactory != nil {
538537 wf .anpFactory .Start (wf .stopChan )
539- for oType , synced := range waitForCacheSyncWithTimeout (wf .anpFactory , wf .stopChan ) {
540- if ! synced {
541- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
542- }
538+ if err := waitForCacheSyncWithTimeout (wf .anpFactory , wf .stopChan ); err != nil {
539+ return err
543540 }
544541 }
545542 if config .OVNKubernetesFeature .EnableEgressIP && wf .eipFactory != nil {
546543 wf .eipFactory .Start (wf .stopChan )
547- for oType , synced := range waitForCacheSyncWithTimeout (wf .eipFactory , wf .stopChan ) {
548- if ! synced {
549- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
550- }
544+ if err := waitForCacheSyncWithTimeout (wf .eipFactory , wf .stopChan ); err != nil {
545+ return err
551546 }
552547 }
553548 if config .OVNKubernetesFeature .EnableEgressFirewall && wf .efFactory != nil {
554549 wf .efFactory .Start (wf .stopChan )
555- for oType , synced := range waitForCacheSyncWithTimeout (wf .efFactory , wf .stopChan ) {
556- if ! synced {
557- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
558- }
550+ if err := waitForCacheSyncWithTimeout (wf .efFactory , wf .stopChan ); err != nil {
551+ return err
559552 }
560553
561554 if config .OVNKubernetesFeature .EnableDNSNameResolver && wf .dnsFactory != nil {
562555 wf .dnsFactory .Start (wf .stopChan )
563- for oType , synced := range waitForCacheSyncWithTimeout (wf .dnsFactory , wf .stopChan ) {
564- if ! synced {
565- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
566- }
556+ if err := waitForCacheSyncWithTimeout (wf .dnsFactory , wf .stopChan ); err != nil {
557+ return err
567558 }
568559 }
569560 }
570561 if util .PlatformTypeIsEgressIPCloudProvider () && wf .cpipcFactory != nil {
571562 wf .cpipcFactory .Start (wf .stopChan )
572- for oType , synced := range waitForCacheSyncWithTimeout (wf .cpipcFactory , wf .stopChan ) {
573- if ! synced {
574- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
575- }
563+ if err := waitForCacheSyncWithTimeout (wf .cpipcFactory , wf .stopChan ); err != nil {
564+ return err
576565 }
577566 }
578567 if config .OVNKubernetesFeature .EnableEgressQoS && wf .egressQoSFactory != nil {
579568 wf .egressQoSFactory .Start (wf .stopChan )
580- for oType , synced := range waitForCacheSyncWithTimeout (wf .egressQoSFactory , wf .stopChan ) {
581- if ! synced {
582- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
583- }
569+ if err := waitForCacheSyncWithTimeout (wf .egressQoSFactory , wf .stopChan ); err != nil {
570+ return err
584571 }
585572 }
586573
587574 if util .IsMultiNetworkPoliciesSupportEnabled () && wf .mnpFactory != nil {
588575 wf .mnpFactory .Start (wf .stopChan )
589- for oType , synced := range waitForCacheSyncWithTimeout (wf .mnpFactory , wf .stopChan ) {
590- if ! synced {
591- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
592- }
576+ if err := waitForCacheSyncWithTimeout (wf .mnpFactory , wf .stopChan ); err != nil {
577+ return err
593578 }
594579 }
595580
596581 if config .OVNKubernetesFeature .EnableEgressService && wf .egressServiceFactory != nil {
597582 wf .egressServiceFactory .Start (wf .stopChan )
598- for oType , synced := range waitForCacheSyncWithTimeout (wf .egressServiceFactory , wf .stopChan ) {
599- if ! synced {
600- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
601- }
583+ if err := waitForCacheSyncWithTimeout (wf .egressServiceFactory , wf .stopChan ); err != nil {
584+ return err
602585 }
603586 }
604587
605588 if config .OVNKubernetesFeature .EnableMultiExternalGateway && wf .apbRouteFactory != nil {
606589 wf .apbRouteFactory .Start (wf .stopChan )
607- for oType , synced := range waitForCacheSyncWithTimeout (wf .apbRouteFactory , wf .stopChan ) {
608- if ! synced {
609- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
610- }
590+ if err := waitForCacheSyncWithTimeout (wf .apbRouteFactory , wf .stopChan ); err != nil {
591+ return err
611592 }
612593 }
613594
614595 if wf .ipamClaimsFactory != nil {
615596 wf .ipamClaimsFactory .Start (wf .stopChan )
616- for oType , synced := range waitForCacheSyncWithTimeout (wf .ipamClaimsFactory , wf .stopChan ) {
617- if ! synced {
618- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
619- }
597+ if err := waitForCacheSyncWithTimeout (wf .ipamClaimsFactory , wf .stopChan ); err != nil {
598+ return err
620599 }
621600 }
622601
623602 if wf .nadFactory != nil {
624603 wf .nadFactory .Start (wf .stopChan )
625- for oType , synced := range waitForCacheSyncWithTimeout (wf .nadFactory , wf .stopChan ) {
626- if ! synced {
627- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
628- }
604+ if err := waitForCacheSyncWithTimeout (wf .nadFactory , wf .stopChan ); err != nil {
605+ return err
629606 }
630607 }
631608
632609 if config .OVNKubernetesFeature .EnableNetworkQoS && wf .networkQoSFactory != nil {
633610 wf .networkQoSFactory .Start (wf .stopChan )
634- for oType , synced := range waitForCacheSyncWithTimeout (wf .networkQoSFactory , wf .stopChan ) {
635- if ! synced {
636- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
637- }
611+ if err := waitForCacheSyncWithTimeout (wf .networkQoSFactory , wf .stopChan ); err != nil {
612+ return err
638613 }
639614 }
640615
641616 if util .IsNetworkSegmentationSupportEnabled () && wf .udnFactory != nil {
642617 wf .udnFactory .Start (wf .stopChan )
643- for oType , synced := range waitForCacheSyncWithTimeout (wf .udnFactory , wf .stopChan ) {
644- if ! synced {
645- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
646- }
618+ if err := waitForCacheSyncWithTimeout (wf .udnFactory , wf .stopChan ); err != nil {
619+ return err
647620 }
648621 }
649622
650623 if wf .raFactory != nil {
651624 wf .raFactory .Start (wf .stopChan )
652- for oType , synced := range waitForCacheSyncWithTimeout (wf .raFactory , wf .stopChan ) {
653- if ! synced {
654- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
655- }
625+ if err := waitForCacheSyncWithTimeout (wf .raFactory , wf .stopChan ); err != nil {
626+ return err
656627 }
657628 }
658629
659630 if wf .frrFactory != nil {
660631 wf .frrFactory .Start (wf .stopChan )
661- for oType , synced := range waitForCacheSyncWithTimeout (wf .frrFactory , wf .stopChan ) {
662- if ! synced {
663- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
664- }
665- }
666- }
667-
668- if config .OVNKubernetesFeature .EnableNetworkQoS && wf .networkQoSFactory != nil {
669- wf .networkQoSFactory .Start (wf .stopChan )
670- for oType , synced := range waitForCacheSyncWithTimeout (wf .networkQoSFactory , wf .stopChan ) {
671- if ! synced {
672- return fmt .Errorf ("error in syncing cache for %v informer" , oType )
673- }
632+ if err := waitForCacheSyncWithTimeout (wf .frrFactory , wf .stopChan ); err != nil {
633+ return err
674634 }
675635 }
676-
636+ klog . Infof ( "Watch Factory start up complete, took: %s" , time . Since ( start ))
677637 return nil
678638}
679639
@@ -1919,10 +1879,18 @@ type waitForCacheSyncer interface {
19191879 WaitForCacheSync (stopCh <- chan struct {}) map [reflect.Type ]bool
19201880}
19211881
1922- func waitForCacheSyncWithTimeout (factory waitForCacheSyncer , stopCh <- chan struct {}) map [reflect. Type ] bool {
1923- // Give some small time for sync. It helps significantly reduce unit tests time
1882+ func waitForCacheSyncWithTimeout (factory waitForCacheSyncer , stopCh <- chan struct {}) error {
1883+ // Give some small amount of time for sync. It helps significantly reduce unit tests time.
19241884 time .Sleep (5 * time .Millisecond )
1925- return factory .WaitForCacheSync (util .GetChildStopChanWithTimeout (stopCh , types .InformerSyncTimeout ))
1885+
1886+ for oType , synced := range factory .WaitForCacheSync (util .GetChildStopChanWithTimeout (stopCh , types .InformerSyncTimeout )) {
1887+ if ! synced {
1888+ return fmt .Errorf ("error in syncing cache for %v informer" , oType )
1889+ } else {
1890+ klog .Infof ("%s informer cache synced successfully" , oType )
1891+ }
1892+ }
1893+ return nil
19261894}
19271895
19281896// getEndpointSliceSelector returns an EndpointSlice selector function used in watchers.
0 commit comments