-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for running programs #604
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# @summary Program definition | ||
# | ||
# A command to be executed by haproxy master process | ||
# | ||
# @see https://www.haproxy.com/documentation/haproxy-configuration-tutorials/programs/ | ||
# @example | ||
# haproxy::program { 'hello': | ||
# command => 'hello world', | ||
# } | ||
define haproxy::program ( | ||
String $command, | ||
Check warning on line 11 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 11 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 11 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)
|
||
Optional[String] $user = undef, | ||
Check warning on line 12 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 12 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 12 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)
|
||
Optional[String] $group = undef, | ||
Check warning on line 13 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 13 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 13 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)
|
||
Optional[String] $options = undef, | ||
Check warning on line 14 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 14 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
Check warning on line 14 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)
|
||
String $instance = 'haproxy', | ||
Check warning on line 15 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
|
||
Optional[Stdlib::Absolutepath] $config_file = undef, | ||
Check warning on line 16 in manifests/program.pp GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)
|
||
) { | ||
# We derive these settings so that the caller only has to specify $instance. | ||
include haproxy::params | ||
|
||
if $instance == 'haproxy' { | ||
$instance_name = 'haproxy' | ||
$_config_file = pick($config_file, $haproxy::config_file) | ||
} else { | ||
$instance_name = "haproxy-${instance}" | ||
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl)) | ||
} | ||
|
||
concat::fragment { "${instance_name}-${name}_program": | ||
order => "40-program-${name}", | ||
target => $_config_file, | ||
content => epp('haproxy/haproxy_program.epp', { | ||
'name' => $name, | ||
'command' => $command, | ||
'user' => $user, | ||
'group' => $group, | ||
'options' => $options, | ||
}), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'haproxy::program' do | ||
let :pre_condition do | ||
'class{"haproxy": | ||
config_file => "/tmp/haproxy.cfg" | ||
} | ||
' | ||
end | ||
let(:facts) do | ||
{ | ||
concat_basedir: '/foo', | ||
os: { | ||
family: 'Debian' | ||
} | ||
} | ||
end | ||
|
||
context 'simple program' do | ||
let(:title) { 'hello' } | ||
let(:params) do | ||
{ | ||
command: 'echo "hello world"', | ||
} | ||
end | ||
|
||
it { | ||
is_expected.to contain_concat__fragment('haproxy-hello_program').with( | ||
'order' => '40-program-hello', | ||
'target' => '/tmp/haproxy.cfg', | ||
'content' => %r{command echo "hello world"}, | ||
) | ||
} | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
program <%= $name %> | ||
command <%= $command %> | ||
<% if $user { -%> | ||
user <%= $user %> | ||
<% } -%> | ||
<% if $group { -%> | ||
group $group | ||
<% } -%> | ||
<% if $options { -%> | ||
<%= $options %> | ||
<% } -%> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type Haproxy::Programs = Hash[String, Struct[{ | ||
command => String[1], | ||
Optional[user] => String[1], | ||
Optional[group] => String[1], | ||
Optional[options] => String[1], | ||
Optional[instance] => String[1], | ||
Optional[config_file] => Stdlib::Absolutepath, | ||
}]] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use
create_resources()
, it's deprecated and we want to get rid of it. please iterate on$programs
and call the defined resource for each element.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bastelfreak Doesn't seem to be deprecated in stdlib v9.4.1 where can I find such deprecation note? Generally I'd try to avoid code repetition, this feels like a code smell. I've tried to replace it, but I'm not sure what you mean.