From 89ab64292818087c43739fb6c1fc44eee4b67ffd Mon Sep 17 00:00:00 2001 From: Pierre Souchay Date: Wed, 18 Apr 2018 15:39:38 +0200 Subject: [PATCH] Allow renaming nodes when ID is unchanged --- agent/consul/state/catalog.go | 6 +----- agent/consul/state/catalog_test.go | 13 +------------ 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 8196934845..f01148adb1 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -355,11 +355,7 @@ func (s *Store) ensureNodeTxn(tx *memdb.Txn, idx uint64, node *structs.Node) err if existing != nil { n = existing.(*structs.Node) if n.Node != node.Node { - if n.Address != node.Address { - return fmt.Errorf("node ID %q for node %q (%s) aliases existing node %q (%s)", - node.ID, node.Node, node.Address, n.Node, n.Address) - } - fmt.Printf("Node renaming: %s VS %s -- idx=%d\n", node.Node, n.Node, idx) + // We are actually renaming a node, remove its reference first err := s.deleteNodeTxn(tx, idx, n.Node) if err != nil { return fmt.Errorf("Error while renaming Node ID: %q from %s to %s", diff --git a/agent/consul/state/catalog_test.go b/agent/consul/state/catalog_test.go index 03e0f1f485..593fbcadaa 100644 --- a/agent/consul/state/catalog_test.go +++ b/agent/consul/state/catalog_test.go @@ -466,18 +466,7 @@ func TestStateStore_EnsureNode(t *testing.T) { t.Fatalf("err: %v", err) } - // Now try to add another node with the same ID - in = &structs.Node{ - Node: "nope", - ID: types.NodeID("cda916bc-a357-4a19-b886-59419fcee50c"), - Address: "1.2.3.4", - } - err = s.EnsureNode(5, in) - if err == nil || !strings.Contains(err.Error(), "aliases existing node") { - t.Fatalf("err: %v", err) - } - - // Renaming a node should work as long as IP did not change + // Renaming a node should work if ID is the same in = &structs.Node{ Node: "node1-renamed", ID: types.NodeID("cda916bc-a357-4a19-b886-59419fcee50c"),