Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move unnecessary init process after startWorkers #3124

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
hongzhen-ma marked this conversation as resolved.
Show resolved Hide resolved
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
Loading