diff --git a/files/gitlab-cookbooks/gitlab-ee/attributes/default.rb b/files/gitlab-cookbooks/gitlab-ee/attributes/default.rb index 5b1062b65825a78ba1a51fc1e072525c89161769_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItZWUvYXR0cmlidXRlcy9kZWZhdWx0LnJi..3c5631b95c3edf44484def3cf2d62d73da82fa42_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItZWUvYXR0cmlidXRlcy9kZWZhdWx0LnJi 100644 --- a/files/gitlab-cookbooks/gitlab-ee/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab-ee/attributes/default.rb @@ -55,7 +55,6 @@ default['gitlab']['geo-secondary']['db_sslcompression'] = 0 default['gitlab']['geo-secondary']['db_sslrootcert'] = nil default['gitlab']['geo-secondary']['db_sslca'] = nil -default['gitlab']['geo-secondary']['db_fdw'] = nil ### # Geo: PostgreSQL (Tracking database) @@ -73,11 +72,6 @@ default['gitlab']['geo-postgresql']['sql_user'] = 'gitlab_geo' default['gitlab']['geo-postgresql']['sql_mattermost_user'] = nil default['gitlab']['geo-postgresql']['port'] = 5431 -# PostgreSQL Foreign Data Wrapper (FDW) -# The following is needed to make FDW work with pgbouncer. You need -# a separate login for the FDW connection to prevent schema path issues. -default['gitlab']['geo-postgresql']['fdw_external_user'] = default['gitlab']['gitlab-rails']['db_username'] -default['gitlab']['geo-postgresql']['fdw_external_password'] = default['gitlab']['gitlab-rails']['db_password'] # Mininum of 1/8 of total memory and Maximum of 1024MB as sane defaults default['gitlab']['geo-postgresql']['shared_buffers'] = "#{[(node['memory']['total'].to_i / 8) / 1024, 1024].max}MB" diff --git a/files/gitlab-cookbooks/gitlab-ee/libraries/fdw_helper.rb b/files/gitlab-cookbooks/gitlab-ee/libraries/fdw_helper.rb deleted file mode 100644 index 5b1062b65825a78ba1a51fc1e072525c89161769_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItZWUvbGlicmFyaWVzL2Zkd19oZWxwZXIucmI=..0000000000000000000000000000000000000000 --- a/files/gitlab-cookbooks/gitlab-ee/libraries/fdw_helper.rb +++ /dev/null @@ -1,34 +0,0 @@ -class FdwHelper - FOREIGN_SCHEMA = 'gitlab_secondary'.freeze - DEFAULT_SCHEMA = 'public'.freeze - - attr_reader :node - - def initialize(node) - @node = node - end - - def fdw_enabled? - node['gitlab']['geo-secondary']['db_fdw'] - end - - def fdw_dbname - node['gitlab']['gitlab-rails']['db_database'] - end - - def fdw_user - node['gitlab']['geo-postgresql']['fdw_external_user'] - end - - def fdw_password - node['gitlab']['geo-postgresql']['fdw_external_password'] - end - - def fdw_host - node['gitlab']['gitlab-rails']['db_host'] - end - - def fdw_port - node['gitlab']['gitlab-rails']['db_port'] - end -end diff --git a/files/gitlab-cookbooks/gitlab-ee/recipes/geo-postgresql.rb b/files/gitlab-cookbooks/gitlab-ee/recipes/geo-postgresql.rb index 5b1062b65825a78ba1a51fc1e072525c89161769_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItZWUvcmVjaXBlcy9nZW8tcG9zdGdyZXNxbC5yYg==..3c5631b95c3edf44484def3cf2d62d73da82fa42_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItZWUvcmVjaXBlcy9nZW8tcG9zdGdyZXNxbC5yYg== 100644 --- a/files/gitlab-cookbooks/gitlab-ee/recipes/geo-postgresql.rb +++ b/files/gitlab-cookbooks/gitlab-ee/recipes/geo-postgresql.rb @@ -26,7 +26,6 @@ postgresql_username = account_helper.postgresql_user geo_pg_helper = GeoPgHelper.new(node) -fdw_helper = FdwHelper.new(node) directory node['gitlab']['geo-postgresql']['dir'] do owner postgresql_username @@ -147,15 +146,6 @@ action :enable end - postgresql_fdw 'gitlab_secondary' do - db_name geo_database_name - external_host fdw_helper.fdw_host - external_port fdw_helper.fdw_port - external_name fdw_helper.fdw_dbname - helper geo_pg_helper - action :delete - end - ruby_block 'warn pending geo-postgresql restart' do block do message = <<~MESSAGE diff --git a/files/gitlab-cookbooks/gitlab-ee/resources/postgresql_fdw.rb b/files/gitlab-cookbooks/gitlab-ee/resources/postgresql_fdw.rb deleted file mode 100644 index 5b1062b65825a78ba1a51fc1e072525c89161769_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItZWUvcmVzb3VyY2VzL3Bvc3RncmVzcWxfZmR3LnJi..0000000000000000000000000000000000000000 --- a/files/gitlab-cookbooks/gitlab-ee/resources/postgresql_fdw.rb +++ /dev/null @@ -1,30 +0,0 @@ -resource_name :postgresql_fdw -provides :postgresql_fdw - -property :server_name, String, name_property: true -property :db_name, String -property :external_host, String -property :external_port, Integer -property :external_name, String -property :helper, default: lazy { PgHelper.new(node) } - -action :delete do - postgresql_query "drop fdw #{new_resource.server_name} on #{new_resource.db_name}" do - query "DROP SERVER #{new_resource.server_name} CASCADE;" - db_name new_resource.db_name - helper new_resource.helper - - not_if { new_resource.helper.is_offline_or_readonly? || !new_resource.helper.fdw_server_exists?(new_resource.server_name, new_resource.db_name) } - end - - postgresql_query "drop postgres_fdw extension on #{new_resource.db_name}" do - query "DROP EXTENSION IF EXISTS postgres_fdw;" - db_name new_resource.db_name - helper new_resource.helper - - not_if do - new_resource.helper.is_offline_or_readonly? || - !new_resource.helper.extension_enabled?('postgres_fdw', new_resource.db_name) - end - end -end diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb index 5b1062b65825a78ba1a51fc1e072525c89161769_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvYXR0cmlidXRlcy9kZWZhdWx0LnJi..3c5631b95c3edf44484def3cf2d62d73da82fa42_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvYXR0cmlidXRlcy9kZWZhdWx0LnJi 100644 --- a/files/gitlab-cookbooks/gitlab/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb @@ -420,7 +420,6 @@ default['gitlab']['gitlab-rails']['db_prepared_statements'] = false default['gitlab']['gitlab-rails']['db_statements_limit'] = 1000 default['gitlab']['gitlab-rails']['db_statement_timeout'] = nil -default['gitlab']['gitlab-rails']['db_fdw'] = nil default['gitlab']['gitlab-rails']['db_connect_timeout'] = nil default['gitlab']['gitlab-rails']['db_keepalives'] = nil default['gitlab']['gitlab-rails']['db_keepalives_idle'] = nil diff --git a/files/gitlab-cookbooks/gitlab/libraries/helpers/base_pg_helper.rb b/files/gitlab-cookbooks/gitlab/libraries/helpers/base_pg_helper.rb index 5b1062b65825a78ba1a51fc1e072525c89161769_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2hlbHBlcnMvYmFzZV9wZ19oZWxwZXIucmI=..3c5631b95c3edf44484def3cf2d62d73da82fa42_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2hlbHBlcnMvYmFzZV9wZ19oZWxwZXIucmI= 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/helpers/base_pg_helper.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/helpers/base_pg_helper.rb @@ -138,12 +138,6 @@ psql_query(db_name, sql) end - def fdw_server_exists?(server_name, db_name) - psql_cmd(["-d '#{db_name}'", - "-c 'select srvname from pg_foreign_server' -tA", - "| grep -x #{server_name}"]) - end - def user_hashed_password(db_user) db_user_safe = db_user.scan(/[a-z_][a-z0-9_-]*[$]?/).first psql_query('template1', "SELECT passwd FROM pg_shadow WHERE usename='#{db_user_safe}'") diff --git a/spec/chef/gitlab-ee/recipes/geo-postgresql_spec.rb b/spec/chef/gitlab-ee/recipes/geo-postgresql_spec.rb index 5b1062b65825a78ba1a51fc1e072525c89161769_c3BlYy9jaGVmL2dpdGxhYi1lZS9yZWNpcGVzL2dlby1wb3N0Z3Jlc3FsX3NwZWMucmI=..3c5631b95c3edf44484def3cf2d62d73da82fa42_c3BlYy9jaGVmL2dpdGxhYi1lZS9yZWNpcGVzL2dlby1wb3N0Z3Jlc3FsX3NwZWMucmI= 100644 --- a/spec/chef/gitlab-ee/recipes/geo-postgresql_spec.rb +++ b/spec/chef/gitlab-ee/recipes/geo-postgresql_spec.rb @@ -494,112 +494,4 @@ .with_content('host foo bar 127.0.0.1/32 trust') end end - - context 'FDW is disabled' do - cached(:chef_run) do - RSpec::Mocks.with_temporary_scope do - stub_gitlab_rb( - geo_postgresql: { - enable: true, - sql_user: 'mygeodbuser' - }, - geo_secondary: { - db_database: 'gitlab_geodb', - db_fdw: false - }, - gitlab_rails: { - db_host: '10.0.0.1', - db_port: 5430, - db_username: 'mydbuser', - db_database: 'gitlab_myorg', - db_password: 'custompass' - } - ) - end - - allow_any_instance_of(PgHelper).to receive(:is_running?).and_return(true) - allow_any_instance_of(GeoPgHelper).to receive(:is_running?).and_return(true) - ChefSpec::SoloRunner.new(step_into: %w(runit_service)).converge('gitlab-ee::default') - end - - it 'deletes the postgresql fdw server in the geo-postgresql database' do - expect(chef_run).to delete_postgresql_fdw('gitlab_secondary') - end - end - - context 'FDW is enabled' do - cached(:chef_run) do - RSpec::Mocks.with_temporary_scope do - stub_gitlab_rb( - geo_postgresql: { - enable: true, - sql_user: 'mygeodbuser' - }, - geo_secondary: { - db_database: 'gitlab_geodb', - db_fdw: true - }, - gitlab_rails: { - db_host: '10.0.0.1', - db_port: 5430, - db_username: 'mydbuser', - db_database: 'gitlab_myorg', - db_password: 'custompass' - } - ) - end - - allow_any_instance_of(PgHelper).to receive(:is_running?).and_return(true) - allow_any_instance_of(GeoPgHelper).to receive(:is_running?).and_return(true) - ChefSpec::SoloRunner.new(step_into: %w(runit_service)).converge('gitlab-ee::default') - end - - it 'deletes the postgresql fdw server in the geo-postgresql database' do - params = { - db_name: 'gitlab_geodb', - external_host: '10.0.0.1', - external_port: 5430, - external_name: 'gitlab_myorg' - } - - expect(chef_run).to delete_postgresql_fdw('gitlab_secondary').with(params) - end - - context 'when secondary database is not managed' do - before do - stub_gitlab_rb( - geo_postgresql: { - enable: true, - sql_user: 'mygeodbuser' - }, - geo_secondary: { - db_database: 'gitlab_geodb', - db_fdw: true - }, - gitlab_rails: { - db_host: '10.0.0.10', - db_port: 5430, - db_username: 'mydbuser', - db_database: 'gitlab_myorg', - db_password: 'custompass' - } - ) - end - - let(:chef_run) do - allow_any_instance_of(GeoPgHelper).to receive(:is_offline_or_readonly?).and_return(false) - allow_any_instance_of(GeoPgHelper).to receive(:schema_exists?).and_return(true) - allow_any_instance_of(GitlabGeoHelper).to receive(:geo_database_configured?).and_return(true) - - # not managed (using external database) - allow_any_instance_of(PgHelper).to receive(:is_managed_and_offline?).and_return(false) - - ChefSpec::SoloRunner.new(step_into: %w(runit_service)).converge('gitlab-ee::default') - end - - it 'deletes the postgresql fdw server in the geo-postgresql database' do - expect(chef_run).to delete_postgresql_fdw('gitlab_secondary') - end - end - end end