Compare commits

...

9 Commits

Author SHA1 Message Date
Yu Shao Pang (SQPC) e89d9731ea Merge branch 'master' into 'master'
feat: account for potential consul port override to determine patroni leader

See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7576

Merged-by: Yu Shao Pang (SQPC) <yushao.pang@squarepoint-capital.com>
2024-05-06 17:35:34 +00:00
Andrew Patterson 196b5a3326 Merge branch 'deps/19dfc8b-42de0a3' into 'master'
Update gitlab-org/container-registry from v3.93.0-gitlab to v4.0.0-gitlab

See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7580

Merged-by: Andrew Patterson <apatterson@gitlab.com>
Approved-by: Clemens Beck <cbeck@gitlab.com>
Approved-by: Andrew Patterson <apatterson@gitlab.com>
Co-authored-by: deps <bot@dependencies.io>
2024-05-06 17:32:03 +00:00
deps 242873ad43 Update gitlab-org/container-registry from v3.93.0-gitlab to v4.0.0-gitlab
Changelog: changed
2024-05-02 08:21:39 +00:00
Yu Shao Pang (SQPC) 79177289a5 Update file ee_spec.rb 2024-04-30 15:31:37 +00:00
Yu Shao Pang (SQPC) 670165fc52 Update file ee_spec.rb 2024-04-30 14:29:32 +00:00
Yu Shao Pang (SQPC) 4c95dc39b5 Apply 1 suggestion(s) to 1 file(s) 2024-04-30 13:25:54 +00:00
Yu Shao Pang (SQPC) c3ee932c0f Update 2 files
- /files/gitlab-ctl-commands-ee/lib/postgresql/ee.rb
- /spec/chef/gitlab-ctl-commands-ee/lib/postgresql/ee_spec.rb
2024-04-30 13:20:33 +00:00
Yu Shao Pang (SQPC) d959213af0 Update file ee_spec.rb 2024-04-30 13:14:46 +00:00
Yu Shao Pang (SQPC) 97ccbcfa13 feat: account for potential consul port override to determine patroni leader 2024-04-30 12:24:00 +00:00
3 changed files with 48 additions and 4 deletions

View File

@ -19,7 +19,7 @@
require "#{Omnibus::Config.project_root}/lib/gitlab/version"
name 'registry'
version = Gitlab::Version.new('registry', 'v3.93.0-gitlab')
version = Gitlab::Version.new('registry', 'v4.0.0-gitlab')
default_version version.print(false)
display_version version.print(false).delete_suffix('-gitlab')

View File

@ -7,6 +7,7 @@ module GitlabCtl
def get_primary
node_attributes = GitlabCtl::Util.get_node_attributes
consul_enable = node_attributes.dig('consul', 'enable')
consul_dns_port = node_attributes.dig('consul', 'configuration', 'ports', 'dns') || 8600
postgresql_service_name = node_attributes.dig('patroni', 'scope')
raise 'Consul agent is not enabled on this node' unless consul_enable
@ -14,7 +15,7 @@ module GitlabCtl
raise 'PostgreSQL service name is not defined' if postgresql_service_name.nil? || postgresql_service_name.empty?
result = []
Resolv::DNS.open(nameserver_port: [['127.0.0.1', 8600]]) do |dns|
Resolv::DNS.open(nameserver_port: [['127.0.0.1', consul_dns_port]]) do |dns|
['master', 'standby-leader'].each do |postgresql_primary_service_name|
result = dns.getresources("#{postgresql_primary_service_name}.#{postgresql_service_name}.service.consul", Resolv::DNS::Resource::IN::SRV).map do |srv|
"#{dns.getaddress(srv.target)}:#{srv.port}"

View File

@ -37,6 +37,7 @@ RSpec.describe GitlabCtl::PostgreSQL::EE do
end
context 'when required settings are available' do
let(:dns_double) { instance_double(Resolv::DNS) }
before do
allow(GitlabCtl::Util).to receive(:get_node_attributes)
.and_return(
@ -49,17 +50,59 @@ RSpec.describe GitlabCtl::PostgreSQL::EE do
}
}
)
allow_any_instance_of(Resolv::DNS).to receive(:getresources)
allow(Resolv::DNS).to receive(:open).and_return(dns_double)
allow(dns_double).to receive(:getresources)
.with('master.fake.service.consul', Resolv::DNS::Resource::IN::SRV)
.and_return([Struct.new(:target, :port).new('fake.address', 6432)])
allow_any_instance_of(Resolv::DNS).to receive(:getaddress)
allow(dns_double).to receive(:getaddress)
.with('fake.address')
.and_return('1.2.3.4')
end
it 'initializes Resolv::DNS with port 8600' do
expect(Resolv::DNS).to receive(:open).with(nameserver_port: [['127.0.0.1', 8600]])
end
it 'should get the list of PostgreSQL endpoints' do
expect(described_class.get_primary).to eq ['1.2.3.4:6432']
end
end
end
context 'when consul has a dns port override' do
let(:dns_double) { instance_double(Resolv::DNS) }
before do
allow(GitlabCtl::Util).to receive(:get_node_attributes)
.and_return(
{
'consul' => {
'enable' => true,
'configuration' => {
"ports" => {
"dns" => 18600
}
}
},
'patroni' => {
'scope' => 'fake'
}
}
)
allow(Resolv::DNS).to receive(:open).and_return(dns_double)
allow(dns_double).to receive(:getresources)
.with('master.fake.service.consul', Resolv::DNS::Resource::IN::SRV)
.and_return([Struct.new(:target, :port).new('fake.address', 6432)])
allow(dns_double).to receive(:getaddress)
.with('fake.address')
.and_return('1.2.3.4')
end
it 'initializes Resolv::DNS with port 18600' do
expect(Resolv::DNS).to receive(:open).with(nameserver_port: [['127.0.0.1', 18600]])
end
it 'should get the list of PostgreSQL endpoints' do
expect(described_class.get_primary).to eq ['1.2.3.4:6432']
end
end
end