@@ -633,6 +633,8 @@ func NewController(config *Configuration) *Controller {
633
633
// is closed, at which point it will shutdown the workqueue and wait for
634
634
// workers to finish processing their current work items.
635
635
func (c * Controller ) Run (ctx context.Context ) {
636
+ // The init process can only be placed here if the init process do really affect the normal process of controller, such as Nodes/Pods/Subnets...
637
+ // Otherwise, the init process should be placed after all workers have already started working
636
638
defer c .shutdown ()
637
639
klog .Info ("Starting OVN controller" )
638
640
@@ -691,49 +693,25 @@ func (c *Controller) Run(ctx context.Context) {
691
693
util .LogFatalAndExit (err , "failed to initialize ipam" )
692
694
}
693
695
694
- if err := c .initNodeChassis (); err != nil {
695
- util .LogFatalAndExit (err , "failed to initialize node chassis" )
696
- }
697
-
698
696
if err := c .initNodeRoutes (); err != nil {
699
697
util .LogFatalAndExit (err , "failed to initialize node routes" )
700
698
}
701
699
702
- if err := c .initDenyAllSecurityGroup (); err != nil {
703
- util .LogFatalAndExit (err , "failed to initialize 'deny_all' security group" )
704
- }
705
-
706
- // remove resources in ovndb that not exist any more in kubernetes resources
707
- if err := c .gc (); err != nil {
708
- util .LogFatalAndExit (err , "failed to run gc" )
709
- }
710
-
711
- c .registerSubnetMetrics ()
712
700
if err := c .initSyncCrdSubnets (); err != nil {
713
701
util .LogFatalAndExit (err , "failed to sync crd subnets" )
714
702
}
715
703
if err := c .initSyncCrdVlans (); err != nil {
716
704
util .LogFatalAndExit (err , "failed to sync crd vlans" )
717
705
}
718
706
719
- if c .config .PodDefaultFipType == util .IptablesFip {
720
- if err := c .initSyncCrdVpcNatGw (); err != nil {
721
- util .LogFatalAndExit (err , "failed to sync crd vpc nat gateways" )
722
- }
723
- }
724
-
725
- if c .config .EnableLb {
726
- if err := c .initVpcDnsConfig (); err != nil {
727
- util .LogFatalAndExit (err , "failed to initialize vpc-dns" )
728
- }
729
- }
730
-
731
707
if err := c .addNodeGwStaticRoute (); err != nil {
732
708
util .LogFatalAndExit (err , "failed to add static route for node gateway" )
733
709
}
734
710
735
711
// start workers to do all the network operations
736
712
c .startWorkers (ctx )
713
+
714
+ c .initResourceOnce ()
737
715
<- ctx .Done ()
738
716
klog .Info ("Shutting down workers" )
739
717
}
@@ -1035,3 +1013,33 @@ func (c *Controller) startWorkers(ctx context.Context) {
1035
1013
go wait .Until (c .runDelPodAnnotatedIptablesFipWorker , time .Second , ctx .Done ())
1036
1014
}
1037
1015
}
1016
+
1017
+ func (c * Controller ) initResourceOnce () {
1018
+ c .registerSubnetMetrics ()
1019
+
1020
+ if err := c .initNodeChassis (); err != nil {
1021
+ util .LogFatalAndExit (err , "failed to initialize node chassis" )
1022
+ }
1023
+
1024
+ if err := c .initDenyAllSecurityGroup (); err != nil {
1025
+ util .LogFatalAndExit (err , "failed to initialize 'deny_all' security group" )
1026
+ }
1027
+
1028
+ if c .config .PodDefaultFipType == util .IptablesFip {
1029
+ if err := c .initSyncCrdVpcNatGw (); err != nil {
1030
+ util .LogFatalAndExit (err , "failed to sync crd vpc nat gateways" )
1031
+ }
1032
+ }
1033
+
1034
+ if c .config .EnableLb {
1035
+ if err := c .initVpcDnsConfig (); err != nil {
1036
+ util .LogFatalAndExit (err , "failed to initialize vpc-dns" )
1037
+ }
1038
+ }
1039
+
1040
+ // remove resources in ovndb that not exist any more in kubernetes resources
1041
+ // process gc at last in case of affecting other init process
1042
+ if err := c .gc (); err != nil {
1043
+ util .LogFatalAndExit (err , "failed to run gc" )
1044
+ }
1045
+ }
0 commit comments