From 4622d618699ad5c16db28e3e099acf22a16caf7c Mon Sep 17 00:00:00 2001 From: Tim Rozet Date: Tue, 27 Jun 2023 17:42:45 -0400 Subject: [PATCH] Do not restart ovn-controller if encap IP doesn't change Signed-off-by: Tim Rozet --- .../pkg/node/gateway_init_linux_test.go | 15 ++++++++---- .../pkg/node/node_ip_handler_linux.go | 23 +++++++++++++++++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/go-controller/pkg/node/gateway_init_linux_test.go b/go-controller/pkg/node/gateway_init_linux_test.go index 6a297670e8f..3e1a5b9218e 100644 --- a/go-controller/pkg/node/gateway_init_linux_test.go +++ b/go-controller/pkg/node/gateway_init_linux_test.go @@ -150,6 +150,9 @@ func shareGatewayInterfaceTest(app *cli.App, testNS ns.NetNS, Output: "7", }) if setNodeIP { + fexec.AddFakeCmdsNoOutputNoError([]string{ + "ovs-vsctl --timeout=15 get Open_vSwitch . external_ids:ovn-encap-ip", + }) fexec.AddFakeCmdsNoOutputNoError([]string{ "ovs-vsctl --timeout=15 set Open_vSwitch . external_ids:ovn-encap-ip=192.168.1.10", }) @@ -533,6 +536,9 @@ func shareGatewayInterfaceDPUTest(app *cli.App, testNS ns.NetNS, Cmd: "ovs-vsctl --timeout=15 get interface " + hostRep + " ofport", Output: "9", }) + fexec.AddFakeCmdsNoOutputNoError([]string{ + "ovs-vsctl --timeout=15 get Open_vSwitch . external_ids:ovn-encap-ip", + }) fexec.AddFakeCmdsNoOutputNoError([]string{ "ovs-vsctl --timeout=15 set Open_vSwitch . external_ids:ovn-encap-ip=192.168.1.101", }) @@ -910,11 +916,10 @@ func localGatewayInterfaceTest(app *cli.App, testNS ns.NetNS, Cmd: "ovs-vsctl --timeout=15 get interface eth0 ofport", Output: "7", }) - fexec.AddFakeCmdsNoOutputNoError([]string{ - "ovs-vsctl --timeout=15 set Open_vSwitch . external_ids:ovn-encap-ip=192.168.1.10", - }) - fexec.AddFakeCmdsNoOutputNoError([]string{ - "ovn-appctl --timeout=5 -t ovn-controller exit --restart", + // IP already configured, do not try to set it or restart ovn-controller + fexec.AddFakeCmd(&ovntest.ExpectedCmd{ + Cmd: "ovs-vsctl --timeout=15 get Open_vSwitch . external_ids:ovn-encap-ip", + Output: "192.168.1.10", }) fexec.AddFakeCmd(&ovntest.ExpectedCmd{ Cmd: "ip route replace table 7 172.16.1.0/24 via 10.1.1.1 dev ovn-k8s-mp0", diff --git a/go-controller/pkg/node/node_ip_handler_linux.go b/go-controller/pkg/node/node_ip_handler_linux.go index 16243f6d90c..1e37e1dc7ae 100644 --- a/go-controller/pkg/node/node_ip_handler_linux.go +++ b/go-controller/pkg/node/node_ip_handler_linux.go @@ -6,6 +6,7 @@ package node import ( "fmt" "net" + "strings" "sync" "time" @@ -327,13 +328,31 @@ func (c *addressManager) nodePrimaryAddrChanged() (bool, error) { // updateOVNEncapIP updates encap IP to OVS when the node primary IP changed. func (c *addressManager) updateOVNEncapIPAndReconnect() { - cmd := []string{ + checkCmd := []string{ + "get", + "Open_vSwitch", + ".", + "external_ids:ovn-encap-ip", + } + encapIP, stderr, err := util.RunOVSVsctl(checkCmd...) + if err != nil { + klog.Warningf("Unable to retrieve configured ovn-encap-ip from OVS: %v, %q", err, stderr) + } else { + encapIP = strings.TrimSuffix(encapIP, "\n") + if len(encapIP) > 0 && c.nodePrimaryAddr.String() == encapIP { + klog.V(4).Infof("Will not update encap IP, value: %s is the already configured", c.nodePrimaryAddr) + return + } + } + + confCmd := []string{ "set", "Open_vSwitch", ".", fmt.Sprintf("external_ids:ovn-encap-ip=%s", c.nodePrimaryAddr), } - _, stderr, err := util.RunOVSVsctl(cmd...) + + _, stderr, err = util.RunOVSVsctl(confCmd...) if err != nil { klog.Errorf("Error setting OVS encap IP: %v %q", err, stderr) return