fix node removal from host

This commit is contained in:
Abhishek Kondur 2022-12-27 19:47:30 +05:30
parent 749452af53
commit d5446fb302

View file

@ -235,15 +235,17 @@ func DissasociateNodeFromHost(n *models.Node, h *models.Host) error {
break break
} }
} }
if index < 0 {
if index == -1 { if len(h.Nodes) == 0 {
return fmt.Errorf("node %s, not found in host, %s", n.ID.String(), h.ID.String()) 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 { if err := deleteNodeByID(n); err != nil {
return err return err
} }
h.Nodes = RemoveStringSlice(h.Nodes, index)
return UpsertHost(h) return UpsertHost(h)
} }