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 0857593 commit 3ee977a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
60 changes: 34 additions & 26 deletions pkg/controller/controller.go
Expand Up @@ -633,6 +633,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(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
defer c.shutdown()
klog.Info("Starting OVN controller")

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

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

if err := c.initNodeRoutes(); err != nil {
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 @@ -1035,3 +1013,33 @@ func (c *Controller) startWorkers(ctx context.Context) {
go wait.Until(c.runDelPodAnnotatedIptablesFipWorker, time.Second, ctx.Done())
}
}

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
Expand Up @@ -26,7 +26,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
1 change: 1 addition & 0 deletions pkg/controller/init.go
Expand Up @@ -422,6 +422,7 @@ func (c *Controller) InitIPAM() error {
}
}
}

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

0 comments on commit 3ee977a

Please sign in to comment.