Skip to content

Commit

Permalink
Merge pull request #694 from span786/CAT-2193-fix-puppetlabs-kubernet…
Browse files Browse the repository at this point in the history
…es-nightly-for-debian

(CAT-2193): Fixed kubernetes environment setup for Debian.
  • Loading branch information
span786 authored Jan 15, 2025
2 parents 689d78b + 0cc4f36 commit 19bfbd8
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix: {'platform':['rhel-8'],'collection':['puppet7-nightly', 'puppet8-nightly']}
matrix: {'platform':['rhel-8', 'debian-11'],'collection':['puppet7-nightly', 'puppet8-nightly']}

steps:
- name: Checkout Source
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix: {'platform':['rhel-8'],'collection':['puppet7-nightly', 'puppet8-nightly']}
matrix: {'platform':['rhel-8', 'debian-11'],'collection':['puppet7-nightly', 'puppet8-nightly']}

steps:
- name: Checkout Source
Expand Down
2 changes: 2 additions & 0 deletions data/os/debian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kubernetes::kubernetes_apt_location: 'https://pkgs.k8s.io/core:/stable:'
kubernetes::docker_apt_location: 'https://download.docker.com/linux'
2 changes: 2 additions & 0 deletions data/os/rhel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kubernetes::kubernetes_yum_baseurl: 'https://pkgs.k8s.io/core:/stable:'
kubernetes::docker_yum_baseurl: 'https://download.docker.com/linux'
6 changes: 3 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,14 @@
#
#
class kubernetes (
String $kubernetes_version = '1.10.2',
String $kubernetes_version = '1.32.0',
String $kubernetes_cluster_name = 'kubernetes',
String $kubernetes_package_version = $facts['os']['family'] ? {
'Debian' => "${kubernetes_version}-00",
'RedHat' => $kubernetes::kubernetes_version,
},
String $container_runtime = 'docker',
String $containerd_version = '1.4.3',
String $containerd_version = '1.6.12',
Enum['archive','package'] $containerd_install_method = 'archive',
String $containerd_package_name = 'containerd.io',
String $docker_package_name = 'docker-engine',
Expand All @@ -625,7 +625,7 @@
Boolean $manage_etcd = true,
Integer $kube_api_bind_port = 6443,
Optional[String] $kube_api_advertise_address = undef,
String $etcd_version = '3.2.18',
String $etcd_version = '3.4.13',
Optional[String] $etcd_hostname = $facts['networking']['hostname'],
String $etcd_data_dir = '/var/lib/etcd',
Optional[String] $etcd_ip = undef,
Expand Down
30 changes: 17 additions & 13 deletions manifests/repos.pp
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,33 @@
Boolean $manage_docker = $kubernetes::manage_docker,
Boolean $create_repos = $kubernetes::create_repos,

) {
) inherits kubernetes {
if $create_repos {
$k8s_core_package_version = kubernetes::kubernetes_version.split('.')[0,1].join('.')
case $facts['os']['family'] {
'Debian': {
$codename = fact('os.distro.codename')
$k8s_apt_location = "${kubernetes::kubernetes_apt_location}/v${k8s_core_package_version}"
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, "${k8s_apt_location}/deb/"),
repos => pick($kubernetes_apt_repos, ' '),
release => pick($kubernetes_apt_release, ' /'),
comment => 'Kubernetes',
key => {
'id' => pick($kubernetes_key_id, 'A362B822F6DEDC652817EA46B53DC80D13EDEF05'),
'source' => pick($kubernetes_key_source, 'https://packages.cloud.google.com/apt/doc/apt-key.gpg'),
'name' => 'kubernetes-apt-keyring.gpg',
'source' => pick($kubernetes_key_source, "${$k8s_apt_location}/deb/Release.key"),
},
}

if ($container_runtime == 'docker' and $manage_docker == true) or
($container_runtime == 'cri_containerd' and $containerd_install_method == 'package') {
apt::source { 'docker':
location => pick($docker_apt_location, 'https://download.docker.com/linux/ubuntu/'),
location => pick($docker_apt_location, "${$kubernetes::docker_apt_location}/debian/"),
repos => pick($docker_apt_repos, 'stable'),
release => pick($docker_apt_release,$codename),
release => pick($docker_apt_release, $codename),
key => {
'id' => pick($docker_key_id, '9DC858229FC7DD38854AE2D88D81803C0EBFCD88'),
'source' => pick($docker_key_source, 'https://download.docker.com/linux/ubuntu/gpg'),
'source' => pick($docker_key_source, "${$kubernetes::docker_apt_location}/debian/gpg"),
},
}
}
Expand All @@ -91,16 +94,17 @@
($container_runtime == 'cri_containerd' and $containerd_install_method == 'package') {
yumrepo { 'docker':
descr => 'docker',
baseurl => pick($docker_yum_baseurl, 'https://download.docker.com/linux/centos/7/x86_64/stable'),
gpgkey => pick($docker_yum_gpgkey, 'https://download.docker.com/linux/centos/gpg'),
baseurl => pick($docker_yum_baseurl, "${kubernetes::docker_yum_baseurl}/rhel/8/x86_64/stable/"),
gpgkey => pick($docker_yum_gpgkey, "${kubernetes::docker_yum_baseurl}/rhel/gpg"),
gpgcheck => true,
}
}

$k8s_yum_location = "${kubernetes::kubernetes_yum_baseurl}/v${k8s_core_package_version}"
yumrepo { 'kubernetes':
descr => 'Kubernetes',
baseurl => pick($kubernetes_yum_baseurl, 'https://pkgs.k8s.io/core:/stable:/v1.28/rpm/'),
gpgkey => pick($kubernetes_yum_gpgkey, 'https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key'),
baseurl => pick($kubernetes_yum_baseurl, "${k8s_yum_location}/rpm/"),
gpgkey => pick($kubernetes_yum_gpgkey, "${k8s_yum_location}/rpm/repodata/repomd.xml.key"),
gpgcheck => true,
}
}
Expand Down
20 changes: 14 additions & 6 deletions spec/acceptance/kubernetes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
class {'kubernetes':
kubernetes_version => '1.28.15',
kubernetes_package_version => '1.28.15',
kubernetes_yum_baseurl => 'https://pkgs.k8s.io/core:/stable:/v1.28/rpm/',
kubernetes_yum_gpgkey => 'https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key',
controller_address => "#{int_ipaddr1}:6443",
container_runtime => 'docker',
manage_docker => false,
Expand All @@ -30,12 +32,18 @@ class {'kubernetes':
}
}
/^(Debian|Ubuntu)$/: {
class {'kubernetes':
controller => true,
schedule_on_controller => true,
environment => ['HOME=/root', 'KUBECONFIG=/etc/kubernetes/admin.conf'],
ignore_preflight_errors => ['NumCPU'],
}
class {'kubernetes':
kubernetes_version => '1.28.15',
kubernetes_package_version => '1.28.15-1.1',
kubernetes_apt_location => 'https://pkgs.k8s.io/core:/stable:/v1.28/deb/',
kubernetes_apt_repos => ' ',
kubernetes_apt_release => ' /',
kubernetes_key_source => 'https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key',
controller => true,
schedule_on_controller => true,
environment => ['HOME=/root', 'KUBECONFIG=/etc/kubernetes/admin.conf'],
ignore_preflight_errors => ['NumCPU','ExternalEtcdVersion'],
}
}
default: {
class {'kubernetes': } # any other OS are not supported
Expand Down
3 changes: 0 additions & 3 deletions spec/classes/config/kubeadm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
it { is_expected.not_to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{foo:\n- bar\n- baz}) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{kubeletConfiguration:\n baseConfig:\n baz:\n - bar\n - foo}) }

context 'with etcd_listen_metric_urls defined' do
let(:params) do
Expand Down Expand Up @@ -113,7 +112,6 @@
it { is_expected.not_to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{foo:\n- bar\n- baz}) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{kubeletConfiguration:\n baseConfig:\n baz:\n - bar\n - foo}) }
end

context 'with manage_etcd => false' do
Expand Down Expand Up @@ -146,7 +144,6 @@
it { is_expected.not_to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{foo:\n- bar\n- baz}) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{kubeletConfiguration:\n baseConfig:\n baz:\n - bar\n - foo}) }
end

context 'manage_etcd => true and etcd_install_method => package' do
Expand Down
3 changes: 2 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
context 'with worker => true and version => 1.10.2' do
let(:params) do
{
worker: true
worker: true,
kubernetes_version: '1.10.2'
}
end

Expand Down
56 changes: 28 additions & 28 deletions spec/classes/repos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
let(:params) do
{
'container_runtime' => 'docker',
'kubernetes_apt_location' => 'http://apt.kubernetes.io',
'kubernetes_apt_release' => 'kubernetes-xenial',
'kubernetes_apt_repos' => 'main',
'kubernetes_apt_location' => 'https://pkgs.k8s.io/core:/stable:/v1.32/deb/',
'kubernetes_apt_release' => ' /',
'kubernetes_apt_repos' => ' ',
'kubernetes_key_id' => '54A647F9048D5688D7DA2ABE6A030B21BA07F4FB',
'kubernetes_key_source' => 'https://packages.cloud.google.com/apt/doc/apt-key.gpg',
'kubernetes_key_source' => 'https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key',
'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_location' => 'https://download.docker.com/linux/debian',
'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_yum_baseurl' => 'https://download.docker.com/linux/rhel/8/x86_64/stable',
'docker_yum_gpgkey' => 'https://download.docker.com/linux/rhel/gpg',
'docker_key_id' => '9DC858229FC7DD38854AE2D88D81803C0EBFCD88',
'docker_key_source' => 'https://download.docker.com/linux/ubuntu/gpg',
'docker_key_source' => 'https://download.docker.com/linux/debian/gpg',
'containerd_install_method' => 'archive',
'create_repos' => true,
'manage_docker' => true
Expand All @@ -45,20 +45,20 @@
it {
expect(subject).to contain_apt__source('kubernetes').with(
ensure: 'present',
location: 'http://apt.kubernetes.io',
repos: 'main',
release: 'kubernetes-xenial',
key: { 'id' => '54A647F9048D5688D7DA2ABE6A030B21BA07F4FB', 'source' => 'https://packages.cloud.google.com/apt/doc/apt-key.gpg' },
location: 'https://pkgs.k8s.io/core:/stable:/v1.32/deb/',
repos: ' ',
release: ' /',
key: { 'name' => 'kubernetes-apt-keyring.gpg', 'source' => 'https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key' },
)
}

it {
expect(subject).to contain_apt__source('docker').with(
ensure: 'present',
location: 'https://download.docker.com/linux/ubuntu',
location: 'https://download.docker.com/linux/debian',
repos: 'main',
release: 'xenial',
key: { 'id' => '9DC858229FC7DD38854AE2D88D81803C0EBFCD88', 'source' => 'https://download.docker.com/linux/ubuntu/gpg' },
key: { 'id' => '9DC858229FC7DD38854AE2D88D81803C0EBFCD88', 'source' => 'https://download.docker.com/linux/debian/gpg' },
)
}
end
Expand All @@ -83,20 +83,20 @@
let(:params) do
{
'container_runtime' => 'cri_containerd',
'kubernetes_apt_location' => 'http://apt.kubernetes.io',
'kubernetes_apt_release' => 'kubernetes-xenial',
'kubernetes_apt_repos' => 'main',
'kubernetes_apt_location' => 'https://pkgs.k8s.io/core:/stable:/v1.32/deb/',
'kubernetes_apt_release' => ' /',
'kubernetes_apt_repos' => ' ',
'kubernetes_key_id' => '54A647F9048D5688D7DA2ABE6A030B21BA07F4FB',
'kubernetes_key_source' => 'https://packages.cloud.google.com/apt/doc/apt-key.gpg',
'kubernetes_key_source' => 'https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key',
'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_location' => 'https://download.docker.com/linux/debian',
'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_yum_baseurl' => 'https://download.docker.com/linux/rhel/8/x86_64/stable',
'docker_yum_gpgkey' => 'https://download.docker.com/linux/rhel/gpg',
'docker_key_id' => '9DC858229FC7DD38854AE2D88D81803C0EBFCD88',
'docker_key_source' => 'https://download.docker.com/linux/ubuntu/gpg',
'docker_key_source' => 'https://download.docker.com/linux/debian/gpg',
'containerd_install_method' => 'package',
'create_repos' => true,
'manage_docker' => true
Expand All @@ -106,20 +106,20 @@
it {
expect(subject).to contain_apt__source('kubernetes').with(
ensure: 'present',
location: 'http://apt.kubernetes.io',
repos: 'main',
release: 'kubernetes-xenial',
key: { 'id' => '54A647F9048D5688D7DA2ABE6A030B21BA07F4FB', 'source' => 'https://packages.cloud.google.com/apt/doc/apt-key.gpg' },
location: 'https://pkgs.k8s.io/core:/stable:/v1.32/deb/',
repos: ' ',
release: ' /',
key: { 'name' => 'kubernetes-apt-keyring.gpg', 'source' => 'https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key' },
)
}

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

0 comments on commit 19bfbd8

Please sign in to comment.