Skip to content

Commit 9b32cfd

Browse files
CopilotdamacusCopilotramereth
authored
fix(RHEL): Add PCRE version detection based on platform version (#521)
* Add PCRE2 support for CentOS Stream 10 and enable it in CI Co-authored-by: damacus <40786+damacus@users.noreply.github.com> * Add validation and improve documentation for PCRE2 support Co-authored-by: damacus <40786+damacus@users.noreply.github.com> * fix: Platform tests Signed-off-by: Dan Webb <dan.webb@damacus.io> * fix: Reverse PCRE version logic per maintainer feedback Changed PCRE2 to be used for RHEL < 10 and PCRE for RHEL >= 10. Updated tests and documentation accordingly. Co-authored-by: damacus <40786+damacus@users.noreply.github.com> * fix: consolidate PCRE detection logic and simplify make command construction - Extract pcre_package_name helper to eliminate duplication - Use consistent platform_family? check across all RHEL derivatives - Simplify make command conditional with pcre_make_flag helper - Fix test for use_pcre false to verify make flags - Add test coverage for Amazon Linux and Fedora - Improve documentation clarity for PCRE platform behavior - Remove unnecessary Rubocop disable comment Signed-off-by: Dan Webb <dan.webb@damacus.io> * Update .windsurf/rules/definition-of-done.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: Fix rspec test for PCRE disabled scenario - Changed stub_command to return false so bash resource runs - Rewrote test to directly check bash_resource.code instead of using .with(code:) matcher - All 14 examples now pass with 0 failures Co-authored-by: ramereth <48997+ramereth@users.noreply.github.com> * Cookstyle fix Signed-off-by: Lance Albertson <lance@osuosl.org> * fix: Revert PCRE logic to use PCRE2 for RHEL >= 10 The maintainer's earlier feedback to reverse the logic was incorrect. CentOS Stream 10 requires pcre2-devel as pcre-devel is not available. Reverted to original logic: RHEL >= 10 uses PCRE2, RHEL < 10 uses PCRE. - Updated helpers.rb: RHEL >= 10 uses pcre2-devel - Updated install.rb comment to match - Fixed unit tests for AlmaLinux 9/10 - Updated test recipe comments - Updated documentation Co-authored-by: ramereth <48997+ramereth@users.noreply.github.com> --------- Signed-off-by: Dan Webb <dan.webb@damacus.io> Signed-off-by: Lance Albertson <lance@osuosl.org> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: damacus <40786+damacus@users.noreply.github.com> Co-authored-by: Dan Webb <dan.webb@damacus.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: ramereth <48997+ramereth@users.noreply.github.com> Co-authored-by: Lance Albertson <lance@osuosl.org>
1 parent 9b541fb commit 9b32cfd

File tree

9 files changed

+147
-9
lines changed

9 files changed

+147
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
- "ubuntu-2004"
2828
- "ubuntu-2204"
2929
- "centos-stream-9"
30-
# - "centos-stream-10" No candidate version available for pcre-devel
31-
# - "fedora-latest"
30+
- "centos-stream-10"
31+
- "fedora-latest"
3232
suite:
3333
- config-2
3434
# - config-3

.markdownlint-cli2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ config:
77
maximum: 2
88
ignores:
99
- .github/copilot-instructions.md
10+
- .windsurf/**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
trigger: model_decision
3+
description: When completing a task check the following are true
4+
---
5+
6+
- `cookstyle` does not return any syntax or style errors
7+
- markdownlint-cli2 "**/*.md" "!vendor" "!.venv" --fix
8+
- yamllint
9+
- `kitchen test` does not return any errors
10+
- run all suites
11+
- do not skip suites
12+
This gives us knowledge that we have not broken areas of the cookbook we are not currently changing (regression)
13+
No matter what we have done, even if you think it is outside our control, kitchen test must pass

documentation/haproxy_install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This resource also uses the following partial resources:
3636
| `source_target_arch` | String | | | |
3737
| `source_target_os` | String | See resource | | |
3838
| `use_libcrypt` | Boolean | `true` | | `true`, `false` |
39-
| `use_pcre` | Boolean | `true` | | `true`, `false` |
39+
| `use_pcre` | Boolean | `true` | Enable PCRE regex support. Automatically selects PCRE2 for RHEL/CentOS/AlmaLinux/Rocky >= 10, PCRE for < 10, Amazon Linux, and Fedora. | `true`, `false` |
4040
| `use_openssl` | Boolean | `true` | Include openssl support (<https://openssl.org>) | `true`, `false` |
4141
| `use_zlib` | Boolean | `true` | Include ZLIB support | `true`, `false` |
4242
| `use_linux_tproxy` | Boolean | `true` | | `true`, `false` |

libraries/helpers.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ def haproxy_version
66
v.run_command.stdout.to_f
77
end
88

9+
def pcre_package_name
10+
# Use PCRE2 for RHEL/CentOS/AlmaLinux/Rocky >= 10 where PCRE1 is deprecated
11+
# Use PCRE for RHEL < 10, Amazon Linux, Fedora, and other platforms
12+
if platform_family?('rhel') && platform_version.to_i >= 10
13+
'pcre2-devel'
14+
else
15+
'pcre-devel'
16+
end
17+
end
18+
919
def source_package_list
1020
case node['platform_family']
1121
when 'debian'
1222
%w(libpcre3-dev libssl-dev zlib1g-dev libsystemd-dev)
1323
when 'rhel', 'amazon', 'fedora'
14-
%w(pcre-devel openssl-devel zlib-devel systemd-devel tar)
24+
[pcre_package_name, 'openssl-devel', 'zlib-devel', 'systemd-devel', 'tar']
1525
when 'suse'
1626
%w(pcre-devel libopenssl-devel zlib-devel systemd-devel)
1727
end

mise.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# .mise.toml
2+
3+
[env]
4+
PATH = "/opt/chef-workstation/bin:/opt/chef-workstation/embedded/bin:{{env.PATH}}"
5+
KITCHEN_LOCAL_YAML = "kitchen.dokken.yml"

resources/install.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
default: true
5252

5353
property :use_pcre, [true, false],
54-
default: true
54+
default: true,
55+
description: 'Enable PCRE support (automatically selects PCRE or PCRE2 based on platform)'
5556

5657
property :use_promex, [true, false],
5758
default: false
@@ -96,6 +97,11 @@
9697
def compile_make_boolean(bool)
9798
bool ? '1' : '0'
9899
end
100+
101+
def pcre_make_flag
102+
# Use PCRE2 for RHEL/CentOS/AlmaLinux/Rocky >= 10, PCRE for < 10 and other platforms
103+
pcre_package_name.include?('pcre2') ? 'USE_PCRE2' : 'USE_PCRE'
104+
end
99105
end
100106

101107
action :install do
@@ -146,7 +152,7 @@ def compile_make_boolean(bool)
146152
make_cmd << " CPU=#{new_resource.source_target_cpu}" if property_is_set?(:source_target_cpu)
147153
make_cmd << " ARCH=#{new_resource.source_target_arch}" if property_is_set?(:source_target_arch)
148154
make_cmd << " USE_LIBCRYPT=#{compile_make_boolean(new_resource.use_libcrypt)}"
149-
make_cmd << " USE_PCRE=#{compile_make_boolean(new_resource.use_pcre)}"
155+
make_cmd << " #{pcre_make_flag}=1" if new_resource.use_pcre
150156
make_cmd << " USE_OPENSSL=#{compile_make_boolean(new_resource.use_openssl)}"
151157
make_cmd << " USE_ZLIB=#{compile_make_boolean(new_resource.use_zlib)}"
152158
make_cmd << " USE_LINUX_TPROXY=#{compile_make_boolean(new_resource.use_linux_tproxy)}"
@@ -178,8 +184,7 @@ def compile_make_boolean(bool)
178184
home "/home/#{new_resource.user}"
179185
group new_resource.group
180186
expire_date '2050-12-31' if Chef::VERSION.to_f >= 18.0
181-
# rubocop:disable Lint/AmbiguousOperator
182-
inactive -1 if Chef::VERSION.to_f >= 18.0
187+
inactive(-1) if Chef::VERSION.to_f >= 18.0
183188
end
184189
end
185190
end

spec/unit/recipes/install_spec.rb

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
it { is_expected.to install_package('haproxy') }
1313
end
1414

15-
context 'compile HAProxy' do
15+
context 'compile HAProxy on Ubuntu' do
1616
recipe do
1717
haproxy_install 'source' do
1818
use_libcrypt true
@@ -30,4 +30,86 @@
3030
it { is_expected.to install_package(%w(libpcre3-dev libssl-dev zlib1g-dev libsystemd-dev)) }
3131
it { is_expected.not_to install_package('pcre-devel') }
3232
end
33+
34+
context 'compile HAProxy on AlmaLinux 9' do
35+
platform 'almalinux', '9'
36+
37+
recipe do
38+
haproxy_install 'source'
39+
end
40+
before(:each) do
41+
stub_command('/usr/sbin/haproxy -v | grep 2.8.5').and_return('2.8.5')
42+
end
43+
44+
it { is_expected.to install_package(%w(pcre-devel openssl-devel zlib-devel systemd-devel tar)) }
45+
it { is_expected.not_to install_package('pcre2-devel') }
46+
end
47+
48+
context 'compile HAProxy on AlmaLinux 10 (uses PCRE2)' do
49+
platform 'almalinux', '10'
50+
51+
recipe do
52+
haproxy_install 'source'
53+
end
54+
before(:each) do
55+
stub_command('/usr/sbin/haproxy -v | grep 2.8.5').and_return('2.8.5')
56+
end
57+
58+
it { is_expected.to install_package(%w(pcre2-devel openssl-devel zlib-devel systemd-devel tar)) }
59+
it { is_expected.not_to install_package('pcre-devel') }
60+
end
61+
62+
context 'compile HAProxy on Amazon Linux (uses PCRE)' do
63+
platform 'amazon', '2023'
64+
65+
recipe do
66+
haproxy_install 'source'
67+
end
68+
before(:each) do
69+
stub_command('/usr/sbin/haproxy -v | grep 2.8.5').and_return('2.8.5')
70+
end
71+
72+
it { is_expected.to install_package(%w(pcre-devel openssl-devel zlib-devel systemd-devel tar)) }
73+
it { is_expected.not_to install_package('pcre2-devel') }
74+
end
75+
76+
context 'compile HAProxy on Fedora (uses PCRE)' do
77+
platform 'fedora', '32'
78+
79+
recipe do
80+
haproxy_install 'source'
81+
end
82+
before(:each) do
83+
stub_command('/usr/sbin/haproxy -v | grep 2.8.5').and_return('2.8.5')
84+
end
85+
86+
it { is_expected.to install_package(%w(pcre-devel openssl-devel zlib-devel systemd-devel tar)) }
87+
it { is_expected.not_to install_package('pcre2-devel') }
88+
end
89+
90+
context 'compile HAProxy with PCRE disabled' do
91+
platform 'almalinux', '9'
92+
93+
recipe do
94+
haproxy_install 'source' do
95+
use_pcre false
96+
end
97+
end
98+
before(:each) do
99+
stub_command('/usr/sbin/haproxy -v | grep 2.8.5').and_return(false)
100+
end
101+
102+
# When PCRE is disabled, we still install the package (for dependencies)
103+
# but the make command should not include USE_PCRE or USE_PCRE2 flags
104+
it { is_expected.to install_package(%w(pcre-devel openssl-devel zlib-devel systemd-devel tar)) }
105+
it { is_expected.to run_bash('compile_haproxy') }
106+
107+
it 'does not include PCRE flags in make command' do
108+
bash_resource = chef_run.bash('compile_haproxy')
109+
expect(bash_resource.code).to match(/make TARGET=linux-glibc/)
110+
expect(bash_resource.code).to match(/USE_OPENSSL=1/)
111+
expect(bash_resource.code).not_to match(/USE_PCRE2/)
112+
expect(bash_resource.code).not_to match(/USE_PCRE=/)
113+
end
114+
end
33115
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version = '2.8.5'
2+
3+
# Test recipe for RHEL/CentOS platforms version 10 and above (uses PCRE2)
4+
haproxy_install 'source' do
5+
source_url "https://www.haproxy.org/download/#{version.to_f}/src/haproxy-#{version}.tar.gz"
6+
source_checksum '3f5459c5a58e0b343a32eaef7ed5bed9d3fc29d8aa9e14b36c92c969fc2a60d9'
7+
source_version version
8+
# Rely on auto-detection for PCRE2 on RHEL >= 10
9+
use_libcrypt true
10+
use_openssl true
11+
use_zlib true
12+
use_linux_tproxy true
13+
use_linux_splice true
14+
end
15+
16+
haproxy_config_global ''
17+
18+
haproxy_config_defaults ''
19+
20+
haproxy_service 'haproxy' do
21+
action %i(create enable start)
22+
end

0 commit comments

Comments
 (0)