Merge branch 'multi-postgresql-listen-addresses' into 'master'

Use single db_host when multi postgresql::listen_adresses

Fixes #1166

Postgresql allows to listen on multiple adresses: https://www.postgresql.org/docs/9.5/static/runtime-config-connection.html#listen_addresses

ActiveRecord accept one host for a connection (seems legit)

This commit allow user to specify in `['gitlab']['postgresql']['listen_address']` and `['gitlab-ci']['postgresql']['listen_address']` multiple addresses, comma-separated, as accepted by Postgresql.

In parsing time, it take as `db_host` the first ip from the list.

cc @marin 

See merge request !966
This commit is contained in:
Marin Jankovski 2016-09-13 08:37:23 +00:00
commit 717dc269b0
5 changed files with 54 additions and 1 deletions

View File

@ -14,6 +14,7 @@ omnibus-gitlab repository.
- Update the mode of the certificate files when using trusted certificates b00cd4
- Allow configuring Rack Attack endpoints (Dmitry Ivanov) 7aee63
- Bundle jemalloc and allow optional enable 1381ba
- Use single db_host when multi postgresql::listen_adresses
8.11.4

View File

@ -48,8 +48,12 @@ sure that PostgreSQL is set up according to the [database requirements document]
lines.
**Note:**
`/etc/gitlab/gitlab.rb` should have file permissions `0600` because it contains
- `/etc/gitlab/gitlab.rb` should have file permissions `0600` because it contains
plain-text passwords.
- Postgresql allows to listen on multiple adresses. See [Postgresql Connection Config#listen_addresses](https://www.postgresql.org/docs/9.5/static/runtime-config-connection.html#listen_addresses)
If you use multiple addresses in `gitlab_rails['db_host']`, comma-separated, the first address in the list will be used for connection.
1. [Reconfigure GitLab][] for the changes to take effect.

View File

@ -350,6 +350,8 @@ default['gitlab']['postgresql']['sql_user'] = "gitlab"
default['gitlab']['postgresql']['sql_ci_user'] = "gitlab_ci"
default['gitlab']['postgresql']['sql_mattermost_user'] = "gitlab_mattermost"
default['gitlab']['postgresql']['port'] = 5432
# Postgres allow multi listen_address, comma-separated values.
# If used, first address from the list will be use for connection
default['gitlab']['postgresql']['listen_address'] = nil
default['gitlab']['postgresql']['max_connections'] = 200
default['gitlab']['postgresql']['md5_auth_cidr_addresses'] = []

View File

@ -19,6 +19,7 @@ module Postgresql
class << self
def parse_variables
parse_postgresql_settings
parse_multi_db_host_addresses
parse_mattermost_postgresql_settings
end
@ -49,6 +50,22 @@ module Postgresql
end
end
def parse_multi_db_host_addresses
# Postgres allow multiple listen addresses, comma-separated values
# In case of multi listen_address, will use the first address from list
db_host = Gitlab['gitlab_rails']['db_host']
return if db_host.nil?
if db_host.include?(',')
Gitlab['gitlab_rails']['db_host'] = db_host.split(',')[0]
warning = [
"Received gitlab_rails['db_host'] value was: #{db_host.to_json}.",
"First listen_address '#{Gitlab['gitlab_rails']['db_host']}' will be used."
].join("\n ")
warn(warning)
end
end
def parse_mattermost_postgresql_settings
value_from_gitlab_rb = Gitlab['mattermost']['sql_data_source']

View File

@ -11,6 +11,35 @@ describe 'gitlab::gitlab-rails' do
allow(Kernel).to receive(:load).with(%r{gitlab/libraries/storage_directory_helper}).and_return(true)
end
context 'when multiple postgresql listen_address is used' do
before do
stub_gitlab_rb(postgresql: { listen_address: "127.0.0.1,1.1.1.1" })
end
it 'creates the postgres configuration file with multi listen_address and database.yml file with one host' do
expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/database.yml').with_content(/host: '127.0.0.1'/)
expect(chef_run).to render_file('/var/opt/gitlab/postgresql/data/postgresql.conf').with_content(/listen_addresses = '127.0.0.1,1.1.1.1'/)
end
end
context 'when no postgresql listen_address is used' do
it 'creates the postgres configuration file with empty listen_address and database.yml file with default one' do
expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/database.yml').with_content(/host: '\/var\/opt\/gitlab\/postgresql'/)
expect(chef_run).to render_file('/var/opt/gitlab/postgresql/data/postgresql.conf').with_content(/listen_addresses = ''/)
end
end
context 'when one postgresql listen_address is used' do
before do
stub_gitlab_rb(postgresql: { listen_address: "127.0.0.1" })
end
it 'creates the postgres configuration file with one listen_address and database.yml file with one host' do
expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/database.yml').with_content(/host: '127.0.0.1'/)
expect(chef_run).to render_file('/var/opt/gitlab/postgresql/data/postgresql.conf').with_content(/listen_addresses = '127.0.0.1'/)
end
end
context 'when manage-storage-directories is disabled' do
before do
stub_gitlab_rb(gitlab_rails: { shared_path: '/tmp/shared' }, manage_storage_directories: { enable: false })