diff --git a/controllers/hosts.go b/controllers/hosts.go index c6c74a98..4cc2e78a 100644 --- a/controllers/hosts.go +++ b/controllers/hosts.go @@ -3,6 +3,7 @@ package controller import ( "encoding/json" "net/http" + "reflect" "github.com/gorilla/mux" "github.com/gravitl/netmaker/logger" @@ -79,6 +80,13 @@ func updateHost(w http.ResponseWriter, r *http.Request) { } newHost := newHostData.ConvertAPIHostToNMHost(currHost) + // check if relay information is changed + updateRelay := false + if newHost.IsRelay && len(newHost.RelayedHosts) > 0 { + if len(newHost.RelayedHosts) != len(currHost.RelayedHosts) || !reflect.DeepEqual(newHost.RelayedHosts, currHost.RelayedHosts) { + updateRelay = true + } + } logic.UpdateHost(newHost, currHost) // update the in memory struct values if err = logic.UpsertHost(newHost); err != nil { @@ -86,6 +94,9 @@ func updateHost(w http.ResponseWriter, r *http.Request) { logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal")) return } + if updateRelay { + logic.UpdateHostRelay(currHost.ID.String(), currHost.RelayedHosts, newHost.RelayedHosts) + } newNetworks := logic.GetHostNetworks(newHost.ID.String()) if len(newNetworks) > 0 { diff --git a/go.mod b/go.mod index 56636420..c31afa4c 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( ) require ( - github.com/gravitl/netclient v0.0.0-20230110143106-043eda46f800 + github.com/gravitl/netclient v0.0.0-20230110162232-fcba83b2f589 github.com/guumaster/tablewriter v0.0.10 github.com/matryer/is v1.4.0 github.com/olekukonko/tablewriter v0.0.5 @@ -52,9 +52,64 @@ require ( require ( cloud.google.com/go/compute/metadata v0.2.1 // indirect + github.com/Microsoft/go-winio v0.5.2 // indirect + github.com/bep/debounce v1.2.1 // indirect + github.com/cloverstd/tcping v0.1.1 // indirect + github.com/devilcove/httpclient v0.6.0 // indirect + github.com/docker/distribution v2.8.1+incompatible // indirect + github.com/docker/docker v20.10.17+incompatible // indirect + github.com/docker/go-connections v0.4.0 // indirect + github.com/docker/go-units v0.4.0 // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/google/gopacket v1.1.19 // indirect + github.com/guumaster/hostctl v1.1.3 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/labstack/echo/v4 v4.9.0 // indirect + github.com/labstack/gommon v0.3.1 // indirect + github.com/leaanthony/go-ansi-parser v1.0.1 // indirect + github.com/leaanthony/gosod v1.0.3 // indirect + github.com/leaanthony/slicer v1.5.0 // indirect + github.com/magiconair/properties v1.8.6 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.0.2 // indirect + github.com/pelletier/go-toml v1.9.5 // indirect + github.com/pelletier/go-toml/v2 v2.0.5 // indirect + github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 // indirect github.com/rivo/uniseg v0.2.0 // indirect + github.com/rogpeppe/go-internal v1.9.0 // indirect + github.com/samber/lo v1.27.1 // indirect + github.com/spf13/afero v1.9.2 // indirect + github.com/spf13/cast v1.5.0 // indirect + github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/viper v1.14.0 // indirect + github.com/subosito/gotenv v1.4.1 // indirect + github.com/tkrajina/go-reflector v0.5.5 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasttemplate v1.2.1 // indirect + github.com/vishvananda/netlink v1.1.0 // indirect + github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect + github.com/wailsapp/mimetype v1.4.1 // indirect + github.com/wailsapp/wails/v2 v2.3.1 // indirect + golang.design/x/clipboard v0.6.3 // indirect + golang.org/x/exp/shiny v0.0.0-20221208044002-44028be4359e // indirect + golang.org/x/image v0.0.0-20220601225756-64ec528b34cd // indirect + golang.org/x/mobile v0.0.0-20211207041440-4e6c2922fdee // indirect + golang.org/x/term v0.2.0 // indirect + golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect + golang.zx2c4.com/wireguard/windows v0.5.3 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) require ( diff --git a/logic/relay.go b/logic/relay.go index 6366db5c..89d0138b 100644 --- a/logic/relay.go +++ b/logic/relay.go @@ -222,3 +222,9 @@ func DeleteHostRelay(relayHostID string) (relayHost *models.Host, relayedHosts [ } return } + +// UpdateHostRelay - updates the relay host with new relayed hosts +func UpdateHostRelay(relayHostID string, oldRelayedHosts, newRelayedHosts []string) { + _ = SetRelayedHosts(false, relayHostID, oldRelayedHosts) + _ = SetRelayedHosts(true, relayHostID, newRelayedHosts) +}