Skip to content

Commit

Permalink
Merge branch 'net-687' of github.com:gravitl/netmaker into net-687
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielseibel1 committed Nov 16, 2023
2 parents a950189 + 94524b9 commit 233b730
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
19 changes: 19 additions & 0 deletions controllers/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
"github.com/gravitl/netmaker/models"
Expand Down Expand Up @@ -329,6 +330,24 @@ func deleteHostFromNetwork(w http.ResponseWriter, r *http.Request) {
// confirm host exists
currHost, err := logic.GetHost(hostid)
if err != nil {
if database.IsEmptyRecord(err) {
// check if there is any daemon nodes that needs to be deleted
node, err := logic.GetNodeByHostRef(hostid, network)
if err != nil {
slog.Error("couldn't get node for host", "hostid", hostid, "network", network, "error", err)
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
if err = logic.DeleteNodeByID(&node); err != nil {
slog.Error("failed to force delete daemon node",
"nodeid", node.ID.String(), "hostid", hostid, "network", network, "error", err)
logic.ReturnErrorResponse(w, r, logic.FormatError(fmt.Errorf("failed to force delete daemon node: "+err.Error()), "internal"))
return
}
logic.ReturnSuccessResponse(w, r, "force deleted daemon node successfully")
return
}

logger.Log(0, r.Header.Get("user"), "failed to find host:", err.Error())
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
return
Expand Down
16 changes: 15 additions & 1 deletion mq/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,21 @@ func UpdateNode(client mqtt.Client, msg mqtt.Message) {
return
}
if ifaceDelta { // reduce number of unneeded updates, by only sending on iface changes
if err = PublishPeerUpdate(); err != nil {
if !newNode.Connected {
err = PublishDeletedNodePeerUpdate(&newNode)
host, err := logic.GetHost(newNode.HostID.String())
if err != nil {
slog.Error("failed to get host for the node", "nodeid", newNode.ID.String(), "error", err)
return
}
allNodes, err := logic.GetAllNodes()
if err == nil {
PublishSingleHostPeerUpdate(host, allNodes, nil, nil)
}
} else {
err = PublishPeerUpdate()
}
if err != nil {
slog.Warn("error updating peers when node informed the server of an interface change", "nodeid", currentNode.ID, "error", err)
}
}
Expand Down
4 changes: 0 additions & 4 deletions mq/publishers.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ func PublishSingleHostPeerUpdate(host *models.Host, allNodes []models.Node, dele
if err != nil {
return err
}
if len(peerUpdate.Peers) == 0 { // no peers to send
return nil
}

data, err := json.Marshal(&peerUpdate)
if err != nil {
return err
Expand Down

0 comments on commit 233b730

Please sign in to comment.