diff --git a/pkg/network/node/egressip.go b/pkg/network/node/egressip.go index 8359b189fe5e..791e80e21a27 100644 --- a/pkg/network/node/egressip.go +++ b/pkg/network/node/egressip.go @@ -57,8 +57,8 @@ type egressIPWatcher struct { namespacesByVNID map[uint32]*namespaceEgress egressIPs map[string]*egressIPInfo - changedEgressIPs []*egressIPInfo - changedNamespaces []*namespaceEgress + changedEgressIPs map[*egressIPInfo]bool + changedNamespaces map[*namespaceEgress]bool localEgressLink netlink.Link localEgressNet *net.IPNet @@ -74,6 +74,9 @@ func newEgressIPWatcher(oc *ovsController, localIP string, masqueradeBit *int32) nodesByNodeIP: make(map[string]*nodeEgress), namespacesByVNID: make(map[uint32]*namespaceEgress), egressIPs: make(map[string]*egressIPInfo), + + changedEgressIPs: make(map[*egressIPInfo]bool), + changedNamespaces: make(map[*namespaceEgress]bool), } if masqueradeBit != nil { eip.masqueradeBit = 1 << uint32(*masqueradeBit) @@ -122,9 +125,9 @@ func (eip *egressIPWatcher) ensureEgressIPInfo(egressIP string) *egressIPInfo { } func (eip *egressIPWatcher) egressIPChanged(eg *egressIPInfo) { - eip.changedEgressIPs = append(eip.changedEgressIPs, eg) + eip.changedEgressIPs[eg] = true for _, ns := range eg.namespaces { - eip.changedNamespaces = append(eip.changedNamespaces, ns) + eip.changedNamespaces[ns] = true } } @@ -289,7 +292,7 @@ func (eip *egressIPWatcher) updateNamespaceEgress(vnid uint32, egressIPs []strin // Make sure we update OVS even if nothing was added or removed; the order might // have changed - eip.changedNamespaces = append(eip.changedNamespaces, ns) + eip.changedNamespaces[ns] = true eip.syncEgressIPs() } @@ -299,28 +302,18 @@ func (eip *egressIPWatcher) deleteNamespaceEgress(vnid uint32) { } func (eip *egressIPWatcher) syncEgressIPs() { - changedEgressIPs := make(map[*egressIPInfo]bool) - for _, eg := range eip.changedEgressIPs { - changedEgressIPs[eg] = true - } - eip.changedEgressIPs = eip.changedEgressIPs[:0] - - changedNamespaces := make(map[*namespaceEgress]bool) - for _, ns := range eip.changedNamespaces { - changedNamespaces[ns] = true - } - eip.changedNamespaces = eip.changedNamespaces[:0] - - for eg := range changedEgressIPs { + for eg := range eip.changedEgressIPs { eip.syncEgressNodeState(eg) } + eip.changedEgressIPs = make(map[*egressIPInfo]bool) - for ns := range changedNamespaces { + for ns := range eip.changedNamespaces { err := eip.syncEgressNamespaceState(ns) if err != nil { utilruntime.HandleError(fmt.Errorf("Error updating Namespace egress rules for VNID %d: %v", ns.vnid, err)) } } + eip.changedNamespaces = make(map[*namespaceEgress]bool) } func (eip *egressIPWatcher) syncEgressNodeState(eg *egressIPInfo) {