Skip to content

Commit 3ee977a

Browse files
committed
move unnecessary init process after startWorkers (#3124)
1 parent 0857593 commit 3ee977a

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

pkg/controller/controller.go

+34-26
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ func NewController(config *Configuration) *Controller {
633633
// is closed, at which point it will shutdown the workqueue and wait for
634634
// workers to finish processing their current work items.
635635
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
636638
defer c.shutdown()
637639
klog.Info("Starting OVN controller")
638640

@@ -691,49 +693,25 @@ func (c *Controller) Run(ctx context.Context) {
691693
util.LogFatalAndExit(err, "failed to initialize ipam")
692694
}
693695

694-
if err := c.initNodeChassis(); err != nil {
695-
util.LogFatalAndExit(err, "failed to initialize node chassis")
696-
}
697-
698696
if err := c.initNodeRoutes(); err != nil {
699697
util.LogFatalAndExit(err, "failed to initialize node routes")
700698
}
701699

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()
712700
if err := c.initSyncCrdSubnets(); err != nil {
713701
util.LogFatalAndExit(err, "failed to sync crd subnets")
714702
}
715703
if err := c.initSyncCrdVlans(); err != nil {
716704
util.LogFatalAndExit(err, "failed to sync crd vlans")
717705
}
718706

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-
731707
if err := c.addNodeGwStaticRoute(); err != nil {
732708
util.LogFatalAndExit(err, "failed to add static route for node gateway")
733709
}
734710

735711
// start workers to do all the network operations
736712
c.startWorkers(ctx)
713+
714+
c.initResourceOnce()
737715
<-ctx.Done()
738716
klog.Info("Shutting down workers")
739717
}
@@ -1035,3 +1013,33 @@ func (c *Controller) startWorkers(ctx context.Context) {
10351013
go wait.Until(c.runDelPodAnnotatedIptablesFipWorker, time.Second, ctx.Done())
10361014
}
10371015
}
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+
}

pkg/controller/gc.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (c *Controller) gc() error {
2626
c.gcChassis,
2727
c.gcLogicalSwitch,
2828
c.gcCustomLogicalRouter,
29-
c.gcLogicalSwitchPort,
29+
// The lsp gc is processed periodically by markAndCleanLSP, will not gc lsp when init
3030
c.gcLoadBalancer,
3131
c.gcPortGroup,
3232
c.gcStaticRoute,
@@ -277,14 +277,6 @@ func (c *Controller) gcVip() error {
277277
return nil
278278
}
279279

280-
func (c *Controller) gcLogicalSwitchPort() error {
281-
klog.Info("start to gc logical switch port")
282-
if err := c.markAndCleanLSP(); err != nil {
283-
return err
284-
}
285-
return c.markAndCleanLSP()
286-
}
287-
288280
func (c *Controller) markAndCleanLSP() error {
289281
klog.V(4).Infof("start to gc logical switch ports")
290282
pods, err := c.podsLister.List(labels.Everything())

pkg/controller/init.go

+1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ func (c *Controller) InitIPAM() error {
422422
}
423423
}
424424
}
425+
425426
nodes, err := c.nodesLister.List(labels.Everything())
426427
if err != nil {
427428
klog.Errorf("failed to list nodes: %v", err)

0 commit comments

Comments
 (0)