mirror of https://github.com/status-im/consul.git
Allow renaming nodes when ID is unchanged
This commit is contained in:
parent
a9868ae956
commit
89ab642928
|
@ -355,11 +355,7 @@ func (s *Store) ensureNodeTxn(tx *memdb.Txn, idx uint64, node *structs.Node) err
|
||||||
if existing != nil {
|
if existing != nil {
|
||||||
n = existing.(*structs.Node)
|
n = existing.(*structs.Node)
|
||||||
if n.Node != node.Node {
|
if n.Node != node.Node {
|
||||||
if n.Address != node.Address {
|
// We are actually renaming a node, remove its reference first
|
||||||
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)
|
|
||||||
err := s.deleteNodeTxn(tx, idx, n.Node)
|
err := s.deleteNodeTxn(tx, idx, n.Node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error while renaming Node ID: %q from %s to %s",
|
return fmt.Errorf("Error while renaming Node ID: %q from %s to %s",
|
||||||
|
|
|
@ -466,18 +466,7 @@ func TestStateStore_EnsureNode(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now try to add another node with the same ID
|
// Renaming a node should work if ID is the same
|
||||||
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
|
|
||||||
in = &structs.Node{
|
in = &structs.Node{
|
||||||
Node: "node1-renamed",
|
Node: "node1-renamed",
|
||||||
ID: types.NodeID("cda916bc-a357-4a19-b886-59419fcee50c"),
|
ID: types.NodeID("cda916bc-a357-4a19-b886-59419fcee50c"),
|
||||||
|
|
Loading…
Reference in New Issue