From d5446fb30237e84dfb5759c19f14c5ae0d45b37d Mon Sep 17 00:00:00 2001 From: Abhishek Kondur Date: Tue, 27 Dec 2022 19:47:30 +0530 Subject: [PATCH] fix node removal from host --- logic/hosts.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/logic/hosts.go b/logic/hosts.go index 90b0705d..9e29e689 100644 --- a/logic/hosts.go +++ b/logic/hosts.go @@ -235,15 +235,17 @@ func DissasociateNodeFromHost(n *models.Node, h *models.Host) error { break } } - - if index == -1 { - return fmt.Errorf("node %s, not found in host, %s", n.ID.String(), h.ID.String()) + if index < 0 { + if len(h.Nodes) == 0 { + return fmt.Errorf("node %s, not found in host, %s", n.ID.String(), h.ID.String()) + } + } else { + h.Nodes = RemoveStringSlice(h.Nodes, index) } - if err := deleteNodeByID(n); err != nil { return err } - h.Nodes = RemoveStringSlice(h.Nodes, index) + return UpsertHost(h) }