diff --git a/REFERENCE.md b/REFERENCE.md index 5a68d520..64a7ee7e 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -17,7 +17,7 @@ * [`r10k::params`](#r10k--params): Reasonable defaults for all classes * [`r10k::postrun_command`](#r10k--postrun_command): This class will configure r10k to run as part of the masters agent run * [`r10k::prerun_command`](#r10k--prerun_command): This class will configure r10k to run as part of the masters agent run -* [`r10k::webhook`](#r10k--webhook): Class: r10k::webhook +* [`r10k::webhook`](#r10k--webhook): install and configure the webhook-go package as local webhook receiver to trigger r10k runs * [`r10k::webhook::config`](#r10k--webhook--config): Class: r10k::webhook::config * [`r10k::webhook::package`](#r10k--webhook--package): Class: r10k::webhook::package * [`r10k::webhook::service`](#r10k--webhook--service): Class: r10k::webhook::service @@ -551,12 +551,13 @@ Default value: `'present'` ### `r10k::webhook` -Class: r10k::webhook +install and configure the webhook-go package as local webhook receiver to trigger r10k runs #### Parameters The following parameters are available in the `r10k::webhook` class: +* [`install_method`](#-r10k--webhook--install_method) * [`ensure`](#-r10k--webhook--ensure) * [`version`](#-r10k--webhook--version) * [`service_ensure`](#-r10k--webhook--service_ensure) @@ -569,6 +570,14 @@ The following parameters are available in the `r10k::webhook` class: * [`r10k`](#-r10k--webhook--r10k) * [`config`](#-r10k--webhook--config) +##### `install_method` + +Data type: `Enum['package', 'repo', 'none']` + +how the package should be installed + +Default value: `'package'` + ##### `ensure` Data type: `Boolean` diff --git a/manifests/webhook.pp b/manifests/webhook.pp index 7055ebd8..52fd14d2 100644 --- a/manifests/webhook.pp +++ b/manifests/webhook.pp @@ -1,7 +1,10 @@ -# Class: r10k::webhook # +# @summary install and configure the webhook-go package as local webhook receiver to trigger r10k runs +# +# @param install_method how the package should be installed # class r10k::webhook ( + Enum['package', 'repo', 'none'] $install_method = 'package', Boolean $ensure = $r10k::params::webhook_ensure, String $version = $r10k::params::webhook_version, Variant[ diff --git a/manifests/webhook/package.pp b/manifests/webhook/package.pp index 76469140..b25e68a0 100644 --- a/manifests/webhook/package.pp +++ b/manifests/webhook/package.pp @@ -2,31 +2,44 @@ # # class r10k::webhook::package () { - case $facts['os']['family'] { - 'RedHat': { - $provider = 'rpm' - $pkg_file = '/tmp/webhook-go.rpm' - $package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${r10k::webhook::version}/webhook-go_${r10k::webhook::version}_linux_amd64.rpm" + case $r10k::webhook::install_method { # lint:ignore:case_without_default + 'package': { + case $facts['os']['family'] { + 'RedHat': { + $provider = 'rpm' + $pkg_file = '/tmp/webhook-go.rpm' + $package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${r10k::webhook::version}/webhook-go_${r10k::webhook::version}_linux_amd64.rpm" + } + 'Debian', 'Ubuntu': { + $provider = 'dpkg' + $pkg_file = '/tmp/webhook-go.deb' + $package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${r10k::webhook::version}/webhook-go_${r10k::webhook::version}_linux_amd64.deb" + } + default: { + fail("Operating system ${facts['os']['name']} not supported for packages") + } + } + + file { $pkg_file: + ensure => file, + source => $package_url, + before => Package['webhook-go'], + } + + package { 'webhook-go': + ensure => 'present', + source => $pkg_file, + provider => $provider, + } } - 'Debian', 'Ubuntu': { - $provider = 'dpkg' - $pkg_file = '/tmp/webhook-go.deb' - $package_url = "https://github.com/voxpupuli/webhook-go/releases/download/v${r10k::webhook::version}/webhook-go_${r10k::webhook::version}_linux_amd64.deb" + 'repo': { + warning('webhook-go: configuring a repo is not implemented yet') } - default: { - fail("Operating system ${facts['os']['name']} not supported for packages") + # none = people configure a repo on their own + 'none': { + package { 'webhook-go': + ensure => 'installed', + } } } - - file { $pkg_file: - ensure => file, - source => $package_url, - before => Package['webhook-go'], - } - - package { 'webhook-go': - ensure => 'present', - source => $pkg_file, - provider => $provider, - } } diff --git a/spec/classes/webhook_spec.rb b/spec/classes/webhook_spec.rb index 966f06b8..a6acaffc 100644 --- a/spec/classes/webhook_spec.rb +++ b/spec/classes/webhook_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' describe 'r10k::webhook' do - on_supported_os.each do |os, facts| + on_supported_os.each do |os, os_facts| context "on #{os}" do let :facts do - facts + os_facts end let :params do @@ -74,16 +74,34 @@ deploy_modules: true generate_types: true ' - if %w[archlinux-rolling-x86_64 gentoo-2-x86_64].include?(os) - it { is_expected.not_to compile } - else - it { is_expected.to compile } - it { is_expected.to contain_class('r10k::webhook::package') } - it { is_expected.to contain_class('r10k::webhook::service') } - it { is_expected.to contain_class('r10k::webhook::config') } - it { is_expected.to contain_package('webhook-go').with_ensure('present') } - it { is_expected.to contain_service('webhook-go').with_ensure('running') } - it { is_expected.to contain_file('webhook.yml').with_content(content) } + context 'with default install_method' do + if %w[archlinux-rolling-x86_64 gentoo-2-x86_64].include?(os) + it { is_expected.not_to compile } + else + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('r10k::webhook::package') } + it { is_expected.to contain_class('r10k::webhook::service') } + it { is_expected.to contain_class('r10k::webhook::config') } + it { is_expected.to contain_package('webhook-go').with_ensure('present') } + it { is_expected.to contain_service('webhook-go').with_ensure('running') } + it { is_expected.to contain_file('webhook.yml').with_content(content) } + + if os_facts[:os]['family'] == 'RedHat' + it { is_expected.to contain_file('/tmp/webhook-go.rpm') } + it { is_expected.not_to contain_file('/tmp/webhook-go.deb') } + elsif os_facts[:os]['family'] == 'Debian' + it { is_expected.not_to contain_file('/tmp/webhook-go.rpm') } + it { is_expected.to contain_file('/tmp/webhook-go.deb') } + end + end + end + + context 'with install_method = none' do + let :params do + super().merge({ install_method: 'none' }) + end + + it { is_expected.to compile.with_all_deps } end end end