From b85e450f262ed7bb73cec738390f386c5c98933e Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Sat, 3 Apr 2021 22:15:50 -0700 Subject: [PATCH] manage the docker-ce-cli package Manage the docker-ce-cli package the same way as the docker-ce package. Fixes #597. Also remove obsolete manual setting of package provider. --- REFERENCE.md | 9 ++++++++ manifests/init.pp | 2 ++ manifests/install.pp | 38 +++++++++++++++------------------ manifests/params.pp | 3 ++- spec/classes/init_spec.rb | 1 + spec/helper/get_defaults.rb | 4 +++- spec/shared_examples/install.rb | 26 ++++++++++++---------- 7 files changed, 49 insertions(+), 34 deletions(-) mode change 100755 => 100644 spec/classes/init_spec.rb diff --git a/REFERENCE.md b/REFERENCE.md index 4a28f686..55c0fe03 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -166,6 +166,7 @@ The following parameters are available in the `docker` class: * [`docker_msft_provider_version`](#docker_msft_provider_version) * [`docker_ce_start_command`](#docker_ce_start_command) * [`docker_ce_package_name`](#docker_ce_package_name) +* [`docker_ce_cli_package_name`](#docker_ce_cli_package_name) * [`docker_ce_source_location`](#docker_ce_source_location) * [`docker_ce_key_source`](#docker_ce_key_source) * [`docker_ce_key_id`](#docker_ce_key_id) @@ -926,6 +927,14 @@ Data type: `Optional[String]` Default value: `$docker::params::docker_ce_package_name` +##### `docker_ce_cli_package_name` + +Data type: `String[1]` + + + +Default value: `$docker::params::docker_ce_cli_package_name` + ##### `docker_ce_source_location` Data type: `Optional[String]` diff --git a/manifests/init.pp b/manifests/init.pp index 0e660083..f016a081 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -318,6 +318,7 @@ # # @param docker_ce_start_command # @param docker_ce_package_name +# @param docker_ce_cli_package_name # @param docker_ce_source_location # @param docker_ce_key_source # @param docker_ce_key_id @@ -363,6 +364,7 @@ Array $dependent_packages = $docker::params::dependent_packages, String $docker_ce_start_command = $docker::params::docker_ce_start_command, Optional[String] $docker_ce_package_name = $docker::params::docker_ce_package_name, + String[1] $docker_ce_cli_package_name = $docker::params::docker_ce_cli_package_name, Optional[String] $docker_ce_source_location = $docker::params::package_ce_source_location, Optional[String] $docker_ce_key_source = $docker::params::package_ce_key_source, Optional[String] $docker_ce_key_id = $docker::params::package_ce_key_id, diff --git a/manifests/install.pp b/manifests/install.pp index 967955da..2aebe2b4 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -47,35 +47,27 @@ } if $docker::package_source { - case $facts['os']['family'] { - 'Debian' : { - $pk_provider = 'dpkg' - } - 'RedHat' : { - $pk_provider = 'yum' - } - 'windows' : { - fail('Custom package source is currently not implemented on windows.') - } - default : { - $pk_provider = undef - } + if $facts['os']['family'] == 'windows' { + fail('Custom package source is currently not implemented on windows.') } case $docker::package_source { /docker-engine/ : { ensure_resource('package', 'docker', merge($docker_hash, { - ensure => $ensure, - provider => $pk_provider, - source => $docker::package_source, - name => $docker::docker_engine_package_name, + ensure => $ensure, + source => $docker::package_source, + name => $docker::docker_engine_package_name, })) } /docker-ce/ : { ensure_resource('package', 'docker', merge($docker_hash, { - ensure => $ensure, - provider => $pk_provider, - source => $docker::package_source, - name => $docker::docker_ce_package_name, + ensure => $ensure, + source => $docker::package_source, + name => $docker::docker_ce_package_name, + })) + ensure_resource('package', 'docker-ce-cli', merge($docker_hash, { + ensure => $ensure, + source => $docker::package_source, + name => $docker::docker_ce_cli_package_name, })) } default : {} @@ -88,6 +80,10 @@ ensure => $ensure, name => $docker::docker_package_name, })) + ensure_resource('package', 'docker-ce-cli', merge($docker_hash, { + ensure => $ensure, + name => $docker::docker_ce_cli_package_name, + })) if $ensure == 'absent' { ensure_resource('package', $dependent_packages, { diff --git a/manifests/params.pp b/manifests/params.pp index 68dd0937..91fb1561 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -5,6 +5,7 @@ $ensure = present $docker_ce_start_command = 'dockerd' $docker_ce_package_name = 'docker-ce' + $docker_ce_cli_package_name = 'docker-ce-cli' $docker_engine_start_command = 'docker daemon' $docker_engine_package_name = 'docker-engine' $docker_ce_channel = stable @@ -372,7 +373,7 @@ default => [], } - $dependent_packages = [ 'docker-ce-cli', 'containerd.io', ] + $dependent_packages = [ $docker_ce_cli_package_name, 'containerd.io', ] if($service_provider == 'systemd') { # systemd v230 adds new StartLimitIntervalSec, StartLimitBurst diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb old mode 100755 new mode 100644 index cd94d34e..0e4ab609 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -89,6 +89,7 @@ 'docker_ce_key_id' => defaults['package_ce_key_id'], 'docker_ce_key_source' => defaults['package_ce_key_source'], 'docker_ce_package_name' => defaults['docker_ce_package_name'], + 'docker_ce_cli_package_name' => defaults['docker_ce_cli_package_name'], 'docker_ce_release' => defaults['package_ce_release'], 'docker_ce_source_location' => defaults['package_ce_source_location'], 'docker_ce_start_command' => defaults['docker_ce_start_command'], diff --git a/spec/helper/get_defaults.rb b/spec/helper/get_defaults.rb index ec5f6a50..89336759 100644 --- a/spec/helper/get_defaults.rb +++ b/spec/helper/get_defaults.rb @@ -26,6 +26,7 @@ def get_defaults(_facts) dns_search = :undef docker_ce_channel = 'stable' docker_ce_package_name = 'docker-ce' + docker_ce_cli_package_name = 'docker-ce-cli' docker_ce_start_command = 'dockerd' docker_command = 'docker' docker_ee = false @@ -343,7 +344,7 @@ def get_defaults(_facts) apt_source_pin_level = :undef end - dependent_packages = ['docker-ce-cli', 'containerd.io'] + dependent_packages = [docker_ce_cli_package_name, 'containerd.io'] prerequired_packages = case _facts[:os]['family'] when 'Debian' @@ -392,6 +393,7 @@ def get_defaults(_facts) 'dns_search' => dns_search, 'docker_ce_channel' => docker_ce_channel, 'docker_ce_package_name' => docker_ce_package_name, + 'docker_ce_cli_package_name' => docker_ce_cli_package_name, 'docker_ce_start_command' => docker_ce_start_command, 'docker_command' => docker_command, 'docker_ee' => docker_ee, diff --git a/spec/shared_examples/install.rb b/spec/shared_examples/install.rb index e7b87f78..d8e31bdc 100644 --- a/spec/shared_examples/install.rb +++ b/spec/shared_examples/install.rb @@ -21,22 +21,12 @@ is_expected.to contain_class('docker::install') } - provider_value = case _facts[:os]['family'] - when 'Debian' - 'dpkg' - when 'RedHat' - 'yum' - else - :undef - end - case _params['package_source'] when 'docker-engine' it { is_expected.to contain_package('docker').with( { 'ensure' => ensure_value, - 'provider' => provider_value, 'source' => _params['package_source'], 'name' => _params['docker_engine_package_name'], }.merge(docker_hash), @@ -47,12 +37,20 @@ is_expected.to contain_package('docker').with( { 'ensure' => ensure_value, - 'provider' => provider_value, 'source' => _params['package_source'], 'name' => _params['docker_ce_package_name'], }.merge(docker_hash), ) } + it { + is_expected.to contain_package('docker-ce-cli').with( + { + 'ensure' => ensure_value, + 'source' => _params['package_source'], + 'name' => _params['docker_ce_cli_package_name'], + }.merge(docker_hash), + ) + } end elsif _facts[:os]['family'] != 'windows' it { @@ -61,6 +59,12 @@ 'name' => values['docker_package_name'], ) } + it { + is_expected.to contain_package('docker-ce-cli').with( + 'ensure' => ensure_value, + 'name' => _params['docker_ce_cli_package_name'], + ) + } if ensure_value == 'absent' _params['dependent_packages'].each do |dependent_package|