From ae4ce3770c71de6c2c9ba456d11bf30b651f83ab Mon Sep 17 00:00:00 2001 From: dolibali <139439533+dolibali@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:21:44 +0800 Subject: [PATCH] add loop check for tunnel nic (#4736) * add loop check for tunnel nic Signed-off-by: dolibali * fix gofumpt err Signed-off-by: dolibali --------- Signed-off-by: dolibali Co-authored-by: dolibali --- pkg/daemon/controller.go | 1 + pkg/daemon/ovs_linux.go | 30 ++++++++++++++++++++++++++++++ pkg/daemon/ovs_windows.go | 4 ++++ pkg/util/const.go | 3 +++ 4 files changed, 38 insertions(+) diff --git a/pkg/daemon/controller.go b/pkg/daemon/controller.go index 8a146c8c40c..eb9bd7dca4a 100644 --- a/pkg/daemon/controller.go +++ b/pkg/daemon/controller.go @@ -596,6 +596,7 @@ func (c *Controller) Run(stopCh <-chan struct{}) { klog.Info("Started workers") go wait.Until(c.loopOvn0Check, 5*time.Second, stopCh) go wait.Until(c.loopOvnExt0Check, 5*time.Second, stopCh) + go wait.Until(c.loopTunnelCheck, 5*time.Second, stopCh) go wait.Until(c.runAddOrUpdateProviderNetworkWorker, time.Second, stopCh) go wait.Until(c.runDeleteProviderNetworkWorker, time.Second, stopCh) go wait.Until(c.runSubnetWorker, time.Second, stopCh) diff --git a/pkg/daemon/ovs_linux.go b/pkg/daemon/ovs_linux.go index 1868e248408..b6f339c2f1c 100644 --- a/pkg/daemon/ovs_linux.go +++ b/pkg/daemon/ovs_linux.go @@ -714,6 +714,36 @@ func (c *Controller) loopOvn0Check() { } } +// This method checks the status of the tunnel interface, +// If the interface is found to be down, it attempts to bring it up +func (c *Controller) loopTunnelCheck() { + tunnelType := c.config.NetworkType + var tunnelNic string + switch tunnelType { + case "vxlan": + tunnelNic = util.VxlanNic + case "geneve": + tunnelNic = util.GeneveNic + case "stt": + // TODO: tunnelNic = "stt tunnel nic name" + return + default: + return + } + + link, err := netlink.LinkByName(tunnelNic) + if err != nil || link == nil { + return + } + + if link.Attrs().OperState == netlink.OperDown { + klog.Errorf("nic: %s is down, attempting to bring it up", tunnelNic) + if err := netlink.LinkSetUp(link); err != nil { + klog.Errorf("fail to bring up nic: %s, %v", tunnelNic, err) + } + } +} + func (c *Controller) checkNodeGwNicInNs(nodeExtIP, ip, gw string, gwNS ns.NetNS) error { exists, err := ovs.PortExists(util.NodeGwNic) if err != nil { diff --git a/pkg/daemon/ovs_windows.go b/pkg/daemon/ovs_windows.go index 12e19650259..a0aa28c935b 100644 --- a/pkg/daemon/ovs_windows.go +++ b/pkg/daemon/ovs_windows.go @@ -343,6 +343,10 @@ func (c *Controller) loopOvnExt0Check() { // no need to check ovnext0 on Windows } +func (c *Controller) loopTunnelCheck() { + // no need to check tunnel on Windows +} + func configureMirrorLink(portName string, mtu int) error { adapter, err := util.GetNetAdapter(portName, false) if err != nil { diff --git a/pkg/util/const.go b/pkg/util/const.go index a26189eb3ea..8acda2daaf0 100644 --- a/pkg/util/const.go +++ b/pkg/util/const.go @@ -133,6 +133,9 @@ const ( NodeLspPrefix = "node-" NodeAllowPriority = "3000" + VxlanNic = "vxlan_sys_4789" + GeneveNic = "genev_sys_6081" + SecurityGroupHighestPriority = "2300" SecurityGroupBasePriority = "2005" SecurityGroupAllowPriority = "2004"