diff --git a/resources/libraries/helper.rb b/resources/libraries/helper.rb index fcb6c4e..bbbe3b9 100644 --- a/resources/libraries/helper.rb +++ b/resources/libraries/helper.rb @@ -14,22 +14,14 @@ def local_routes routes end - # Queries Serf members to find the master node's IP. - def find_master_ip_from_serf(postgresql_hosts) - postgresql_master_node = postgresql_hosts.first - serf_output = `serf members` + def find_master_ip + cluster_info = node.dig('redborder', 'cluster_info') + postgresql_managers = node.dig('redborder', 'managers_per_services', 'postgresql') - master_ip = serf_output.lines.find do |line| - next unless line.include?('alive') - - node_name = line.split[0] - node_name == postgresql_master_node + if cluster_info && postgresql_managers + postgres_ips = cluster_info.select { |m, _| postgresql_managers.include?(m) }.map { |_, v| v['ipaddress_sync'] } + postgres_ips.first end - - return unless master_ip - - ip_part = master_ip.split[1] - ip_part&.split(':')&.first end end end diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 3ff3f15..330dc46 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -6,7 +6,6 @@ action :add do begin user = new_resource.user - postgresql_hosts = new_resource.postgresql_hosts routes = local_routes dnf_package 'postgresql' do @@ -42,7 +41,7 @@ ruby_block 'sync_if_not_master' do block do - master_ip = find_master_ip_from_serf(postgresql_hosts) + master_ip = find_master_ip if master_ip local_ips = `hostname -I`.split unless local_ips.include?(master_ip) diff --git a/resources/resources/config.rb b/resources/resources/config.rb index 7519878..ad68593 100644 --- a/resources/resources/config.rb +++ b/resources/resources/config.rb @@ -8,4 +8,3 @@ attribute :postgresql_port, kind_of: Integer, default: 5432 attribute :cdomain, kind_of: String, default: 'redborder.cluster' attribute :ipaddress, kind_of: String, default: '127.0.0.1' -attribute :postgresql_hosts, kind_of: Array, default: []