forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wireguard, linuxnodehandler: untangle wg from lnh
The reason the WireGuard agent node event handling was contained within the linuxNodeHandler code was routing, which is no longer the case. In addition, entangling the two leads to a deadlock, as diagnosed in GitHub issue cilium#24574. This patch thus implements NodeHandler for the WireGuard agent, and subscribes to the NodeManager itself. That way, the wait cycle of the deadlock is broken, as the linuxNodeHandler doesn't acquire the IPCache lock while holding its lock. From the perspective of the agent, the invocations of the callbacks change insofar that previously, only once the linuxNodeHandler considered itself "initialised" it would forward node events. Specifically, this excluded the initial sync of nodes performed on subscribe. However, I didn't see a reason to specifically replicate this behaviour. Suggested-by: Sebastian Wicki <[email protected]> Signed-off-by: David Bimmler <[email protected]>
- Loading branch information
1 parent
57c2064
commit c8598f8
Showing
7 changed files
with
79 additions
and
34 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package agent | ||
|
||
import ( | ||
datapath "github.com/cilium/cilium/pkg/datapath/types" | ||
"github.com/cilium/cilium/pkg/logging/logfields" | ||
nodeTypes "github.com/cilium/cilium/pkg/node/types" | ||
) | ||
|
||
// NodeAdd is called when a node is discovered for the first time. | ||
func (a *Agent) NodeAdd(newNode nodeTypes.Node) error { | ||
return a.nodeUpsert(newNode) | ||
} | ||
|
||
// NmdeUpdate is called when a node definition changes. Both the old | ||
// and new node definition is provided. NodeUpdate() is never called | ||
// before NodeAdd() is called for a particular node. | ||
func (a *Agent) NodeUpdate(_, newNode nodeTypes.Node) error { | ||
return a.nodeUpsert(newNode) | ||
} | ||
|
||
// NodeDelete is called after a node has been deleted | ||
func (a *Agent) NodeDelete(node nodeTypes.Node) error { | ||
if node.IsLocal() { | ||
return nil | ||
} | ||
|
||
return a.DeletePeer(node.Fullname()) | ||
} | ||
|
||
// NodeValidateImplementation is called to validate the implementation of | ||
// the node in the datapath. This function is intended to be run on an | ||
// interval to ensure that the datapath is consistently converged. | ||
func (a *Agent) NodeValidateImplementation(node nodeTypes.Node) error { | ||
return a.nodeUpsert(node) | ||
} | ||
|
||
func (a *Agent) nodeUpsert(node nodeTypes.Node) error { | ||
if node.IsLocal() || node.WireguardPubKey == "" { | ||
return nil | ||
} | ||
|
||
newIP4 := node.GetNodeIP(false) | ||
newIP6 := node.GetNodeIP(true) | ||
|
||
if err := a.UpdatePeer(node.Fullname(), node.WireguardPubKey, newIP4, newIP6); err != nil { | ||
log.WithError(err). | ||
WithField(logfields.NodeName, node.Fullname()). | ||
Warning("Failed to update wireguard configuration for peer") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// NodeConfigurationChanged is called when the local node configuration | ||
// has changed | ||
func (a *Agent) NodeConfigurationChanged(config datapath.LocalNodeConfiguration) error { return nil } |