Skip to content

Commit

Permalink
feat: recycle lsp at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Jul 20, 2020
1 parent 3f9d7c9 commit c3814c7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
6 changes: 6 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ func (c *Controller) Run(stopCh <-chan struct{}) {

// start workers to do all the network operations
c.startWorkers(stopCh)

go wait.Until(func() {
if err := c.markAndCleanLSP(); err != nil {
klog.Errorf("gc lsp error %v", err)
}
}, 30*time.Second, stopCh)
<-stopCh
klog.Info("Shutting down workers")
}
Expand Down
35 changes: 27 additions & 8 deletions pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog"
"strings"
"time"
)

var lastNoPodLSP map[string]bool

func (c *Controller) gc() error {
gcFunctions := []func() error{
c.gcLogicalSwitch,
Expand Down Expand Up @@ -95,6 +98,14 @@ func (c *Controller) gcNode() error {
}

func (c *Controller) gcLogicalSwitchPort() error {
if err := c.markAndCleanLSP(); err != nil {
return err
}
time.Sleep(3 * time.Second)
return c.markAndCleanLSP()
}

func (c *Controller) markAndCleanLSP() error {
klog.Infof("start to gc logical switch ports")
pods, err := c.podsLister.List(labels.Everything())
if err != nil {
Expand All @@ -120,21 +131,29 @@ func (c *Controller) gcLogicalSwitchPort() error {
klog.Errorf("failed to list logical switch port, %v", err)
return err
}

noPodLSP := map[string]bool{}
for _, lsp := range lsps {
if !util.IsStringIn(lsp, ipNames) {
klog.Infof("gc logical switch port %s", lsp)
if err := c.ovnClient.DeletePort(lsp); err != nil {
klog.Errorf("failed to delete lsp %s, %v", lsp, err)
return err
}
if err := c.config.KubeOvnClient.KubeovnV1().IPs().Delete(lsp, &metav1.DeleteOptions{}); err != nil {
if !k8serrors.IsNotFound(err) {
klog.Errorf("failed to delete ip %s, %v", lsp, err)
if lastNoPodLSP[lsp] == false {
noPodLSP[lsp] = true
} else {
klog.Infof("gc logical switch port %s", lsp)
if err := c.ovnClient.DeletePort(lsp); err != nil {
klog.Errorf("failed to delete lsp %s, %v", lsp, err)
return err
}
if err := c.config.KubeOvnClient.KubeovnV1().IPs().Delete(lsp, &metav1.DeleteOptions{}); err != nil {
if !k8serrors.IsNotFound(err) {
klog.Errorf("failed to delete ip %s, %v", lsp, err)
return err
}
}
}
}
}

lastNoPodLSP = noPodLSP
return nil
}

Expand Down

0 comments on commit c3814c7

Please sign in to comment.