Skip to content
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

Allow setting docker service limits #711

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ class { 'docker':
}
```

To increase/decrese docker process limits (open files limit or proc limit), you can use the service_limits option.
This could be necessary to set higher limits than the ones inherited from systemd.
```puppet
class {'docker':
service_limits => {
nofile => 4096,
nproc => 4096
}
}
```

The class contains lots of other options, please see the inline code
documentation for the full options.

Expand Down
13 changes: 13 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@
# Valid values are 'true', 'false'.
# Defaults to 'true'.
#
# [*service_limits*]
# Hash of limits to be applied for the systemd service
# Example:
# class {'docker':
# service_limits => {
# nofile => 4096
# }
# }
#
# [*root_dir*]
# Custom root directory for containers
# Defaults to undefined
Expand Down Expand Up @@ -440,6 +449,7 @@
$service_overrides_template = $docker::params::service_overrides_template,
$service_hasstatus = $docker::params::service_hasstatus,
$service_hasrestart = $docker::params::service_hasrestart,
$service_limits = $docker::params::service_limits,
) inherits docker::params {

validate_string($version)
Expand All @@ -463,6 +473,9 @@
validate_string($fixed_cidr)
validate_string($default_gateway)
validate_string($bip)
if $service_limits != undef {
validate_hash($service_limits)
}

if ($default_gateway) and (!$bridge) {
fail('You must provide the $bridge parameter.')
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
$labels = []
$service_state = running
$service_enable = true
$service_limits = undef
$manage_service = true
$root_dir = undef
$tmp_dir = '/tmp/'
Expand Down
10 changes: 10 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
# [*shell_values*]
# Array of shell values to pass into init script config files
#
# [*service_limits*]
# Hash of limits to be applied for the systemd service
# Example:
# class {'docker':
# service_limits => {
# nofile => 4096
# }
# }
#
# [*manage_service*]
# Specify whether the service should be managed.
# Valid values are 'true', 'false'.
Expand Down Expand Up @@ -104,6 +113,7 @@
$service_overrides_template = $docker::service_overrides_template,
$service_hasstatus = $docker::service_hasstatus,
$service_hasrestart = $docker::service_hasrestart,
$service_limits = $docker::service_limits,
$daemon_environment_files = $docker::daemon_environment_files,
$tls_enable = $docker::tls_enable,
$tls_verify = $docker::tls_verify,
Expand Down
37 changes: 32 additions & 5 deletions spec/classes/docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -905,12 +905,23 @@
it { should contain_yumrepo('docker') }
it { should_not contain_class('epel') }
it { should contain_package('docker').with_install_options('--enablerepo=rhel7-extras') }

let(:params) { {'proxy' => 'http://127.0.0.1:3128' } }
service_config_file = '/etc/sysconfig/docker'
it { should contain_file(service_config_file).with_content(/^http_proxy='http:\/\/127.0.0.1:3128'/) }
it { should contain_file(service_config_file).with_content(/^ https_proxy='http:\/\/127.0.0.1:3128'/) }
it { should contain_service('docker').with_provider('systemd').with_hasstatus(true).with_hasrestart(true) }


context 'with proxy param' do
let(:params) { {'proxy' => 'http://127.0.0.1:3128' } }
service_config_file = '/etc/sysconfig/docker'
it { should contain_file(service_config_file).with_content(/^http_proxy='http:\/\/127.0.0.1:3128'/) }
it { should contain_file(service_config_file).with_content(/^ https_proxy='http:\/\/127.0.0.1:3128'/) }
end

context 'with service_limits specified' do
let(:params) { { 'service_limits' => { 'nofile' => 1024, 'nproc' => 2048 } } }
systemd_service_file = '/etc/systemd/system/docker.service.d/service-overrides.conf'
it { should contain_file(systemd_service_file).with_content(/^LimitNOFILE=1024/)}
it { should contain_file(systemd_service_file).with_content(/^LimitNPROC=2048/)}
end

end

context 'specific to Oracle Linux 7 or above' do
Expand Down Expand Up @@ -981,6 +992,14 @@
} }

it { should contain_service('docker').with_provider('systemd').with_hasstatus(true).with_hasrestart(true) }

context 'with service_limits specified' do
let(:params) { { 'service_limits' => { 'nofile' => 1024, 'nproc' => 2048 } } }
systemd_service_file = '/etc/systemd/system/docker.service.d/service-overrides.conf'
it { should contain_file(systemd_service_file).with_content(/^LimitNOFILE=1024/)}
it { should contain_file(systemd_service_file).with_content(/^LimitNPROC=2048/)}
end

end

context 'Debian >= 8' do
Expand All @@ -994,6 +1013,14 @@
} }

it { should contain_service('docker').with_provider('systemd').with_hasstatus(true).with_hasrestart(true) }

context 'with service_limits specified' do
let(:params) { { 'service_limits' => { 'nofile' => 1024, 'nproc' => 2048 } } }
systemd_service_file = '/etc/systemd/system/docker.service.d/service-overrides.conf'
it { should contain_file(systemd_service_file).with_content(/^LimitNOFILE=1024/)}
it { should contain_file(systemd_service_file).with_content(/^LimitNPROC=2048/)}
end

end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
[Service]
EnvironmentFile=-/etc/conf.d/docker
<%- if @service_limits -%>
<%- @service_limits.each do |lim,value| -%>
<%- case lim -%>
<%- when "nofile" -%>
LimitNOFILE=<%= value %>
<%- when "nproc" -%>
LimitNPROC=<%= value %>
<%- end -%>
<%- end -%>
<%- end -%>
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
[Service]
EnvironmentFile=-/etc/default/docker
EnvironmentFile=-/etc/default/docker-storage
<%- if @service_limits -%>
<%- @service_limits.each do |lim,value| -%>
<%- case lim -%>
<%- when "nofile" -%>
LimitNOFILE=<%= value %>
<%- when "nproc" -%>
LimitNPROC=<%= value %>
<%- end -%>
<%- end -%>
<%- end -%>
ExecStart=
ExecStart=/usr/bin/<%= @docker_command %> <%= @daemon_subcommand %> $OPTIONS \
$DOCKER_STORAGE_OPTIONS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
<%- if @service_limits -%>
<%- @service_limits.each do |lim,value| -%>
<%- case lim -%>
<%- when "nofile" -%>
LimitNOFILE=<%= value %>
<%- when "nproc" -%>
LimitNPROC=<%= value %>
<%- end -%>
<%- end -%>
<%- end -%>
<% if @daemon_environment_files %><% @daemon_environment_files.each do |param| %>EnvironmentFile=-<%= param %>
<% end %><% end -%>
ExecStart=
Expand Down