Skip to content

Commit

Permalink
Fixes #28067 - dynflow sidekiq services config
Browse files Browse the repository at this point in the history
  • Loading branch information
ezr-ondrej committed Oct 22, 2019
1 parent 95f1416 commit 63c29e1
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 4 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fixtures:
mysql: 'https://github.com/puppetlabs/puppetlabs-mysql'
postgresql: 'https://github.com/puppetlabs/puppetlabs-postgresql'
puppet: 'https://github.com/theforeman/puppet-puppet'
redis: 'https://github.com/voxpupuli/puppet-redis'
systemd: 'https://github.com/camptocamp/puppet-systemd'
selinux_core:
repo: "https://github.com/puppetlabs/puppetlabs-selinux_core"
Expand Down
28 changes: 28 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,34 @@
ensure => absent,
}

if $::foreman::jobs_sidekiq {
if $::foreman::jobs_sidekiq_redis_url == undef {
include ::redis'

redis::instance { 'dynflow':
port => $::foreman::jobs_sidekiq_redis_port,
}
}

file { '/etc/foreman/dynflow/':
ensure => directory,
}

file { '/etc/foreman/dynflow/orchestrator.yml':
owner => 'root',
group => $::foreman::group,
mode => '0640',
content => template('foreman/dynflow_orchestrator.yml.erb'),
}

file { '/etc/foreman/dynflow/worker.yml':
owner => 'root',
group => $::foreman::group,
mode => '0640',
content => template('foreman/dynflow_worker.yml.erb'),
}
}

if $::foreman::apache {
contain foreman::config::apache

Expand Down
9 changes: 9 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@
#
# $jobs_service_ensure:: Whether the Dynflow executor should be running or stopped
#
# $jobs_sidekiq:: Whether use Sidekiq to run Dynflow executor
#
# $jobs_sidekiq_redis_url:: If set, the redis server is not managed and we use the defined url to connect
#
# $jobs_sidekiq_redis_port:: What port should redis server for Dynflow worker use
#
# $hsts_enabled:: Should HSTS enforcement in https requests be enabled
#
# $cors_domains:: List of domains that show be allowed for Cross-Origin Resource Sharing. This requires Foreman 1.22+
Expand Down Expand Up @@ -305,6 +311,9 @@
String $jobs_service = $::foreman::params::jobs_service,
Stdlib::Ensure::Service $jobs_service_ensure = $::foreman::params::jobs_service_ensure,
Boolean $jobs_service_enable = $::foreman::params::jobs_service_enable,
Boolean $jobs_sidekiq = $::foreman::params::jobs_sidekiq,
Optional[Redis::RedisUrl] $jobs_sidekiq_redis_url = $::foreman::params::jobs_sidekiq_redis_url,
Stdlib::Port $jobs_sidekiq_redis_port = $::foreman::params::jobs_sidekiq_redis_port,
Boolean $hsts_enabled = $::foreman::params::hsts_enabled,
Array[Stdlib::HTTPUrl] $cors_domains = $::foreman::params::cors_domains,
) inherits foreman::params {
Expand Down
6 changes: 6 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
}
}

if $::foreman::jobs_sidekiq {
package { 'foreman-dynflow-sidekiq':
ensure => installed,
}
}

if $::foreman::use_foreman_service {
package { 'foreman-service':
ensure => installed,
Expand Down
3 changes: 3 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
$jobs_service = 'dynflowd'
$jobs_service_ensure = 'running'
$jobs_service_enable = true
$jobs_sidekiq = true
$jobs_sidekiq_redis_url = undef
$jobs_sidekiq_redis_port = 6381

$hsts_enabled = true

Expand Down
24 changes: 22 additions & 2 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,30 @@
String $jobs_service = $::foreman::jobs_service,
Stdlib::Ensure::Service $jobs_service_ensure = $::foreman::jobs_service_ensure,
Boolean $jobs_service_enable = $::foreman::jobs_service_enable,
Boolean $jobs_sidekiq = $::foreman::jobs_sidekiq,
) {
if $jobs_sidekiq {
$sidekiq_ensure = $jobs_service_ensure
$sidekiq_enable = $jobs_service_enable
$dynflowd_ensure = 'stopped'
$dynflowd_enable = false
} else {
$dynflowd_ensure = $jobs_service_ensure
$dynflowd_enable = $jobs_service_enable
$sidekiq_enable = false
$sidekiq_ensure = 'stopped'
}
service { 'dynflow-sidekiq@orchestrator':
ensure => $sidekiq_ensure,
enable => $sidekiq_enable,
}
service { 'dynflow-sidekiq@worker':
ensure => $sidekiq_ensure,
enable => $sidekiq_enable,
}
service { $jobs_service:
ensure => $jobs_service_ensure,
enable => $jobs_service_enable,
ensure => $dynflowd_ensure,
enable => $dynflowd_enable,
}

if $apache {
Expand Down
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
{
"name": "puppet/extlib",
"version_requirement": ">= 3.0.0 < 5.0.0"
},
{
"name": "puppet/redis",
"version_requirement": ">= 4.2.0 < 5.0.0"
}
],
"requirements": [
Expand Down
11 changes: 11 additions & 0 deletions spec/classes/foreman_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
it { should contain_package('foreman-postgresql').that_requires('Class[foreman::repo]') }
end

describe 'sidekiq jobs' do
context 'with jobs_sidekiq disabled' do
let(:params) { super().merge(jobs_sidekiq: false) }
it { is_expected.not_to contain_package('foreman-dynflow-sidekiq') }
end
context 'with jobs_sidekiq enabled' do
let(:params) { super().merge(jobs_sidekiq: true) }
it { is_expected.to contain_package('foreman-dynflow-sidekiq') }
end
end

context 'with SELinux enabled' do
let(:facts) { super().merge(selinux: true) }

Expand Down
11 changes: 10 additions & 1 deletion spec/classes/foreman_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
foreman_service_enable: true,
jobs_service: 'dynflower',
jobs_service_ensure: 'stopped',
jobs_service_enable: false
jobs_service_enable: false,
jobs_sidekiq: false
}
end

Expand Down Expand Up @@ -67,4 +68,12 @@
.with_enable(true)
end
end

context 'with sidekiq' do
let(:pre_condition) { 'include ::apache' }
let(:params) { super().merge(jobs_sidekiq: true, jobs_service_ensure: 'running', jobs_service_enable: true) }
it { is_expected.to contain_service('dynflow-sidekiq@orchestrator').with_ensure('running').with_enable(true) }
it { is_expected.to contain_service('dynflow-sidekiq@worker').with_ensure('running').with_enable(true) }
it { is_expected.to contain_service('dynflower').with_ensure('stopped').with_enable(false) }
end
end
4 changes: 3 additions & 1 deletion spec/classes/foreman_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@
# service
it { should contain_class('foreman::service') }
it { should_not contain_service('foreman') }
it { is_expected.to contain_service('dynflowd').with_ensure('running').with_enable(true) }
it { is_expected.to contain_service('dynflow-sidekiq@orchestrator').with_ensure('running').with_enable(true) }
it { is_expected.to contain_service('dynflow-sidekiq@worker').with_ensure('running').with_enable(true) }
it { is_expected.to contain_service('dynflowd').with_ensure('stopped').with_enable(false) }

it 'should restart passenger' do
should contain_exec('restart_foreman')
Expand Down
3 changes: 3 additions & 0 deletions templates/dynflow_orchestrator.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:concurrency: 1
:queues:
- dynflow_orchestrator
4 changes: 4 additions & 0 deletions templates/dynflow_worker.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:concurrency: <%= scope.lookupvar("foreman::dynflow_pool_size") %>
:queues:
- default
- remote_execution
3 changes: 3 additions & 0 deletions templates/settings.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@

:dynflow:
:pool_size: <%= scope.lookupvar("foreman::dynflow_pool_size") %>
<% if scope.lookupvar("foreman::jobs_sidekiq") %>
:redis_url: <%= scope.lookupvar("foreman::jobs_sidekiq_redis_url") || "redis://localhost:#{scope.lookupvar("foreman::jobs_sidekiq_redis_port")}/0" %>
<% end %>
<% if scope.lookupvar("foreman::apache") && !scope.lookupvar("foreman::passenger") -%>

# Configure reverse proxy headers
Expand Down

0 comments on commit 63c29e1

Please sign in to comment.