Skip to content
Snippets Groups Projects
Commit 93f2f97a5a30 authored by Stan Hu's avatar Stan Hu
Browse files

Accept multiple bind addresses in Redis config

As specified in https://redis.io/docs/management/config-file/, Redis
can bind to multiple addresses with a space-separated field. Previously
attempting to do this without setting `gitlab_rails['redis_host']`
would fail because a URI could not be built with a space in the
hostname.

This commit now splits the string with the space and picks the first
address as the default Redis host.

Relates to https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/8465

Changelog: added
parent 9273fa9e6ee6
No related branches found
No related tags found
3 merge requests!128heptapod#1534: making 1.5 the oldstable,!125heptapod#1494: make 1.5 the new stable,!124Upstream 16.11 quasi branching point
......@@ -78,4 +78,5 @@
return unless redis_managed?
redis_bind = Gitlab['redis']['bind'] || node['redis']['bind']
Gitlab['redis']['default_host'] = redis_bind.split(' ').first
......@@ -81,5 +82,5 @@
Gitlab['gitlab_rails']['redis_host'] ||= redis_bind
Gitlab['gitlab_rails']['redis_host'] ||= Gitlab['redis']['default_host']
redis_port_config_key = if Gitlab['redis'].key?('port') && !Gitlab['redis']['port'].zero?
# If Redis is specified to run on a non-TLS port
......
......@@ -51,7 +51,7 @@
end
def redis_cli_tcp_connect_options(args)
args << ["-h #{redis['bind']}"]
args << ["-h #{redis['default_host']}"]
port = redis['port'].to_i
if port.zero?
......
redis_dir='<%= node['redis']['dir'] %>'
redis_host='<%= node['redis']['bind'] %>'
redis_host='<%= node['redis']['default_host'] %>'
redis_port='<%= node['redis']['port'] %>'
redis_tls_port='<%= node['redis']['tls_port'] %>'
redis_tls_auth_clients='<%= node['redis']['tls_auth_clients'] %>'
......
......@@ -31,6 +31,23 @@
let(:redis_host) { '1.2.3.4' }
let(:redis_port) { 6370 }
context 'when binding to multiple addresses' do
before do
stub_gitlab_rb(
redis: {
bind: '1.2.3.4 5.6.7.8',
port: redis_port
}
)
end
it 'expects redis_host to match first bind value from redis' do
expect(node['gitlab']['gitlab_rails']['redis_host']).to eq '1.2.3.4'
subject.parse_redis_settings
end
end
context 'when not using sentinels' do
before do
stub_gitlab_rb(
......
......@@ -12,7 +12,7 @@
let(:gitlab_redis_cli_rc) do
<<-EOF
redis_dir='/var/opt/gitlab/redis'
redis_host='127.0.0.1'
redis_host=''
redis_port='0'
redis_tls_port=''
redis_tls_auth_clients='optional'
......@@ -201,6 +201,46 @@
end
end
context 'with multiple bind addresses' do
let(:redis_host) { '1.2.3.4 5.6.7.8' }
let(:redis_port) { 6370 }
let(:master_ip) { '10.0.0.0' }
let(:master_port) { 6371 }
let(:gitlab_redis_cli_rc) do
<<-EOF
redis_dir='/var/opt/gitlab/redis'
redis_host='1.2.3.4'
redis_port='6370'
redis_tls_port=''
redis_tls_auth_clients='optional'
redis_tls_cacert_file='/opt/gitlab/embedded/ssl/certs/cacert.pem'
redis_tls_cacert_dir='/opt/gitlab/embedded/ssl/certs/'
redis_tls_cert_file=''
redis_tls_key_file=''
redis_socket=''
EOF
end
before do
stub_gitlab_rb(
redis: {
bind: redis_host,
port: redis_port,
master_ip: master_ip,
master_port: master_port,
master_password: 'password',
master: false
}
)
end
it 'creates gitlab-redis-cli-rc' do
expect(chef_run).to render_file('/opt/gitlab/etc/gitlab-redis-cli-rc')
.with_content(gitlab_redis_cli_rc)
end
end
context 'with a replica configured' do
let(:redis_host) { '1.2.3.4' }
let(:redis_port) { 6370 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment