Browse Source

fix node removal from host

Abhishek Kondur 2 years ago
parent
commit
d5446fb302
1 changed files with 7 additions and 5 deletions
  1. 7 5
      logic/hosts.go

+ 7 - 5
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)
 }