Skip to content

Commit

Permalink
Update Fedora initdb commands
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Webb <[email protected]>
  • Loading branch information
damacus committed Nov 4, 2024
1 parent 259bc83 commit fb22405
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 64 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
- "amazonlinux-2023"
- "debian-11"
- "debian-12"
- "fedora-latest"
- "ubuntu-2204"
- "ubuntu-2404"
suite:
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ This file is used to list changes made in the last 3 major versions of the postg

## Unreleased

- Remove support for Fedora
Fedora is not an officially supported platform by the Sous Chefs community. If you would like to see Fedora support added back please open a PR to add it back.
The installtion methods for Fedora are substantially different than other platforms and require a lot of additional testing and maintenance.
- Add testing for PostgreSQL 16 and 17
- Add libpq package to default packages
- Fix GPG key URLs
- Update Amazon to Amazonlinux 2023
- Remove unspoorted configuration options from the `postgresql_config` resource
`stats_temp_directory`

## 11.11.2 - *2024-10-07*

Standardise files with files in sous-chefs/repo-management
Expand Down Expand Up @@ -301,7 +311,7 @@ Standardise files with files in sous-chefs/repo-management

- Allow to install extensions with hyphens, ex: `postgresql_extension '"uuid-ossp"'`
- Update Circle CI config to match sous-chefs defaults #617
- Remove Fedora testing from CI, not an official supported OS by sous-chefs, PR welcome #617
- Remove Fedora testing from CI, not an official supported OS by sous-chefs, PRs welcome #617

## v7.1.4 (2019-03-28)

Expand Down
2 changes: 1 addition & 1 deletion documentation/postgresql_ident.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ postgresql_access 'local_foo_user' do
database 'all'
user 'foo'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'
end
```

Expand Down
1 change: 0 additions & 1 deletion kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ platforms:
- name: amazonlinux-2023
- name: debian-11
- name: debian-12
- name: fedora-latest
- name: ubuntu-22.04
- name: ubuntu-24.04

Expand Down
35 changes: 10 additions & 25 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def installed_postgresql_package_source

def data_dir(version: installed_postgresql_major_version, source: installed_postgresql_package_source)
case node['platform_family']
when 'rhel', 'fedora', 'amazon'
when 'rhel', 'amazon'
source.eql?(:repo) ? "/var/lib/pgsql/#{version}/data" : '/var/lib/pgsql/data'
when 'debian'
"/var/lib/postgresql/#{version}/main"
Expand All @@ -76,7 +76,7 @@ def data_dir(version: installed_postgresql_major_version, source: installed_post

def conf_dir(version: installed_postgresql_major_version, source: installed_postgresql_package_source)
case node['platform_family']
when 'rhel', 'fedora', 'amazon'
when 'rhel', 'amazon'
source.eql?(:repo) ? "/var/lib/pgsql/#{version}/data" : '/var/lib/pgsql/data'
when 'debian'
"/etc/postgresql/#{version}/main"
Expand All @@ -85,7 +85,7 @@ def conf_dir(version: installed_postgresql_major_version, source: installed_post

# determine the platform specific service name
def default_platform_service_name(version: installed_postgresql_major_version, source: installed_postgresql_package_source)
if platform_family?('rhel', 'fedora', 'amazon') && source.eql?(:repo)
if platform_family?('rhel', 'amazon') && source.eql?(:repo)
"postgresql-#{version}"
else
'postgresql'
Expand All @@ -110,7 +110,7 @@ def secure_random

def default_server_packages(version: nil, source: :os)
case node['platform_family']
when 'rhel', 'fedora'
when 'rhel'
{
os: %w(libpq postgresql-contrib postgresql-server),
repo: %W(postgresql#{version.delete('.')}-contrib postgresql#{version.delete('.')}-server),
Expand All @@ -130,7 +130,7 @@ def default_server_packages(version: nil, source: :os)

def default_client_packages(version: nil, source: :os)
case node['platform_family']
when 'rhel', 'fedora'
when 'rhel'
{
os: %w(postgresql),
repo: %W(postgresql#{version.delete('.')}),
Expand All @@ -151,18 +151,16 @@ def default_client_packages(version: nil, source: :os)
def default_yum_gpg_key_uri
if platform_family?('rhel') && node['platform_version'].to_i == 7
'https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL7'
elsif platform_family?('fedora')
'https://download.postgresql.org/pub/repos/yum/keys/PGDG-KEY-fedora'
else
'https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL'
end
end

def dnf_module_platform?
(platform_family?('rhel') && node['platform_version'].to_i == 8) || platform_family?('fedora')
(platform_family?('rhel') && node['platform_version'].to_i == 8)
end

# determine the appropriate DB init command to run based on RHEL/Fedora/Amazon release
# determine the appropriate DB init command to run based on RHEL/Amazon release
# initdb defaults to the execution environment.
# https://www.postgresql.org/docs/9.5/static/locale.html
def rhel_init_db_command(new_resource)
Expand All @@ -175,38 +173,25 @@ def rhel_init_db_command(new_resource)

# Given the base URL build the complete URL string for a yum repo
def yum_repo_url(base_url)
"#{base_url}/#{new_resource.version}/#{yum_repo_platform_family_string}/#{yum_repo_platform_string}"
"#{base_url}/#{new_resource.version}/redhat/#{yum_repo_platform_string}"
end

# Given the base URL build the complete URL string for a yum repo
def yum_common_repo_url
"https://download.postgresql.org/pub/repos/yum/common/#{yum_repo_platform_family_string}/#{yum_repo_platform_string}"
end

# The postgresql yum repos URLs are organized into redhat and fedora directories.s
# route things to the right place based on platform_family
def yum_repo_platform_family_string
platform_family?('fedora') ? 'fedora' : 'redhat'
"https://download.postgresql.org/pub/repos/yum/common/redhat/#{yum_repo_platform_string}"
end

# Build the platform string that makes up the final component of the yum repo URL
def yum_repo_platform_string
platform = platform?('fedora') ? 'fedora' : 'rhel'
release = platform?('amazon') ? '8' : '$releasever'
"#{platform}-#{release}-$basearch"
"rhel-#{release}-$basearch"
end

# On Amazon use the RHEL 8 packages. Otherwise use the releasever yum variable
def yum_releasever
platform?('amazon') ? '8' : '$releasever'
end

# Fedora doesn't seem to know the right symbols for psql
def psql_environment
return {} unless platform?('fedora')
{ LD_LIBRARY_PATH: '/usr/lib64' }
end

# Generate a password if the value is set to generate.
def postgres_password(new_resource)
new_resource.password == 'generate' ? secure_random : new_resource.password
Expand Down
8 changes: 3 additions & 5 deletions libraries/sql/_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Connection

def postgresql_devel_pkg_name(version: installed_postgresql_major_version, source: installed_postgresql_package_source)
case node['platform_family']
when 'rhel', 'fedora'
when 'rhel'
source.eql?(:repo) ? "postgresql#{version}-devel" : 'postgresql-devel'
when 'debian'
'libpq-dev'
Expand All @@ -40,7 +40,7 @@ def postgresql_devel_pkg_name(version: installed_postgresql_major_version, sourc

def postgresql_devel_path(suffix = nil, version: installed_postgresql_major_version)
path = case node['platform_family']
when 'rhel', 'fedora', 'amazon'
when 'rhel', 'amazon'
"/usr/pgsql-#{version}"
when 'debian'
'/usr/include/postgresql'
Expand All @@ -55,7 +55,7 @@ def postgresql_devel_path(suffix = nil, version: installed_postgresql_major_vers

def pg_gem_build_options
case node['platform_family']
when 'rhel', 'fedora', 'amazon'
when 'rhel', 'amazon'
"-- --with-pg-include=#{postgresql_devel_path('include')} --with-pg-lib=#{postgresql_devel_path('lib')}"
when 'debian'
"-- --with-pg-include=#{postgresql_devel_path} --with-pg-lib=#{postgresql_devel_path}"
Expand All @@ -75,8 +75,6 @@ def install_pg_gem
end

case node['platform_family']
when 'fedora'
declare_resource(:package, libpq_package_name) { compile_time(true) }
when 'rhel'
case node['platform_version'].to_i
when 7
Expand Down
1 change: 0 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
supports 'amazon'
supports 'centos'
supports 'debian'
supports 'fedora'
supports 'oracle'
supports 'redhat'
supports 'scientific'
Expand Down
5 changes: 3 additions & 2 deletions resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def install_method_repo?

def do_repository_action(repo_action)
case node['platform_family']
when 'rhel', 'fedora', 'amazon'
when 'rhel', 'amazon'
# Disable the PostgreSQL module if we're on RHEL 8
dnf_module 'postgresql' do
action :disable
end if dnf_module_platform?
Expand Down Expand Up @@ -268,7 +269,7 @@ def do_server_package_action(package_action)
end

action :init_server do
return if initialized? || !platform_family?('rhel', 'fedora', 'amazon')
return if initialized? || !platform_family?('rhel', 'amazon')

converge_by('Init PostgreSQL') do
execute 'init_db' do
Expand Down
3 changes: 0 additions & 3 deletions templates/default/createcluster.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ ssl = on
# Show cluster name in process title
cluster_name = '%v/%c'

# Put stats_temp_directory on tmpfs
stats_temp_directory = '/var/run/postgresql/%v-%c.pg_stat_tmp'

# Add prefix to log lines
log_line_prefix = '%%m [%%p] %%q%%u@%%d '

Expand Down
14 changes: 7 additions & 7 deletions test/cookbooks/test/recipes/access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
database 'all'
user 'postgres'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'
end

postgresql_service 'postgresql' do
Expand Down Expand Up @@ -45,7 +45,7 @@
type 'host'
database 'all'
user 'sous_chef'
auth_method 'md5'
auth_method 'scram-sha-256'
address '127.0.0.1/32'
position 5

Expand Down Expand Up @@ -74,7 +74,7 @@
type 'host'
database 'all'
user 'hostname_user'
auth_method 'md5'
auth_method 'scram-sha-256'
address 'host.domain'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand All @@ -84,7 +84,7 @@
type 'host'
database 'all'
user 'hostname.user'
auth_method 'md5'
auth_method 'scram-sha-256'
address 'host.domain'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand All @@ -94,7 +94,7 @@
type 'host'
database 'my_database'
user 'hostname.user'
auth_method 'md5'
auth_method 'scram-sha-256'
address 'host.domain'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand All @@ -104,7 +104,7 @@
type 'host'
database 'my_database'
user 'hostname.user'
auth_method 'md5'
auth_method 'scram-sha-256'
address 'a.very.long.host.domain.that.exceeds.the.max.of.24.characters'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand Down Expand Up @@ -135,5 +135,5 @@
database 'foo,bar'
user 'john,doe'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'
end
2 changes: 1 addition & 1 deletion test/cookbooks/test/recipes/extension.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dokken images don't have all locales available so this is a workaround
locale = value_for_platform(
%i(debian ubuntu fedora oracle amazon almalinux rocky) => { default: 'C.UTF-8' },
%i(debian ubuntu oracle amazon almalinux rocky) => { default: 'C.UTF-8' },
centos: { default: node['platform_version'].to_i < 8 ? 'en_US.utf-8' : 'C.UTF-8' },
default: 'en_US'
)
Expand Down
2 changes: 1 addition & 1 deletion test/cookbooks/test/recipes/ident.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
database 'all'
user 'postgres'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'

notifies :reload, 'postgresql_service[postgresql]', :delayed
end
Expand Down
4 changes: 2 additions & 2 deletions test/cookbooks/test/recipes/multi_client.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postgresql_install '13' do
version '13'
postgresql_install '16' do
version '16'

action :install_client
end
Expand Down
4 changes: 2 additions & 2 deletions test/cookbooks/test/recipes/server_install_os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
database 'all'
user 'postgres'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'
end

postgresql_user 'postgres' do
Expand Down Expand Up @@ -77,7 +77,7 @@
type 'host'
database 'all'
user 'sous_chef'
auth_method 'md5'
auth_method 'scram-sha-256'
address '127.0.0.1/32'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand Down
8 changes: 4 additions & 4 deletions test/integration/access/controls/base_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe postgres_hba_conf.where { type == 'host' && user == 'postgres' } do
its('database') { should cmp 'all' }
its('user') { should cmp 'postgres' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp '127.0.0.1/32' }
end

Expand All @@ -23,7 +23,7 @@
describe postgres_hba_conf.where { user == 'sous_chef' } do
its('database') { should cmp 'all' }
its('type') { should cmp 'host' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp '127.0.0.1/32' }
end

Expand All @@ -41,7 +41,7 @@
describe postgres_hba_conf.where { user == 'hostname_user' } do
its('database') { should cmp 'all' }
its('type') { should cmp 'host' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp 'host.domain' }
end
end
Expand All @@ -53,7 +53,7 @@
describe postgres_hba_conf.where { address == 'a.very.long.host.domain.that.exceeds.the.max.of.24.characters' } do
its('database') { should cmp 'my_database' }
its('type') { should cmp 'host' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp 'a.very.long.host.domain.that.exceeds.the.max.of.24.characters' }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
case os.family
when 'debian'
'/usr/lib/postgresql/'
when 'redhat', 'fedora'
when 'redhat'
'/usr/pgsql-'
end

Expand Down
4 changes: 1 addition & 3 deletions test/integration/repo/controls/repo_spec.rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

case os[:family]

when 'redhat', 'fedora'

when 'redhat'
describe yum.repo("pgdg#{pg_ver}") do
it { should exist }
it { should be_enabled }
Expand All @@ -26,7 +25,6 @@
end

when 'debian'

describe apt('https://download.postgresql.org/pub/repos/apt/') do
it { should exist }
it { should be_enabled }
Expand Down
Loading

0 comments on commit fb22405

Please sign in to comment.