Skip to content

Commit 42829cd

Browse files
authored
Allow more fine-grained control over yum repo config. Fixes #716. (#784)
* Allow more fine-grained control over yum repo config. Fixes #716. Signed-off-by: David Schlenk <[email protected]> * defaults and include `setup_pgdg_*` properties --------- Signed-off-by: David Schlenk <[email protected]>
1 parent 4823137 commit 42829cd

File tree

12 files changed

+293
-24
lines changed

12 files changed

+293
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This file is used to list changes made in the last 3 major versions of the postg
55
## Unreleased
66

77
- Cast `server_config` keys to strings in `postgresql_config` to avoid unnecessary converges
8+
- Add `setup_pgdg_*` properties to `postgresql_install` to allow more fine grained control over derived `yum_repository` resources
89

910
## 12.0.3 - *2024-12-30*
1011

documentation/postgresql_install.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,30 @@
1717

1818
## Properties
1919

20-
| Name | Name? | Type | Default | Description | Allowed Values |
21-
| ---------------------------------- | ----- | --------------- | ------- | ------------------------------------------------ | -------------- |
22-
| `sensitive` | | true, false | | | |
23-
| `version` | | String, Integer | | Version to install | |
24-
| `source` | | String, Symbol | | Installation source | repo, os |
25-
| `client_packages` | | String, Array | | Client packages to install | |
26-
| `server_packages` | | String, Array | | Server packages to install | |
27-
| `repo_pgdg` | | true, false | | Create pgdg repo | |
28-
| `repo_pgdg_common` | | true, false | | Create pgdg-common repo | |
29-
| `repo_pgdg_source` | | true, false | | Create pgdg-source repo | |
30-
| `repo_pgdg_updates_testing` | | true, false | | Create pgdg-updates-testing repo | |
31-
| `repo_pgdg_source_updates_testing` | | true, false | | Create pgdg-source-updates-testing repo | |
32-
| `yum_gpg_key_uri` | | String | | YUM/DNF GPG key URL | |
33-
| `apt_repository_uri` | | String | | apt repository URL | |
34-
| `apt_gpg_key_uri` | | String | | apt GPG key URL | |
35-
| `initdb_additional_options` | | String | | Additional options to pass to the initdb command | |
36-
| `initdb_locale` | | String | | Locale to use for the initdb command | |
37-
| `initdb_encoding` | | String | | Encoding to use for the initdb command | |
38-
| `initdb_user` | | String | | User to run the initdb command as | |
20+
| Name | Name? | Type | Default | Description | Allowed Values |
21+
| ---------------------------------- | ----- | --------------- | ----------------- | ------------------------------------------------ | -------------- |
22+
| `sensitive` | | true, false | `true` | | |
23+
| `version` | | String, Integer | `'17'` | Version to install | |
24+
| `source` | | String, Symbol | `:repo` | Installation source | repo, os |
25+
| `client_packages` | | String, Array | platform specific | Client packages to install | |
26+
| `server_packages` | | String, Array | platform specific | Server packages to install | |
27+
| `repo_pgdg` | | true, false | `true` | Create pgdg repo | |
28+
| `setup_repo_pgdg` | | true, false | value of previous | Whether or not to manage the pgdg repo | |
29+
| `repo_pgdg_common` | | true, false | `true` | Create pgdg-common repo | |
30+
| `setup_repo_pgdg_common` | | true, false | value of previous | Whether or not to manage the pgdg_common repo | |
31+
| `repo_pgdg_source` | | true, false | `false` | Create pgdg-source repo | |
32+
| `setup_repo_pgdg_source` | | true, false | value of previous | Whether or not to manage the pgdg_source repo | |
33+
| `repo_pgdg_updates_testing` | | true, false | `false` | Create pgdg-updates-testing repo | |
34+
| `setup_repo_pgdg_updates_testing` | | true, false | value of previous | Whether or not to manage the pgdg_updates_testing repo | |
35+
| `repo_pgdg_source_updates_testing` | | true, false | `false` | Create pgdg-source-updates-testing repo | |
36+
| `setup_repo_pgdg_source_updates_testing` | | true, false | value of previous | Whether or not to manage the pgdg_source_updates_testing repo | |
37+
| `yum_gpg_key_uri` | | String | platform specific | YUM/DNF GPG key URL | |
38+
| `apt_repository_uri` | | String | https://download.postgresql.org/pub/repos/apt/ | apt repository URL | |
39+
| `apt_gpg_key_uri` | | String | https://download.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt GPG key URL | |
40+
| `initdb_additional_options` | | String | | Additional options to pass to the initdb command | |
41+
| `initdb_locale` | | String | | Locale to use for the initdb command | |
42+
| `initdb_encoding` | | String | | Encoding to use for the initdb command | |
43+
| `initdb_user` | | String | `'postgres'` | User to run the initdb command as | |
3944

4045
## Libraries
4146

kitchen.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,25 @@ suites:
246246
pg_ver: "15"
247247
run_list:
248248
- recipe[test::server_install]
249+
- name: all_repos_install_15
250+
attributes:
251+
test:
252+
pg_ver: "15"
253+
verifier:
254+
inspec_tests:
255+
- path: test/integration/all_repos_install/
256+
inputs:
257+
pg_ver: "15"
258+
run_list:
259+
- recipe[test::all_repos_install]
260+
- name: no_repos_install_15
261+
attributes:
262+
test:
263+
pg_ver: "15"
264+
verifier:
265+
inspec_tests:
266+
- path: test/integration/no_repos_install/
267+
inputs:
268+
pg_ver: "15"
269+
run_list:
270+
- recipe[test::no_repos_install]

resources/install.rb

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,43 @@
4545

4646
property :repo_pgdg, [true, false],
4747
default: true,
48-
description: 'Create pgdg repo'
48+
description: 'Enable pgdg repo'
49+
50+
property :setup_repo_pgdg, [true, false],
51+
default: lazy { |r| r.repo_pgdg },
52+
description: 'Setup pgdg repo. Defaults to value of `:repo_pgdg`.'
4953

5054
property :repo_pgdg_common, [true, false],
5155
default: true,
52-
description: 'Create pgdg-common repo'
56+
description: 'Enable pgdg-common repo'
57+
58+
property :setup_repo_pgdg_common, [true, false],
59+
default: lazy { |r| r.repo_pgdg_common },
60+
description: 'Setup pgdg-common repo. Defaults to value of `:repo_pgdg_common`.'
5361

5462
property :repo_pgdg_source, [true, false],
5563
default: false,
56-
description: 'Create pgdg-source repo'
64+
description: 'Enable pgdg-source repo'
65+
66+
property :setup_repo_pgdg_source, [true, false],
67+
default: lazy { |r| r.repo_pgdg_source },
68+
description: 'Setup pgdg-source repo. Defaults to value of `:repo_pgdg_source`.'
5769

5870
property :repo_pgdg_updates_testing, [true, false],
5971
default: false,
60-
description: 'Create pgdg-updates-testing repo'
72+
description: 'Enable pgdg-updates-testing repo'
73+
74+
property :setup_repo_pgdg_updates_testing, [true, false],
75+
default: lazy { |r| r.repo_pgdg_updates_testing },
76+
description: 'Setup pgdg-updates-testing repo. Defaults to value of `:repo_pgdg_updates_testing`.'
6177

6278
property :repo_pgdg_source_updates_testing, [true, false],
6379
default: false,
64-
description: 'Create pgdg-source-updates-testing repo'
80+
description: 'Enable pgdg-source-updates-testing repo'
81+
82+
property :setup_repo_pgdg_source_updates_testing, [true, false],
83+
default: lazy { |r| r.repo_pgdg_source_updates_testing },
84+
description: 'Setup pgdg-source-updates-testing repo. Defaults to value of `:repo_pgdg_source_updates_testing`.'
6585

6686
property :yum_gpg_key_uri, String,
6787
default: lazy { default_yum_gpg_key_uri },
@@ -116,6 +136,7 @@ def do_repository_action(repo_action)
116136
gpgcheck true
117137
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
118138
action repo_action
139+
only_if { new_resource.repo_pgdg || new_resource.setup_repo_pgdg }
119140
end
120141

121142
yum_repository 'PostgreSQL - common' do
@@ -126,6 +147,7 @@ def do_repository_action(repo_action)
126147
gpgcheck true
127148
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
128149
action repo_action
150+
only_if { new_resource.repo_pgdg_common || new_resource.setup_repo_pgdg_common }
129151
end
130152

131153
yum_repository "PostgreSQL #{new_resource.version} - source " do
@@ -137,6 +159,7 @@ def do_repository_action(repo_action)
137159
gpgcheck true
138160
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
139161
action repo_action
162+
only_if { new_resource.repo_pgdg_source || new_resource.setup_repo_pgdg_source }
140163
end
141164

142165
yum_repository "PostgreSQL #{new_resource.version} - updates testing" do
@@ -148,6 +171,7 @@ def do_repository_action(repo_action)
148171
gpgcheck true
149172
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
150173
action repo_action
174+
only_if { new_resource.repo_pgdg_updates_testing || new_resource.setup_repo_pgdg_updates_testing }
151175
end
152176

153177
yum_repository "PostgreSQL #{new_resource.version} - source - updates testing" do
@@ -159,6 +183,7 @@ def do_repository_action(repo_action)
159183
gpgcheck true
160184
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
161185
action repo_action
186+
only_if { new_resource.repo_pgdg_source_updates_testing || new_resource.setup_repo_pgdg_source_updates_testing }
162187
end
163188

164189
when 'debian'
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
postgresql_install 'postgresql' do
2+
version node['test']['pg_ver']
3+
setup_repo_pgdg_source true
4+
setup_repo_pgdg_updates_testing true
5+
setup_repo_pgdg_source_updates_testing true
6+
action %i(install init_server)
7+
end
8+
9+
postgresql_config 'postgresql-server' do
10+
version '15'
11+
12+
server_config({
13+
'max_connections' => 110,
14+
'shared_buffers' => '128MB',
15+
'dynamic_shared_memory_type' => 'posix',
16+
'max_wal_size' => '1GB',
17+
'min_wal_size' => '80MB',
18+
'log_destination' => 'stderr',
19+
'logging_collector' => true,
20+
'log_directory' => 'log',
21+
'log_filename' => 'postgresql-%a.log',
22+
'log_rotation_age' => '1d',
23+
'log_rotation_size' => 0,
24+
'log_truncate_on_rotation' => true,
25+
'log_line_prefix' => '%m [%p]',
26+
'log_timezone' => 'Etc/UTC',
27+
'datestyle' => 'iso, mdy',
28+
'timezone' => 'Etc/UTC',
29+
'lc_messages' => 'C',
30+
'lc_monetary' => 'C',
31+
'lc_numeric' => 'C',
32+
'lc_time' => 'C',
33+
'default_text_search_config' => 'pg_catalog.english',
34+
})
35+
36+
notifies :restart, 'postgresql_service[postgresql]', :delayed
37+
action :create
38+
end
39+
40+
postgresql_service 'postgresql' do
41+
action %i(enable start)
42+
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# I can do it myself!
2+
yum_repository 'postgresql-15' do
3+
baseurl 'https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-$releasever-$basearch'
4+
gpgkey "https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL#{node['platform_version'].to_i.eql?(7) ? '7' : ''}"
5+
end
6+
7+
yum_repository 'postgresql-common' do
8+
baseurl 'https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-$releasever-$basearch'
9+
gpgkey "https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL#{node['platform_version'].to_i.eql?(7) ? '7' : ''}"
10+
end
11+
12+
postgresql_install 'postgresql' do
13+
version node['test']['pg_ver']
14+
repo_pgdg false
15+
repo_pgdg_common false
16+
action %i(install init_server)
17+
end
18+
19+
postgresql_config 'postgresql-server' do
20+
version '15'
21+
22+
server_config({
23+
'max_connections' => 110,
24+
'shared_buffers' => '128MB',
25+
'dynamic_shared_memory_type' => 'posix',
26+
'max_wal_size' => '1GB',
27+
'min_wal_size' => '80MB',
28+
'log_destination' => 'stderr',
29+
'logging_collector' => true,
30+
'log_directory' => 'log',
31+
'log_filename' => 'postgresql-%a.log',
32+
'log_rotation_age' => '1d',
33+
'log_rotation_size' => 0,
34+
'log_truncate_on_rotation' => true,
35+
'log_line_prefix' => '%m [%p]',
36+
'log_timezone' => 'Etc/UTC',
37+
'datestyle' => 'iso, mdy',
38+
'timezone' => 'Etc/UTC',
39+
'lc_messages' => 'C',
40+
'lc_monetary' => 'C',
41+
'lc_numeric' => 'C',
42+
'lc_time' => 'C',
43+
'default_text_search_config' => 'pg_catalog.english',
44+
})
45+
46+
notifies :restart, 'postgresql_service[postgresql]', :delayed
47+
action :create
48+
end
49+
50+
postgresql_service 'postgresql' do
51+
action %i(enable start)
52+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
pg_ver = input('pg_ver')
3+
4+
if os[:family] == 'redhat'
5+
describe service("postgresql-#{pg_ver}") do
6+
it { should be_installed }
7+
it { should be_enabled }
8+
it { should be_running }
9+
end
10+
%W(pgdg#{pg_ver} pgdg-common).each do |r|
11+
describe yum.repo(r) do
12+
it { should exist }
13+
it { should be_enabled }
14+
end
15+
end
16+
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
17+
describe yum.repo(r) do
18+
it { should exist }
19+
it { should_not be_enabled }
20+
end
21+
end
22+
else
23+
describe service('postgresql') do
24+
it { should be_installed }
25+
it { should be_enabled }
26+
it { should be_running }
27+
end
28+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: all_repos_install
3+
title: PostgreSQL server with all repos setup but only pgdg and pgdg-common enabled
4+
maintainer: Sous Chefs
5+
copyright_email: [email protected]
6+
license: Apache
7+
summary: Verify the correct installation of the postgresql server including correct repos setup and enabled
8+
version: 0.0.1
9+
supports:
10+
- os-family: unix
11+
depends:
12+
- name: client
13+
path: ./test/integration/client_install
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
pg_ver = input('pg_ver')
3+
4+
if os[:family] == 'redhat'
5+
describe service("postgresql-#{pg_ver}") do
6+
it { should be_installed }
7+
it { should be_enabled }
8+
it { should be_running }
9+
end
10+
%W(pgdg#{pg_ver} pgdg-common).each do |r|
11+
describe yum.repo(r) do
12+
it { should_not exist }
13+
it { should_not be_enabled }
14+
end
15+
end
16+
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
17+
describe yum.repo(r) do
18+
it { should_not exist }
19+
it { should_not be_enabled }
20+
end
21+
end
22+
else
23+
describe service('postgresql') do
24+
it { should be_installed }
25+
it { should be_enabled }
26+
it { should be_running }
27+
end
28+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: no_repos_install
3+
title: PostgreSQL no_repos_install
4+
maintainer: Sous Chefs
5+
copyright_email: [email protected]
6+
license: Apache
7+
summary: Verify the correct installation of the postgresql server with cookbook provided yum repos instead of resource
8+
version: 0.0.1
9+
supports:
10+
- os-family: unix
11+
depends:
12+
- name: client
13+
path: ./test/integration/client_install
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
pg_ver = input('pg_ver')
3+
4+
if os[:family] == 'redhat'
5+
describe service("postgresql-#{pg_ver}") do
6+
it { should be_installed }
7+
it { should be_enabled }
8+
it { should be_running }
9+
end
10+
%W(pgdg#{pg_ver} pgdg-common).each do |r|
11+
describe yum.repo(r) do
12+
it { should exist }
13+
it { should be_enabled }
14+
end
15+
end
16+
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
17+
describe yum.repo(r) do
18+
it { should exist }
19+
it { should_not be_enabled }
20+
end
21+
end
22+
else
23+
describe service('postgresql') do
24+
it { should be_installed }
25+
it { should be_enabled }
26+
it { should be_running }
27+
end
28+
end

0 commit comments

Comments
 (0)