From fcd52f828dce37f0177cc5bbe578f4b72532dc72 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Fri, 22 Sep 2023 09:34:40 +0200 Subject: [PATCH] Switch to repos to maintaned pkgs.k8s.io --- manifests/repos.pp | 22 +++-- spec/acceptance/kubernetes_spec.rb | 4 +- spec/classes/repos_spec.rb | 135 ++++++++++++++++++++++++++++- 3 files changed, 149 insertions(+), 12 deletions(-) diff --git a/manifests/repos.pp b/manifests/repos.pp index b6fbc63f..5de55e97 100644 --- a/manifests/repos.pp +++ b/manifests/repos.pp @@ -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 @@ -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, @@ -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,'DE15B14486CD377B9E876E1A234654DA9A296436'), + 'source' => pick($kubernetes_key_source,"https://pkgs.k8s.io/core:/stable:/v${minor_version}/deb/Release.key"), }, } @@ -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, } } diff --git a/spec/acceptance/kubernetes_spec.rb b/spec/acceptance/kubernetes_spec.rb index ad3ac867..71486ea4 100644 --- a/spec/acceptance/kubernetes_spec.rb +++ b/spec/acceptance/kubernetes_spec.rb @@ -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, diff --git a/spec/classes/repos_spec.rb b/spec/classes/repos_spec.rb index 027cc9e0..ae6eebcc 100644 --- a/spec/classes/repos_spec.rb +++ b/spec/classes/repos_spec.rb @@ -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' => 'DE15B14486CD377B9E876E1A234654DA9A296436', '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 { @@ -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', @@ -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', @@ -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 { @@ -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', @@ -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 @@ -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', @@ -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