From ea67bd4460cd2e6dce99119bf0e0d40a8b811d55 Mon Sep 17 00:00:00 2001 From: Thomas Equeter Date: Thu, 13 Sep 2018 18:30:45 +0200 Subject: [PATCH 1/3] test that invalid yum repos are not generated --- spec/classes/init_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 4472a738..c2d6c760 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -21,9 +21,11 @@ case facts[:osfamily] when 'Debian' - it { is_expected.to contain_apt__source('gitlab_official_ce') } + it { is_expected.to contain_apt__source('gitlab_official_ce').with_comment(%r{.}) } + it { is_expected.not_to contain_apt__source('gitlab_official_') } when 'RedHat' - it { is_expected.to contain_yumrepo('gitlab_official_ce') } + it { is_expected.to contain_yumrepo('gitlab_official_ce').with_enabled(1) } + it { is_expected.not_to contain_yumrepo('gitlab_official_') } end end From 0907012b736eddda5029a96fce702edfaf2e2820 Mon Sep 17 00:00:00 2001 From: Thomas Equeter Date: Fri, 14 Sep 2018 08:54:53 +0200 Subject: [PATCH 2/3] remove useless repos configuration munging The URL is already supposed to be set through Hiera. --- manifests/omnibus_package_repository.pp | 31 +------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/manifests/omnibus_package_repository.pp b/manifests/omnibus_package_repository.pp index 64d87727..12cc8d95 100644 --- a/manifests/omnibus_package_repository.pp +++ b/manifests/omnibus_package_repository.pp @@ -18,36 +18,7 @@ $_edition = $manage_upstream_edition } - # ensure the correct edition is used if upstream package repositories are being configured - if $_edition != 'disabled'{ - case $facts['os']['family'] { - 'Debian': { - $_filtered_repository_configuration = { - 'apt::source' => { - "gitlab_official_${_edition}" => { - location => "https://packages.gitlab.com/gitlab/gitlab-${_edition}/debian", - }, - }, - } - } - 'RedHat': { - $_filtered_repository_configuration = { - 'yumrepo' => { - "gitlab_official_${_edition}" => { - baseurl => "https://packages.gitlab.com/gitlab/gitlab-${_edition}/el/${facts['os']['release']['major']}/\$basearch", - }, - }, - } - } - default: { - $_filtered_repository_configuration = {} - } - } - $_repository_configuration = deep_merge($repository_configuration, $_filtered_repository_configuration) - } else { - # using upstream repository, so just use defaults - $_repository_configuration = $repository_configuration - } + $_repository_configuration = $repository_configuration # common attributes for all repository configuration resources # ensures correct ordering regardless of the number or configuration From e56b7d206f557bd90cf6bba94c5563bec6a7d3dd Mon Sep 17 00:00:00 2001 From: Thomas Equeter Date: Fri, 14 Sep 2018 10:20:58 +0200 Subject: [PATCH 3/3] fix repositories missing the edition name This fixes repositories with missing edition string in the name and URL (ie. `gitlab_official_` instead of `gitlab_official_ce`). --- data/Debian.yaml | 10 ++++++++-- data/RedHat.yaml | 13 +++++++++++-- manifests/omnibus_package_repository.pp | 26 ++++++++++++++++++++++++- spec/classes/init_spec.rb | 14 +++++++++---- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/data/Debian.yaml b/data/Debian.yaml index 26624230..3b54f537 100644 --- a/data/Debian.yaml +++ b/data/Debian.yaml @@ -1,8 +1,14 @@ gitlab::repository_configuration: 'apt::source': - "gitlab_official_%{lookup('gitlab::edition')}": + "gitlab_official_ce": comment: 'Official repository for GitLab Omnibus' - location: "https://packages.gitlab.com/gitlab/gitlab-%{lookup('gitlab::edition')}/debian" + location: "https://packages.gitlab.com/gitlab/gitlab-ce/debian" + key: + id: '1A4C919DB987D435939638B914219A96E15E78F4' + source: 'https://packages.gitlab.com/gpg.key' + "gitlab_official_ee": + comment: 'Official repository for GitLab Omnibus' + location: "https://packages.gitlab.com/gitlab/gitlab-ee/debian" key: id: '1A4C919DB987D435939638B914219A96E15E78F4' source: 'https://packages.gitlab.com/gpg.key' diff --git a/data/RedHat.yaml b/data/RedHat.yaml index 7b0d8dfb..a4fe97bf 100644 --- a/data/RedHat.yaml +++ b/data/RedHat.yaml @@ -1,10 +1,19 @@ gitlab::repository_configuration: yumrepo: - "gitlab_official_%{lookup('gitlab::edition')}": + "gitlab_official_ce": ensure: 'present' assumeyes: true enabled: 1 - baseurl: "https://packages.gitlab.com/gitlab/gitlab-%{lookup('gitlab::edition')}/el/%{facts.os.release.major}/$basearch" + baseurl: "https://packages.gitlab.com/gitlab/gitlab-ce/el/%{facts.os.release.major}/$basearch" + gpgkey: "https://packages.gitlab.com/gpg.key" + gpgcheck: 1 + repo_gpgcheck: 1 + sslverify: 1 + "gitlab_official_ee": + ensure: 'present' + assumeyes: true + enabled: 1 + baseurl: "https://packages.gitlab.com/gitlab/gitlab-ee/el/%{facts.os.release.major}/$basearch" gpgkey: "https://packages.gitlab.com/gpg.key" gpgcheck: 1 repo_gpgcheck: 1 diff --git a/manifests/omnibus_package_repository.pp b/manifests/omnibus_package_repository.pp index 12cc8d95..83a52611 100644 --- a/manifests/omnibus_package_repository.pp +++ b/manifests/omnibus_package_repository.pp @@ -18,7 +18,31 @@ $_edition = $manage_upstream_edition } - $_repository_configuration = $repository_configuration + if $_edition == 'disabled' { + $_repository_configuration = $repository_configuration + } else { + # if we manage the repositories, adjust the ensure => present/absent + # attributes according to the desired edition. + $_repository_configuration = $repository_configuration.reduce({}) | $_memo, $_pair1 | { + # yumrepo => ... + [ $_rsc_type, $_repo_hash ] = $_pair1 + + $_mapped_repo_hash = $_repo_hash.reduce({}) | $_memo, $_pair2 | { + # gitlab_official_ce => ... + [ $_repo_name, $_repo_attrs, ] = $_pair2 + + if $_repo_name == "gitlab_official_${_edition}" { + $_ensure = 'present' + } else { + $_ensure = 'absent' + } + + $_memo + { $_repo_name => $_repo_attrs + { ensure => $_ensure } } + } + + $_memo + { $_rsc_type => $_mapped_repo_hash } + } + } # common attributes for all repository configuration resources # ensures correct ordering regardless of the number or configuration diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index c2d6c760..89b916b8 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -21,11 +21,15 @@ case facts[:osfamily] when 'Debian' - it { is_expected.to contain_apt__source('gitlab_official_ce').with_comment(%r{.}) } + it { is_expected.to contain_apt__source('gitlab_official_ce').with_ensure('present').with_comment(%r{.}) } + it { is_expected.to contain_apt__source('gitlab_official_ee').with_ensure('absent') } it { is_expected.not_to contain_apt__source('gitlab_official_') } + it { is_expected.not_to contain_yumrepo('gitlab_official_ce') } when 'RedHat' - it { is_expected.to contain_yumrepo('gitlab_official_ce').with_enabled(1) } + it { is_expected.to contain_yumrepo('gitlab_official_ce').with_ensure('present').with_enabled(1) } + it { is_expected.to contain_yumrepo('gitlab_official_ee').with_ensure('absent') } it { is_expected.not_to contain_yumrepo('gitlab_official_') } + it { is_expected.not_to contain_apt__source('gitlab_official_ce') } end end @@ -37,9 +41,11 @@ case facts[:osfamily] when 'Debian' - it { is_expected.to contain_apt__source('gitlab_official_ee') } + it { is_expected.to contain_apt__source('gitlab_official_ee').with_ensure('present') } + it { is_expected.to contain_apt__source('gitlab_official_ce').with_ensure('absent') } when 'RedHat' - it { is_expected.to contain_yumrepo('gitlab_official_ee') } + it { is_expected.to contain_yumrepo('gitlab_official_ee').with_ensure('present') } + it { is_expected.to contain_yumrepo('gitlab_official_ce').with_ensure('absent') } end end describe 'external_url' do