Created
November 15, 2021 21:34
-
-
Save trozet/2b6d9f55c62b093bafe74a8de2cbf46b to your computer and use it in GitHub Desktop.
address manager diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[trozet@fedora ovn-kubernetes]$ git diff | |
diff --git a/go-controller/pkg/factory/types.go b/go-controller/pkg/factory/types.go | |
index 04c8612df..f855ca961 100644 | |
--- a/go-controller/pkg/factory/types.go | |
+++ b/go-controller/pkg/factory/types.go | |
@@ -45,6 +45,8 @@ type NodeWatchFactory interface { | |
NodeInformer() cache.SharedIndexInformer | |
LocalPodInformer() cache.SharedIndexInformer | |
+ GetNode(name string) (*kapi.Node, error) | |
+ | |
GetService(namespace, name string) (*kapi.Service, error) | |
GetEndpoint(namespace, name string) (*kapi.Endpoints, error) | |
} | |
diff --git a/go-controller/pkg/node/gateway_shared_intf.go b/go-controller/pkg/node/gateway_shared_intf.go | |
index 111b79281..61da6f8e7 100644 | |
--- a/go-controller/pkg/node/gateway_shared_intf.go | |
+++ b/go-controller/pkg/node/gateway_shared_intf.go | |
@@ -1124,7 +1124,7 @@ func newSharedGateway(nodeName string, subnets []*net.IPNet, gwNextHops []net.IP | |
return err | |
} | |
- gw.nodeIPManager = newAddressManager(nodeName, kube, cfg) | |
+ gw.nodeIPManager = newAddressManager(nodeName, kube, cfg, watchFactory) | |
if config.Gateway.NodeportEnable { | |
klog.Info("Creating Shared Gateway Node Port Watcher") | |
diff --git a/go-controller/pkg/node/node_ip_handler_linux.go b/go-controller/pkg/node/node_ip_handler_linux.go | |
index 13970fedc..19fe3e05b 100644 | |
--- a/go-controller/pkg/node/node_ip_handler_linux.go | |
+++ b/go-controller/pkg/node/node_ip_handler_linux.go | |
@@ -3,6 +3,7 @@ | |
package node | |
import ( | |
+ "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/factory" | |
"net" | |
"sync" | |
"time" | |
@@ -17,6 +18,8 @@ import ( | |
) | |
type addressManager struct { | |
+ node string | |
+ watchFactory factory.NodeWatchFactory | |
addresses sets.String | |
nodeAnnotator kube.Annotator | |
mgmtPortConfig *managementPortConfig | |
@@ -24,8 +27,10 @@ type addressManager struct { | |
} | |
// initializes a new address manager which will hold all the IPs on a node | |
-func newAddressManager(nodeName string, k kube.Interface, config *managementPortConfig) *addressManager { | |
+func newAddressManager(nodeName string, k kube.Interface, config *managementPortConfig, watchFactory factory.NodeWatchFactory) *addressManager { | |
mgr := &addressManager{ | |
+ node: nodeName, | |
+ watchFactory: watchFactory, | |
addresses: sets.NewString(), | |
mgmtPortConfig: config, | |
} | |
@@ -107,7 +112,21 @@ func (c *addressManager) Run(stopChan <-chan struct{}) { | |
addrChanged = c.delAddr(a.LinkAddress.IP) | |
} | |
- if addrChanged { | |
+ var forceRun bool | |
+ node, err := c.watchFactory.GetNode(c.node) | |
+ if err != nil { | |
+ klog.Errorf("Unable to get node from informer, forcing address sync") | |
+ forceRun = true | |
+ } else { | |
+ // check to see if ips on the node differ from what we have | |
+ x:=util.ParseIPsFrom(node.Annotations) | |
+ if c.addresses == x { | |
+ forceRun = true | |
+ } | |
+ } | |
+ | |
+ | |
+ if addrChanged || forceRun { | |
if err := util.SetNodeHostAddresses(c.nodeAnnotator, c.addresses); err != nil { | |
klog.Errorf("Failed to set node annotations: %v", err) | |
continue | |
@@ -134,6 +153,23 @@ func (c *addressManager) Run(stopChan <-chan struct{}) { | |
klog.Info("Node IP manager is running") | |
} | |
+ | |
+func doesAnnotationsMatch(addresses ) bool { | |
+ var forceRun bool | |
+ node, err := c.watchFactory.GetNode(c.node) | |
+ if err != nil { | |
+ klog.Errorf("Unable to get node from informer, forcing address sync") | |
+ forceRun = true | |
+ } else { | |
+ // check to see if ips on the node differ from what we have | |
+ x:=util.ParseIPsFrom(node.Annotations) | |
+ if c.addresses == x { | |
+ forceRun = true | |
+ } | |
+ } | |
+ return forceRun | |
+} | |
+ | |
// detects if the IP is valid for a node | |
// excludes things like local IPs, mgmt port ip | |
func (c *addressManager) isValidNodeIP(addr net.IP) bool { | |
@@ -161,6 +197,7 @@ func (c *addressManager) isValidNodeIP(addr net.IP) bool { | |
} | |
func (c *addressManager) sync() { | |
+ c.addresses = "" | |
addrs, err := net.InterfaceAddrs() | |
if err != nil { | |
klog.Errorf("Failed to initialize Node IP Manager: unable list all IPs on the node, error: %v", err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment