Skip to content

Commit

Permalink
move unnecessary init process after startWorkers
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Aug 9, 2023
1 parent cd1202c commit 2dd1cc2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
60 changes: 34 additions & 26 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ func Run(ctx context.Context, config *Configuration) {
// 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(ctx context.Context) {
// 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
if err := c.ovnClient.SetLsDnatModDlDst(c.config.LsDnatModDlDst); err != nil {
util.LogFatalAndExit(err, "failed to set NB_Global option ls_dnat_mod_dl_dst")
}
Expand All @@ -782,10 +784,6 @@ func (c *Controller) Run(ctx context.Context) {
util.LogFatalAndExit(err, "failed to initialize default vpc")
}

if err := c.initNodeChassis(); err != nil {
util.LogFatalAndExit(err, "failed to initialize node chassis")
}

// sync ip crd before initIPAM since ip crd will be used to restore vm and statefulset pod in initIPAM
if err := c.initSyncCrdIPs(); err != nil {
util.LogFatalAndExit(err, "failed to sync crd ips")
Expand All @@ -799,41 +797,21 @@ func (c *Controller) Run(ctx context.Context) {
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")
}

if c.config.PodDefaultFipType == util.IptablesFip {
if err := c.initSyncCrdVpcNatGw(); err != nil {
util.LogFatalAndExit(err, "failed to sync crd vpc nat gateways")
}
}

if c.config.EnableLb {
if err := c.initVpcDnsConfig(); err != nil {
util.LogFatalAndExit(err, "failed to initialize vpc-dns")
}
}

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(ctx)

c.initResourceOnce()
<-ctx.Done()
klog.Info("Shutting down workers")
}
Expand Down Expand Up @@ -1160,3 +1138,33 @@ func (c *Controller) allSubnetReady(subnets ...string) (bool, error) {

return true, nil
}

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

if err := c.initNodeChassis(); err != nil {
util.LogFatalAndExit(err, "failed to initialize node chassis")
}

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

if c.config.PodDefaultFipType == util.IptablesFip {
if err := c.initSyncCrdVpcNatGw(); err != nil {
util.LogFatalAndExit(err, "failed to sync crd vpc nat gateways")
}
}

if c.config.EnableLb {
if err := c.initVpcDnsConfig(); err != nil {
util.LogFatalAndExit(err, "failed to initialize vpc-dns")
}
}

// 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 @@ -28,7 +28,7 @@ func (c *Controller) gc() error {
c.gcChassis,
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 @@ -277,14 +277,6 @@ func (c *Controller) gcVip() 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
2 changes: 2 additions & 0 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ func (c *Controller) InitIPAM() error {
klog.Errorf("failed to init ipam from iptables eip cr %s: %v", eip.Name, err)
}
}

oeips, err := c.ovnEipsLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list ovn eips: %v", err)
Expand All @@ -461,6 +462,7 @@ func (c *Controller) InitIPAM() error {
klog.Errorf("failed to init ipam from ovn eip cr %s: %v", oeip.Name, err)
}
}

nodes, err := c.nodesLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list nodes: %v", err)
Expand Down

0 comments on commit 2dd1cc2

Please sign in to comment.