Skip to content

Commit

Permalink
Merge pull request #3711 from trozet/fix-ovn-controller-exit
Browse files Browse the repository at this point in the history
Do not restart ovn-controller if encap IP doesn't change
  • Loading branch information
trozet committed Jun 28, 2023
2 parents 8a1a87d + 4622d61 commit f2ef8ea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
15 changes: 10 additions & 5 deletions go-controller/pkg/node/gateway_init_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand Down Expand Up @@ -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",
})
Expand Down Expand Up @@ -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",
Expand Down
23 changes: 21 additions & 2 deletions go-controller/pkg/node/node_ip_handler_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package node
import (
"fmt"
"net"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2ef8ea

Please sign in to comment.