consul_syncer 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/consul_syncer/version.rb +1 -1
- data/lib/consul_syncer.rb +21 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 875c3e3eee8a06872dde88a612d7dfb8ae33ac59377d441e54afa6585da787b7
|
4
|
+
data.tar.gz: 4e1d1d3701fc464772745858109ff04260b0a8568e7ce8ad8eeab6ad6de26032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae7f93e5464309a3ed828ba18e7f43bd8ff2ec8a111b513d225f598d2a84c6df80c480722d3f1545a7813c2a34fbf5de10083357432d6f3f9336bf4923a9f082
|
7
|
+
data.tar.gz: 3cdeb2e0566669014aa37ae01cebcb453593e993cf9cee5a4155d26649fddb8f5ca38e179cd911979824c08a5fa98d23345bf441c5b2eb8e5937001263aedba0
|
data/lib/consul_syncer.rb
CHANGED
@@ -18,9 +18,13 @@ class ConsulSyncer
|
|
18
18
|
# changing tags means all previous services need to be removed manually since
|
19
19
|
# they can no longer be found
|
20
20
|
def sync(expected_definitions, tags, dry: false)
|
21
|
-
|
21
|
+
planned = plan(expected_definitions, tags)
|
22
|
+
execute planned unless dry
|
23
|
+
planned.size # let users know what we did and keep legacy api working
|
24
|
+
end
|
22
25
|
|
23
|
-
|
26
|
+
def plan(expected_definitions, tags)
|
27
|
+
raise ArgumentError, "Need at least 1 tag to reliably update endpoints" if tags.empty?
|
24
28
|
|
25
29
|
# ensure consistent tags to find the endpoints after adding
|
26
30
|
expected_definitions = expected_definitions.dup
|
@@ -44,6 +48,7 @@ class ConsulSyncer
|
|
44
48
|
|
45
49
|
identifying = [:node, :service_id]
|
46
50
|
interesting = [*identifying, :service, :service_address, :address, :tags, :port]
|
51
|
+
planned = []
|
47
52
|
|
48
53
|
expected_definitions.each do |expected|
|
49
54
|
description = "#{expected[:service] || "*"} / #{expected[:service_id] || "*"} on #{expected.fetch(:node)} in Consul"
|
@@ -60,23 +65,30 @@ class ConsulSyncer
|
|
60
65
|
@logger.debug "Found #{description}"
|
61
66
|
elsif remove_matching_service!(actual_definitions, expected, identifying)
|
62
67
|
@logger.info "Updating #{description}"
|
63
|
-
|
64
|
-
register **expected unless dry
|
68
|
+
planned << [:register, [], expected]
|
65
69
|
else
|
66
70
|
@logger.info "Adding #{description}"
|
67
|
-
|
68
|
-
register **expected unless dry
|
71
|
+
planned << [:register, [], expected]
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
75
|
# all definitions that are left did not match any expected definitions and are no longer needed
|
73
76
|
actual_definitions.each do |actual|
|
74
77
|
@logger.info "Removing #{actual.fetch(:service)} / #{actual.fetch(:service_id)} on #{actual.fetch(:node)} in Consul"
|
75
|
-
|
76
|
-
deregister actual.fetch(:node), actual.fetch(:service_id) unless dry
|
78
|
+
planned << [:deregister, [actual.fetch(:node), actual.fetch(:service_id)], nil]
|
77
79
|
end
|
78
80
|
|
79
|
-
|
81
|
+
planned
|
82
|
+
end
|
83
|
+
|
84
|
+
def execute(planned)
|
85
|
+
planned.each do |m, args, kwargs|
|
86
|
+
if kwargs
|
87
|
+
send m, *args, **kwargs
|
88
|
+
else
|
89
|
+
send m, *args
|
90
|
+
end
|
91
|
+
end
|
80
92
|
end
|
81
93
|
|
82
94
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul_syncer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|