Skip to content

Commit

Permalink
Switch to repos to maintaned pkgs.k8s.io
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Sep 22, 2023
1 parent c69dfe7 commit 53b786c
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 12 deletions.
22 changes: 14 additions & 8 deletions manifests/repos.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# @param container_runtime
# This is the runtime that the Kubernetes cluster will use.
# It can only be set to "cri_containerd" or "docker". Defaults to cri_containerd
# @param kubernetes_version
# The kubernetes version used to determine major release version.
# @param kubernetes_apt_location
# The APT repo URL for the Kubernetes packages. Defaults to https://apt.kubernetes.io
# @param kubernetes_apt_release
Expand Down Expand Up @@ -40,6 +42,7 @@
#
class kubernetes::repos (
String $container_runtime = $kubernetes::container_runtime,
Optional[String] $kubernetes_version = $kubernetes::kubernetes_version,
Optional[String] $kubernetes_apt_location = $kubernetes::kubernetes_apt_location,
Optional[String] $kubernetes_apt_release = $kubernetes::kubernetes_apt_release,
Optional[String] $kubernetes_apt_repos = $kubernetes::kubernetes_apt_repos,
Expand All @@ -60,16 +63,18 @@

) {
if $create_repos {
$parts = split($kubernetes_version, '[.]')
$minor_version = "${parts[0]}.${parts[1]}"
case $facts['os']['family'] {
'Debian': {
$codename = fact('os.distro.codename')
apt::source { 'kubernetes':
location => pick($kubernetes_apt_location,'https://apt.kubernetes.io'),
repos => pick($kubernetes_apt_repos,'main'),
release => pick($kubernetes_apt_release,'kubernetes-xenial'),
location => pick($kubernetes_apt_location,"https://pkgs.k8s.io/core:/stable:/v${minor_version}/deb"),
repos => pick($kubernetes_apt_repos,'/'),
release => $kubernetes_apt_release,
key => {
'id' => pick($kubernetes_key_id,'A362B822F6DEDC652817EA46B53DC80D13EDEF05'),
'source' => pick($kubernetes_key_source,'https://packages.cloud.google.com/apt/doc/apt-key.gpg'),
'id' => pick($kubernetes_key_id,'F46193FF99DBC56573C3B95949D205BA06FEF67C'),
'source' => pick($kubernetes_key_source,"https://pkgs.k8s.io/core:/stable:/v${minor_version}/deb/Release.key"),
},
}

Expand Down Expand Up @@ -99,9 +104,10 @@

yumrepo { 'kubernetes':
descr => 'Kubernetes',
baseurl => pick($kubernetes_yum_baseurl,'https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64'),
gpgkey => pick($kubernetes_yum_gpgkey,'https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg'),
gpgcheck => true,
baseurl => pick($kubernetes_yum_baseurl,"https://pkgs.k8s.io/core:/stable:/v${minor_version}/rpm/"),
gpgkey => pick($kubernetes_yum_gpgkey,"https://pkgs.k8s.io/core:/stable:/v${minor_version}/rpm/repodata/repomd.xml.key"),
enabled => 1,
gpgcheck => 1,
}
}

Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/kubernetes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
case $facts['os']['family'] {
'RedHat', 'CentOS': {
class {'kubernetes':
kubernetes_version => '1.22.0',
kubernetes_package_version => '1.22.0',
kubernetes_version => '1.28.2',
kubernetes_package_version => '1.28.2-1.1',
controller_address => "#{int_ipaddr1}:6443",
container_runtime => 'docker',
manage_docker => false,
Expand Down
135 changes: 133 additions & 2 deletions spec/classes/repos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,67 @@

require 'spec_helper'
describe 'kubernetes::repos', type: :class do
context 'with Debian and default params' do
let(:facts) do
{
osfamily: 'Debian', # needed to run dependent tests from fixtures puppetlabs-apt
kernel: 'Linux',
os: {
family: 'Debian',
name: 'Ubuntu',
release: {
full: '16.04'
},
distro: {
codename: 'xenial'
}
}
}
end
let(:params) do
{
'container_runtime' => 'docker',
'kubernetes_version' => '1.28.1',
'kubernetes_apt_location' => '',
'kubernetes_apt_release' => '',
'kubernetes_apt_repos' => '',
'kubernetes_key_id' => '',
'kubernetes_key_source' => '',
'kubernetes_yum_baseurl' => 'https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64',
'kubernetes_yum_gpgkey' => 'https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg',
'docker_apt_location' => 'https://download.docker.com/linux/ubuntu',
'docker_apt_release' => 'xenial',
'docker_apt_repos' => 'main',
'docker_yum_baseurl' => 'https://download.docker.com/linux/centos/7/x86_64/stable',
'docker_yum_gpgkey' => 'https://download.docker.com/linux/centos/gpg',
'docker_key_id' => '9DC858229FC7DD38854AE2D88D81803C0EBFCD88',
'docker_key_source' => 'https://download.docker.com/linux/ubuntu/gpg',
'containerd_install_method' => 'archive',
'create_repos' => true,
'manage_docker' => true
}
end

it {
expect(subject).to contain_apt__source('kubernetes').with(
ensure: 'present',
location: 'https://pkgs.k8s.io/core:/stable:/v1.28/deb',
repos: '/',
key: { 'id' => 'F46193FF99DBC56573C3B95949D205BA06FEF67C', 'source' => 'https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key' },
)
}

it {
expect(subject).to contain_apt__source('docker').with(
ensure: 'present',
location: 'https://download.docker.com/linux/ubuntu',
repos: 'main',
release: 'xenial',
key: { 'id' => '9DC858229FC7DD38854AE2D88D81803C0EBFCD88', 'source' => 'https://download.docker.com/linux/ubuntu/gpg' },
)
}
end

context 'with osfamily => Ubuntu and manage_docker => true' do
let(:facts) do
{
Expand All @@ -22,6 +83,7 @@
let(:params) do
{
'container_runtime' => 'docker',
'kubernetes_version' => '1.28.1',
'kubernetes_apt_location' => 'http://apt.kubernetes.io',
'kubernetes_apt_release' => 'kubernetes-xenial',
'kubernetes_apt_repos' => 'main',
Expand Down Expand Up @@ -83,6 +145,7 @@
let(:params) do
{
'container_runtime' => 'cri_containerd',
'kubernetes_version' => '1.28.1',
'kubernetes_apt_location' => 'http://apt.kubernetes.io',
'kubernetes_apt_release' => 'kubernetes-xenial',
'kubernetes_apt_repos' => 'main',
Expand Down Expand Up @@ -124,6 +187,58 @@
}
end

context 'with RedHat and default params' do
let(:facts) do
{
operatingsystem: 'RedHat',
osfamily: 'RedHat',
operatingsystemrelease: '7.0',
kernel: 'Linux',
os: {
family: 'RedHat',
name: 'RedHat',
release: {
full: '7.0'
}
}
}
end

let(:params) do
{
'container_runtime' => 'docker',
'kubernetes_version' => '1.28.1',
'kubernetes_apt_location' => '',
'kubernetes_apt_release' => '',
'kubernetes_apt_repos' => '',
'kubernetes_key_id' => '',
'kubernetes_key_source' => '',
'kubernetes_yum_baseurl' => '',
'kubernetes_yum_gpgkey' => '',
'docker_apt_location' => 'https://download.docker.com/linux/ubuntu',
'docker_apt_release' => 'xenial',
'docker_apt_repos' => 'main',
'docker_yum_baseurl' => 'https://download.docker.com/linux/centos/7/x86_64/stable',
'docker_yum_gpgkey' => 'https://download.docker.com/linux/centos/gpg',
'docker_key_id' => '9DC858229FC7DD38854AE2D88D81803C0EBFCD88',
'docker_key_source' => 'https://download.docker.com/linux/ubuntu/gpg',
'containerd_install_method' => 'archive',
'create_repos' => true,
'manage_docker' => false
}
end

it { is_expected.not_to contain_yumrepo('docker') }

it {
expect(subject).to contain_yumrepo('kubernetes').with(
'enabled' => '1',
'baseurl' => 'https://pkgs.k8s.io/core:/stable:/v1.28/rpm/',
'gpgkey' => 'https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key',
)
}
end

context 'with osfamily => RedHat and manage_epel => true and manage_docker => false' do
let(:facts) do
{
Expand All @@ -144,6 +259,7 @@
let(:params) do
{
'container_runtime' => 'docker',
'kubernetes_version' => '1.28.1',
'kubernetes_apt_location' => 'http://apt.kubernetes.io',
'kubernetes_apt_release' => 'kubernetes-xenial',
'kubernetes_apt_repos' => 'main',
Expand All @@ -165,7 +281,14 @@
end

it { is_expected.not_to contain_yumrepo('docker') }
it { is_expected.to contain_yumrepo('kubernetes') }

it {
expect(subject).to contain_yumrepo('kubernetes').with(
'enabled' => '1',
'baseurl' => 'https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64',
'gpgkey' => 'https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg',
)
}
end

context 'with osfamily => RedHat and container_runtime => cri_containerd and containerd_install_method => package' do
Expand All @@ -187,6 +310,7 @@

let(:params) do
{
'kubernetes_version' => '1.28.1',
'container_runtime' => 'cri_containerd',
'kubernetes_apt_location' => 'http://apt.kubernetes.io',
'kubernetes_apt_release' => 'kubernetes-xenial',
Expand All @@ -209,6 +333,13 @@
end

it { is_expected.to contain_yumrepo('docker') }
it { is_expected.to contain_yumrepo('kubernetes') }

it {
expect(subject).to contain_yumrepo('kubernetes').with(
'enabled' => '1',
'baseurl' => 'https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64',
'gpgkey' => 'https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg',
)
}
end
end

0 comments on commit 53b786c

Please sign in to comment.