diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh index a37e223..ff641e7 100755 --- a/tests/entrypoint.sh +++ b/tests/entrypoint.sh @@ -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=' "$@" \ No newline at end of file diff --git a/wireguard.go b/wireguard.go index a823696..7556b61 100644 --- a/wireguard.go +++ b/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 -}