Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET-1608:reset failover if endpoint changed #3149

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion controllers/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,22 @@ func pull(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
return
}

sendPeerUpdate := false
for _, nodeID := range host.Nodes {
node, err := logic.GetNodeByID(nodeID)
if err != nil {
slog.Error("failed to get node:", "id", node.ID, "error", err)
continue
}
if node.FailedOverBy != uuid.Nil {
go logic.ResetFailedOverPeer(&node)
logic.ResetFailedOverPeer(&node)
sendPeerUpdate = true
}
}
if sendPeerUpdate {
if err := mq.PublishPeerUpdate(true); err != nil {
logger.Log(0, "fail to publish peer update: ", err.Error())
}
}
allNodes, err := logic.GetAllNodes()
Expand Down
18 changes: 18 additions & 0 deletions logic/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
"golang.org/x/exp/slog"

"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/logger"
Expand Down Expand Up @@ -254,14 +255,31 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
currHost.WgPublicListenPort = newHost.WgPublicListenPort
sendPeerUpdate = true
}
isEndpointChanged := false
if currHost.EndpointIP.String() != newHost.EndpointIP.String() {
currHost.EndpointIP = newHost.EndpointIP
sendPeerUpdate = true
isEndpointChanged = true
}
if currHost.EndpointIPv6.String() != newHost.EndpointIPv6.String() {
currHost.EndpointIPv6 = newHost.EndpointIPv6
sendPeerUpdate = true
isEndpointChanged = true
}

if isEndpointChanged {
for _, nodeID := range currHost.Nodes {
node, err := GetNodeByID(nodeID)
if err != nil {
slog.Error("failed to get node:", "id", node.ID, "error", err)
continue
}
if node.FailedOverBy != uuid.Nil {
ResetFailedOverPeer(&node)
}
}
}

currHost.DaemonInstalled = newHost.DaemonInstalled
currHost.Debug = newHost.Debug
currHost.Verbosity = newHost.Verbosity
Expand Down
Loading