From c2f4d7f2f08b6012637b62ab5c2daa570c669f9f Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Thu, 22 Jun 2023 07:19:40 -0400 Subject: [PATCH 1/4] wireguard check on startup --- cmd/root.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 8221e84b..11f0394c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -10,6 +10,7 @@ import ( "github.com/gravitl/netclient/config" "github.com/gravitl/netclient/functions" + "github.com/gravitl/netclient/wireguard" "github.com/spf13/cobra" "github.com/spf13/viper" "golang.org/x/exp/slog" @@ -54,6 +55,11 @@ func initConfig() { flags.BindPFlags(rootCmd.Flags()) config.InitConfig(flags) setupLoging(flags) + nc := wireguard.NewNCIface(config.Netclient(), config.GetNodes()) + if err := nc.Create(); err != nil { + slog.Error("failed to create interface, is wireguard installed", "error", err) + os.Exit(1) + } } func setupLoging(flags *viper.Viper) { From b179cf74ea86432bf0d5e7026799f91d072fcd87 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Fri, 23 Jun 2023 08:18:48 -0400 Subject: [PATCH 2/4] log update, close interface --- .github/workflows/branchtest.yml | 32 +++++++++++++++++++++++++++++++- cmd/root.go | 3 ++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml index dbce2297..9eca1f91 100644 --- a/.github/workflows/branchtest.yml +++ b/.github/workflows/branchtest.yml @@ -38,12 +38,42 @@ jobs: echo "netmakerbranch=develop" >> $GITHUB_OUTPUT fi + getserver: + runs-on: ubuntu-latest + needs: skip-check + if: ${{ needs.skip-check.outputs.skip != 'true' }} + outputs: + netmakerserver: ${{ steps.getserver.outputs.server }} + steps: + - name: getserver + id: getserver + run: | + server="" + for arg in "branch1" "branch2" "branch3" "branch4" "branch5"; do + echo checking $arg + result=$( ssh root@server.${arg}.clustercat.com '~/branchtesting/check.sh') + echo $result + if [ "$result" == "pass" ] + then + server=$arg + break + fi + done + echo server is $server + if [ "$server" == "" ] + then + echo server not set + exit 1 + fi + echo "netmakerserver=$server" >> $GITHUB_OUTPUT + terraform: - needs: getbranch + needs: [getbranch, getserver] uses: gravitl/devops/.github/workflows/terraform.yml@master with: netclientbranch: ${{ github.head_ref }} netmakerbranch: ${{ needs.getbranch.outputs.netmakerbranch }} + server: ${{ needs.getserver.outputs.netmakerserver }} secrets: inherit diff --git a/cmd/root.go b/cmd/root.go index 11f0394c..9ea6347e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -57,9 +57,10 @@ func initConfig() { setupLoging(flags) nc := wireguard.NewNCIface(config.Netclient(), config.GetNodes()) if err := nc.Create(); err != nil { - slog.Error("failed to create interface, is wireguard installed", "error", err) + slog.Error("failed to create interface, is wireguard installed?", "error", err) os.Exit(1) } + nc.Close() } func setupLoging(flags *viper.Viper) { From 815dba3ec79715906bfeb39cb7ef5337a18065bd Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Fri, 23 Jun 2023 08:26:13 -0400 Subject: [PATCH 3/4] Revert "log update, close interface" This reverts commit b179cf74ea86432bf0d5e7026799f91d072fcd87. --- .github/workflows/branchtest.yml | 32 +------------------------------- cmd/root.go | 3 +-- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml index 9eca1f91..dbce2297 100644 --- a/.github/workflows/branchtest.yml +++ b/.github/workflows/branchtest.yml @@ -38,42 +38,12 @@ jobs: echo "netmakerbranch=develop" >> $GITHUB_OUTPUT fi - getserver: - runs-on: ubuntu-latest - needs: skip-check - if: ${{ needs.skip-check.outputs.skip != 'true' }} - outputs: - netmakerserver: ${{ steps.getserver.outputs.server }} - steps: - - name: getserver - id: getserver - run: | - server="" - for arg in "branch1" "branch2" "branch3" "branch4" "branch5"; do - echo checking $arg - result=$( ssh root@server.${arg}.clustercat.com '~/branchtesting/check.sh') - echo $result - if [ "$result" == "pass" ] - then - server=$arg - break - fi - done - echo server is $server - if [ "$server" == "" ] - then - echo server not set - exit 1 - fi - echo "netmakerserver=$server" >> $GITHUB_OUTPUT - terraform: - needs: [getbranch, getserver] + needs: getbranch uses: gravitl/devops/.github/workflows/terraform.yml@master with: netclientbranch: ${{ github.head_ref }} netmakerbranch: ${{ needs.getbranch.outputs.netmakerbranch }} - server: ${{ needs.getserver.outputs.netmakerserver }} secrets: inherit diff --git a/cmd/root.go b/cmd/root.go index 9ea6347e..11f0394c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -57,10 +57,9 @@ func initConfig() { setupLoging(flags) nc := wireguard.NewNCIface(config.Netclient(), config.GetNodes()) if err := nc.Create(); err != nil { - slog.Error("failed to create interface, is wireguard installed?", "error", err) + slog.Error("failed to create interface, is wireguard installed", "error", err) os.Exit(1) } - nc.Close() } func setupLoging(flags *viper.Viper) { From b7d307d22cd652777a875b4a728324e20292d343 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Fri, 23 Jun 2023 08:29:55 -0400 Subject: [PATCH 4/4] close netmaker interface after check --- cmd/root.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 11f0394c..9ea6347e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -57,9 +57,10 @@ func initConfig() { setupLoging(flags) nc := wireguard.NewNCIface(config.Netclient(), config.GetNodes()) if err := nc.Create(); err != nil { - slog.Error("failed to create interface, is wireguard installed", "error", err) + slog.Error("failed to create interface, is wireguard installed?", "error", err) os.Exit(1) } + nc.Close() } func setupLoging(flags *viper.Viper) {