From 43a68822e39316c4d3420c5e652fbc8a9e7ac5c2 Mon Sep 17 00:00:00 2001 From: nickmy9729 Date: Thu, 16 Aug 2018 15:33:35 -0400 Subject: [PATCH] Added code to allow snapshot inclusion of NodeMeta (#4527) --- agent/consul/fsm/snapshot_oss.go | 1 + agent/consul/fsm/snapshot_oss_test.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/agent/consul/fsm/snapshot_oss.go b/agent/consul/fsm/snapshot_oss.go index f9eb18cc8..b311520a5 100644 --- a/agent/consul/fsm/snapshot_oss.go +++ b/agent/consul/fsm/snapshot_oss.go @@ -75,6 +75,7 @@ func (s *snapshot) persistNodes(sink raft.SnapshotSink, Node: n.Node, Address: n.Address, TaggedAddresses: n.TaggedAddresses, + NodeMeta: n.Meta, } // Register the node itself diff --git a/agent/consul/fsm/snapshot_oss_test.go b/agent/consul/fsm/snapshot_oss_test.go index 9a6f3a355..4351ccdf8 100644 --- a/agent/consul/fsm/snapshot_oss_test.go +++ b/agent/consul/fsm/snapshot_oss_test.go @@ -28,7 +28,7 @@ func TestFSM_SnapshotRestore_OSS(t *testing.T) { // Add some state fsm.state.EnsureNode(1, &structs.Node{Node: "foo", Address: "127.0.0.1"}) - fsm.state.EnsureNode(2, &structs.Node{Node: "baz", Address: "127.0.0.2", TaggedAddresses: map[string]string{"hello": "1.2.3.4"}}) + fsm.state.EnsureNode(2, &structs.Node{Node: "baz", Address: "127.0.0.2", TaggedAddresses: map[string]string{"hello": "1.2.3.4"}, Meta: map[string]string{"testMeta": "testing123"}}) fsm.state.EnsureService(3, "foo", &structs.NodeService{ID: "web", Service: "web", Tags: nil, Address: "127.0.0.1", Port: 80}) fsm.state.EnsureService(4, "foo", &structs.NodeService{ID: "db", Service: "db", Tags: []string{"primary"}, Address: "127.0.0.1", Port: 5000}) fsm.state.EnsureService(5, "baz", &structs.NodeService{ID: "web", Service: "web", Tags: nil, Address: "127.0.0.2", Port: 80}) @@ -166,6 +166,8 @@ func TestFSM_SnapshotRestore_OSS(t *testing.T) { } if nodes[0].Node != "baz" || nodes[0].Address != "127.0.0.2" || + len(nodes[0].Meta) != 1 || + nodes[0].Meta["testMeta"] != "testing123" || len(nodes[0].TaggedAddresses) != 1 || nodes[0].TaggedAddresses["hello"] != "1.2.3.4" { t.Fatalf("bad: %v", nodes[0])