Skip to content

Commit

Permalink
update encap ip by node annotation periodic
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Aug 25, 2021
1 parent 99ec3d4 commit 06810be
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pkg/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,49 @@ func (c *Controller) handlePod(key string) error {
return nil
}

func (c *Controller) loopEncapIpCheck() {
node, err := c.nodesLister.Get(c.config.NodeName)
if err != nil {
klog.Errorf("failed to get node %s %v", c.config.NodeName, err)
return
}

if nodeTunnelName := node.GetAnnotations()[util.TunnelInterfaceAnnotation]; nodeTunnelName != "" {
iface, err := findInterface(nodeTunnelName)
if err != nil {
klog.Errorf("failed to find iface %s, %v", nodeTunnelName, err)
return
}
if iface.Flags&net.FlagUp == 0 {
klog.Errorf("iface %v is down", nodeTunnelName)
return
}
addrs, err := iface.Addrs()
if err != nil {
klog.Errorf("failed to get iface addr. %v", err)
return
}
if len(addrs) == 0 {
klog.Errorf("iface %s has no ip address", nodeTunnelName)
return
}

// if assigned iface in node annotation is down or with no ip, the error msg should be printed periodically
if c.config.Iface == nodeTunnelName {
klog.V(3).Infof("node tunnel interface %s not changed", nodeTunnelName)
return
}
c.config.Iface = nodeTunnelName
klog.Infof("Update node tunnel interface %v", nodeTunnelName)

encapIP := strings.Split(addrs[0].String(), "/")[0]
if err = setEncapIP(encapIP); err != nil {
klog.Errorf("failed to set encap ip %s for iface %s", encapIP, c.config.Iface)
return
}
}
}

// Run starts controller
func (c *Controller) Run(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()
Expand All @@ -1007,6 +1050,7 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
go wait.Until(c.runSubnetWorker, time.Second, stopCh)
go wait.Until(c.runPodWorker, time.Second, stopCh)
go wait.Until(c.runGateway, 3*time.Second, stopCh)
go wait.Until(c.loopEncapIpCheck, 3*time.Second, stopCh)
<-stopCh
klog.Info("Shutting down workers")
}
Expand Down

0 comments on commit 06810be

Please sign in to comment.