Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to repos to maintaned pkgs.k8s.io #657

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Switch to repos to maintaned pkgs.k8s.io
deric committed Jun 27, 2024
commit 54dc7afec995a196f2b3407843d2e0934f211bab
22 changes: 14 additions & 8 deletions manifests/repos.pp
Original file line number Diff line number Diff line change
@@ -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"),
release => pick($kubernetes_apt_release, '/'),
repos => $kubernetes_apt_repos,
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,
}
}

4 changes: 2 additions & 2 deletions spec/acceptance/kubernetes_spec.rb
Original file line number Diff line number Diff line change
@@ -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',
Comment on lines +19 to +20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As 1.29.2 is already out by now this probably should get updated to that new version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this is just version for tests. The point was to update the version, that is available in the new repos. We should definitely update the default version, because the current value is 1.10.2.

controller_address => "#{int_ipaddr1}:6443",
container_runtime => 'docker',
manage_docker => false,
135 changes: 133 additions & 2 deletions spec/classes/repos_spec.rb
Original file line number Diff line number Diff line change
@@ -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'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should perhaps also get updated to a newer version like 22.04, as 24.04 will soon be released, 16.04 is long EOL now and it doesn't help me at all, if it works on some ancient release, but not a current one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has nothing to do with newer distributions. Google was releasing all packages under xenial codename because the binary packages weren't dependent any specific distribution.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know that everything was released under the kubernetes-xenial distribution (release in puppet), but I am not completely mistaken this is what got removed as default in https://github.com/puppetlabs/puppetlabs-kubernetes/pull/657/files#diff-b27acae942df5d6ec2b58798add49fff0f625bec33093d74ea3cb1ac39fd0c6aL69, https://github.com/puppetlabs/puppetlabs-kubernetes/pull/657/files#diff-6ff1ce06229c83037f537d2d0cb33aeba339e8fe801238cfb51c2f538c01c114L26 and tested against in https://github.com/puppetlabs/puppetlabs-kubernetes/pull/657/files#diff-6ff1ce06229c83037f537d2d0cb33aeba339e8fe801238cfb51c2f538c01c114L50
but the standalone xenial should refer to the distro, not the kubernetes-repo.

}
}
}
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',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: CentOS 7 / RHEL 7 will soon be EOL - CentOS Stream 9 / RHEL 9 have been out for almost 2 years now. For sure it would be good, if it still works on older releases, but people should be moving away from them anyway and ensuring that it works on newer versions is crucial to not hold people back and force them to stick with increasingly insecure OS versions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've copy pasted those tests. But these test are garbage in & garbage out tests. It doesn't actually test these distributions. It only tests string getting passed to the class, that it gets propagated. Actual tests should be written in acceptance tests.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure, you take some (more or less arbitrary base os) and then test, if 1. If you don't specify a specific repository, it now correctly defaults to the new repo and 2. If you override it with something (e.g. the old repo), it still includes the specified repo as desired, to e.g. still use the old repo for whatever reason.

As this could in theory be OS version dependent, this should in my opinion be tested on one recent release (Ubuntu 22.04 (as you changed it now - thank you!) or Debian 12 and CentOS Stream 9 / RHEL 9) and optionally additionally on some older version as well.

https://github.com/puppetlabs/puppetlabs-kubernetes/pull/657/files#diff-6ff1ce06229c83037f537d2d0cb33aeba339e8fe801238cfb51c2f538c01c114R5-R70 does 1. as far as I understand it: when testing on (now) Ubuntu 22.04 with Kubernetes version 1.28, no additional kubernetes_apt_* and for whatever reason questionable kubernetes_yum_* config, it correctly set's the apt source to the new 1.28 repo.
https://github.com/puppetlabs/puppetlabs-kubernetes/pull/657/files#diff-6ff1ce06229c83037f537d2d0cb33aeba339e8fe801238cfb51c2f538c01c114R71-R132 does 2., testing that on a Debian-based distro when overriding the repo, it set's it to the override.

https://github.com/puppetlabs/puppetlabs-kubernetes/pull/657/files#diff-6ff1ce06229c83037f537d2d0cb33aeba339e8fe801238cfb51c2f538c01c114R195-R246 tests 1., that on CentOS 7 the new default works.
https://github.com/puppetlabs/puppetlabs-kubernetes/pull/657/files#diff-6ff1ce06229c83037f537d2d0cb33aeba339e8fe801238cfb51c2f538c01c114L127-R297 tests 2., that the override works for CentOS 7, while still configuring some questionable apt stuff, that should be absolutely irrelevant on dnf-based distros.

And finally https://github.com/puppetlabs/puppetlabs-kubernetes/pull/657/files#diff-6ff1ce06229c83037f537d2d0cb33aeba339e8fe801238cfb51c2f538c01c114L127-R297 does 2. again on CentOS 7, but now with packaged containerd instead of docker archives.

'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',
release: '/',
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',
Comment on lines +200 to +226

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

'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