Skip to content
Merged
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
13 changes: 11 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -551,12 +551,13 @@ Default value: `'present'`

### <a name="r10k--webhook"></a>`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)
Expand All @@ -569,6 +570,14 @@ The following parameters are available in the `r10k::webhook` class:
* [`r10k`](#-r10k--webhook--r10k)
* [`config`](#-r10k--webhook--config)

##### <a name="-r10k--webhook--install_method"></a>`install_method`

Data type: `Enum['package', 'repo', 'none']`

how the package should be installed

Default value: `'package'`

##### <a name="-r10k--webhook--ensure"></a>`ensure`

Data type: `Boolean`
Expand Down
5 changes: 4 additions & 1 deletion manifests/webhook.pp
Original file line number Diff line number Diff line change
@@ -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[
Expand Down
59 changes: 36 additions & 23 deletions manifests/webhook/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
42 changes: 30 additions & 12 deletions spec/classes/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down