reuse existing interface instead of erroring out
This commit is contained in:
parent
1f15a6d4f2
commit
9523ca624a
|
@ -6,7 +6,5 @@ mkdir -p /dev/net
|
|||
mknod /dev/net/tun c 10 200
|
||||
|
||||
wireguard-go wgoverlay
|
||||
# this disables kernel-mode interface creation; see wireguard.go:createWgInterface()
|
||||
export WESHER_E2E_TESTS=1
|
||||
|
||||
/app/wesher --log-level debug --cluster-key 'ILICZ3yBMCGAWNIq5Pn0bewBVimW3Q2yRVJ/Be+b1Uc=' "$@"
|
18
wireguard.go
18
wireguard.go
|
@ -77,8 +77,8 @@ func (wg *wgState) downInterface() error {
|
|||
}
|
||||
|
||||
func (wg *wgState) setUpInterface(nodes []node) error {
|
||||
if err := wg.createWgInterface(); err != nil {
|
||||
return err
|
||||
if err := netlink.LinkAdd(&wireguard{LinkAttrs: netlink.LinkAttrs{Name: wg.iface}}); err != nil && !os.IsExist(err) {
|
||||
return errors.Wrapf(err, "could not create interface %s", wg.iface)
|
||||
}
|
||||
|
||||
peerCfgs, err := wg.nodesToPeerConfigs(nodes)
|
||||
|
@ -133,17 +133,3 @@ func (wg *wgState) nodesToPeerConfigs(nodes []node) ([]wgtypes.PeerConfig, error
|
|||
}
|
||||
return peerCfgs, nil
|
||||
}
|
||||
|
||||
func (wg *wgState) createWgInterface() error {
|
||||
if _, err := wg.client.Device(wg.iface); err == nil {
|
||||
// device already exists, but we are running e2e tests, so we're using the user-mode implementation
|
||||
// see tests/entrypoint.sh
|
||||
if _, e2e := os.LookupEnv("WESHER_E2E_TESTS"); e2e {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if err := netlink.LinkAdd(&wireguard{LinkAttrs: netlink.LinkAttrs{Name: wg.iface}}); err != nil {
|
||||
return errors.Wrapf(err, "could not create interface %s", wg.iface)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue