Skip to content

Commit

Permalink
move unnecessary init process after startWorkers (#3124)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Aug 28, 2023
1 parent a8e6813 commit ca061d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
32 changes: 19 additions & 13 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ func NewController(config *Configuration) *Controller {
// is closed, at which point it will shutdown the workqueue and wait for
// workers to finish processing their current work items.
func (c *Controller) Run(stopCh <-chan struct{}) {
// 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...
// Otherwise, the init process should be placed after all workers have already started working
defer c.shutdown()
klog.Info("Starting OVN controller")

Expand Down Expand Up @@ -396,30 +398,20 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
util.LogFatalAndExit(err, "failed to initialize node routes")
}

if err := c.initDenyAllSecurityGroup(); err != nil {
util.LogFatalAndExit(err, "failed to initialize 'deny_all' security group")
}

// remove resources in ovndb that not exist any more in kubernetes resources
if err := c.gc(); err != nil {
util.LogFatalAndExit(err, "failed to run gc")
}

c.registerSubnetMetrics()
if err := c.initSyncCrdSubnets(); err != nil {
util.LogFatalAndExit(err, "failed to sync crd subnets")
}
if err := c.initSyncCrdVlans(); err != nil {
util.LogFatalAndExit(err, "failed to sync crd vlans")
}
// The static route for node gw can be deleted when gc static route, so add it after gc process
dstIp := "0.0.0.0/0,::/0"
if err := c.ovnLegacyClient.AddStaticRoute("", dstIp, c.config.NodeSwitchGateway, c.config.ClusterRouter, util.NormalRouteType, false); err != nil {

if err := c.addNodeGwStaticRoute(); err != nil {
util.LogFatalAndExit(err, "failed to add static route for node gateway")
}

// start workers to do all the network operations
c.startWorkers(stopCh)
c.initResourceOnce()
<-stopCh
klog.Info("Shutting down workers")
}
Expand Down Expand Up @@ -609,3 +601,17 @@ func (c *Controller) startWorkers(stopCh <-chan struct{}) {

go wait.Until(c.syncVmLiveMigrationPort, 15*time.Second, stopCh)
}

func (c *Controller) initResourceOnce() {
c.registerSubnetMetrics()

if err := c.initDenyAllSecurityGroup(); err != nil {
util.LogFatalAndExit(err, "failed to initialize 'deny_all' security group")
}

// remove resources in ovndb that not exist any more in kubernetes resources
// process gc at last in case of affecting other init process
if err := c.gc(); err != nil {
util.LogFatalAndExit(err, "failed to run gc")
}
}
10 changes: 1 addition & 9 deletions pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *Controller) gc() error {
c.gcNode,
c.gcLogicalSwitch,
c.gcCustomLogicalRouter,
c.gcLogicalSwitchPort,
// The lsp gc is processed periodically by markAndCleanLSP, will not gc lsp when init
c.gcLoadBalancer,
c.gcPortGroup,
c.gcStaticRoute,
Expand Down Expand Up @@ -218,14 +218,6 @@ func (c *Controller) gcNode() error {
return nil
}

func (c *Controller) gcLogicalSwitchPort() error {
klog.Info("start to gc logical switch port")
if err := c.markAndCleanLSP(); err != nil {
return err
}
return c.markAndCleanLSP()
}

func (c *Controller) markAndCleanLSP() error {
klog.V(4).Infof("start to gc logical switch ports")
pods, err := c.podsLister.List(labels.Everything())
Expand Down

0 comments on commit ca061d5

Please sign in to comment.