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

Migrate to the community-hosted package repositories (pkgs.k8s.io) and to dl.k8s.io #2873

Merged
merged 6 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions pkg/apis/kubeone/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,10 @@ func (c IPFamily) IsDualstack() bool {
func (c IPFamily) IsIPv6Primary() bool {
return c == IPFamilyIPv6 || c == IPFamilyIPv6IPv4
}

func (v VersionConfig) KubernetesMajorMinorVersion() string {
// Validation passed at this point so we know that version is valid
kubeSemVer := semver.MustParse(v.Kubernetes)

return fmt.Sprintf("v%d.%d", kubeSemVer.Major(), kubeSemVer.Minor())
}
26 changes: 22 additions & 4 deletions pkg/scripts/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ package scripts

import (
"github.com/MakeNowJust/heredoc/v2"
"github.com/Masterminds/semver/v3"

kubeoneapi "k8c.io/kubeone/pkg/apis/kubeone"
"k8c.io/kubeone/pkg/containerruntime"
"k8c.io/kubeone/pkg/fail"
)

const (
defaultKubernetesCNIVersion = "1.2.0"
defaultCriToolsVersion = "1.26.0"
)
const defaultKubernetesCNIVersion = "1.2.0"

var migrateToContainerdScriptTemplate = heredoc.Doc(`
sudo systemctl stop kubelet
Expand Down Expand Up @@ -71,3 +69,23 @@ func installISCSIAndNFS(cluster *kubeoneapi.KubeOneCluster) bool {
func ciliumCNI(cluster *kubeoneapi.KubeOneCluster) bool {
return cluster.ClusterNetwork.CNI != nil && cluster.ClusterNetwork.CNI.Cilium != nil
}

func criToolsVersion(cluster *kubeoneapi.KubeOneCluster) string {
// Validation passed at this point so we know that version is valid
kubeSemVer := semver.MustParse(cluster.Versions.Kubernetes)

switch kubeSemVer.Minor() {
case 24:
fallthrough
case 25:
fallthrough
case 26:
return "1.26.0"
case 27:
return "1.27.1"
case 28:
fallthrough
default:
return "1.28.0"
}
}
28 changes: 22 additions & 6 deletions pkg/scripts/os_amzn.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,28 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf

{{ if .CONFIGURE_REPOSITORIES }}
# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
baseurl=https://pkgs.k8s.io/core:/stable:/{{ .KUBERNETES_MAJOR_MINOR }}/rpm/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
gpgkey=https://pkgs.k8s.io/core:/stable:/{{ .KUBERNETES_MAJOR_MINOR }}/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
{{ end }}

sudo yum install -y \
Expand Down Expand Up @@ -205,8 +218,9 @@ func KubeadmAmazonLinux(cluster *kubeoneapi.KubeOneCluster, force bool) (string,
"CNI_URL": cluster.AssetConfiguration.CNI.URL,
"KUBECTL_URL": cluster.AssetConfiguration.Kubectl.URL,
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_MAJOR_MINOR": cluster.Versions.KubernetesMajorMinorVersion(),
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"CONFIGURE_REPOSITORIES": cluster.SystemPackages.ConfigureRepositories,
"PROXY": proxy,
"FORCE": force,
Expand Down Expand Up @@ -244,8 +258,9 @@ func UpgradeKubeadmAndCNIAmazonLinux(cluster *kubeoneapi.KubeOneCluster) (string
"NODE_BINARIES_URL": cluster.AssetConfiguration.NodeBinaries.URL,
"CNI_URL": cluster.AssetConfiguration.CNI.URL,
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_MAJOR_MINOR": cluster.Versions.KubernetesMajorMinorVersion(),
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"CONFIGURE_REPOSITORIES": cluster.SystemPackages.ConfigureRepositories,
"PROXY": proxy,
"INSTALL_DOCKER": cluster.ContainerRuntime.Docker,
Expand Down Expand Up @@ -277,8 +292,9 @@ func UpgradeKubeletAndKubectlAmazonLinux(cluster *kubeoneapi.KubeOneCluster) (st
"NODE_BINARIES_URL": cluster.AssetConfiguration.NodeBinaries.URL,
"KUBECTL_URL": cluster.AssetConfiguration.Kubectl.URL,
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_MAJOR_MINOR": cluster.Versions.KubernetesMajorMinorVersion(),
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"CONFIGURE_REPOSITORIES": cluster.SystemPackages.ConfigureRepositories,
"PROXY": proxy,
"INSTALL_DOCKER": cluster.ContainerRuntime.Docker,
Expand Down
28 changes: 22 additions & 6 deletions pkg/scripts/os_centos.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,34 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf

{{ if .CONFIGURE_REPOSITORIES }}
# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
baseurl=https://pkgs.k8s.io/core:/stable:/{{ .KUBERNETES_MAJOR_MINOR }}/rpm/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
gpgkey=https://pkgs.k8s.io/core:/stable:/{{ .KUBERNETES_MAJOR_MINOR }}/rpm/repodata/repomd.xml.key
EOF

source /etc/os-release
if [ "$ID" == "centos" ] && [ "$VERSION_ID" == "8" ]; then
sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
fi

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi
{{ end }}

sudo yum install -y \
Expand Down Expand Up @@ -143,8 +156,9 @@ func KubeadmCentOS(cluster *kubeoneapi.KubeOneCluster, force bool) (string, erro
"KUBEADM": true,
"KUBECTL": true,
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_MAJOR_MINOR": cluster.Versions.KubernetesMajorMinorVersion(),
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"CONFIGURE_REPOSITORIES": cluster.SystemPackages.ConfigureRepositories,
"PROXY": proxy,
"FORCE": force,
Expand Down Expand Up @@ -180,8 +194,9 @@ func UpgradeKubeadmAndCNICentOS(cluster *kubeoneapi.KubeOneCluster) (string, err
"UPGRADE": true,
"KUBEADM": true,
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_MAJOR_MINOR": cluster.Versions.KubernetesMajorMinorVersion(),
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"CONFIGURE_REPOSITORIES": cluster.SystemPackages.ConfigureRepositories,
"PROXY": proxy,
"INSTALL_DOCKER": cluster.ContainerRuntime.Docker,
Expand Down Expand Up @@ -211,8 +226,9 @@ func UpgradeKubeletAndKubectlCentOS(cluster *kubeoneapi.KubeOneCluster) (string,
"KUBELET": true,
"KUBECTL": true,
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_MAJOR_MINOR": cluster.Versions.KubernetesMajorMinorVersion(),
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"CONFIGURE_REPOSITORIES": cluster.SystemPackages.ConfigureRepositories,
"PROXY": proxy,
"INSTALL_DOCKER": cluster.ContainerRuntime.Docker,
Expand Down
15 changes: 8 additions & 7 deletions pkg/scripts/os_debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ sudo systemctl enable --now iscsid
{{- end }}

{{- if .CONFIGURE_REPOSITORIES }}
curl -fsSL https://dl.k8s.io/apt/doc/apt-key.gpg | sudo apt-key add -
curl -fsSL https://pkgs.k8s.io/core:/stable:/{{ .KUBERNETES_MAJOR_MINOR }}/deb/Release.key | sudo apt-key add -

# You'd think that kubernetes-$(lsb_release -sc) belongs there instead, but the debian repo
# contains neither kubeadm nor kubelet, and the docs themselves suggest using xenial repo.
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
echo "deb https://pkgs.k8s.io/core:/stable:/{{ .KUBERNETES_MAJOR_MINOR }}/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update
{{- end }}
Expand Down Expand Up @@ -134,8 +132,9 @@ func KubeadmDebian(cluster *kubeoneapi.KubeOneCluster, force bool) (string, erro
"KUBEADM": true,
"KUBECTL": true,
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_MAJOR_MINOR": cluster.Versions.KubernetesMajorMinorVersion(),
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"CONFIGURE_REPOSITORIES": cluster.SystemPackages.ConfigureRepositories,
"HTTP_PROXY": cluster.Proxy.HTTP,
"HTTPS_PROXY": cluster.Proxy.HTTPS,
Expand Down Expand Up @@ -167,8 +166,9 @@ func UpgradeKubeadmAndCNIDebian(cluster *kubeoneapi.KubeOneCluster) (string, err
"UPGRADE": true,
"KUBEADM": true,
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_MAJOR_MINOR": cluster.Versions.KubernetesMajorMinorVersion(),
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"CONFIGURE_REPOSITORIES": cluster.SystemPackages.ConfigureRepositories,
"HTTP_PROXY": cluster.Proxy.HTTP,
"HTTPS_PROXY": cluster.Proxy.HTTPS,
Expand All @@ -194,8 +194,9 @@ func UpgradeKubeletAndKubectlDebian(cluster *kubeoneapi.KubeOneCluster) (string,
"KUBELET": true,
"KUBECTL": true,
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_MAJOR_MINOR": cluster.Versions.KubernetesMajorMinorVersion(),
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"CONFIGURE_REPOSITORIES": cluster.SystemPackages.ConfigureRepositories,
"HTTP_PROXY": cluster.Proxy.HTTP,
"HTTPS_PROXY": cluster.Proxy.HTTPS,
Expand Down
8 changes: 4 additions & 4 deletions pkg/scripts/os_flatcar.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ curl -L https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRI_TOO
{{ end }}

cd /opt/bin
k8s_rel_baseurl=https://storage.googleapis.com/kubernetes-release/release
k8s_rel_baseurl=https://dl.k8s.io
for binary in kubeadm kubelet kubectl; do
curl -L --output /tmp/$binary \
$k8s_rel_baseurl/${RELEASE}/bin/linux/${HOST_ARCH}/$binary
Expand Down Expand Up @@ -125,7 +125,7 @@ RELEASE="v{{ .KUBERNETES_VERSION }}"
sudo mkdir -p /var/tmp/kube-binaries
cd /var/tmp/kube-binaries
sudo curl -L --remote-name-all \
https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/${HOST_ARCH}/kubeadm
https://dl.k8s.io/${RELEASE}/bin/linux/${HOST_ARCH}/kubeadm

sudo mkdir -p /opt/bin
cd /opt/bin
Expand All @@ -150,7 +150,7 @@ RELEASE="v{{ .KUBERNETES_VERSION }}"
sudo mkdir -p /var/tmp/kube-binaries
cd /var/tmp/kube-binaries
sudo curl -L --remote-name-all \
https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/${HOST_ARCH}/{kubelet,kubectl}
https://dl.k8s.io/${RELEASE}/bin/linux/${HOST_ARCH}/{kubelet,kubectl}
sudo mkdir -p /opt/bin
cd /opt/bin
sudo systemctl stop kubelet
Expand Down Expand Up @@ -197,7 +197,7 @@ func KubeadmFlatcar(cluster *kubeoneapi.KubeOneCluster) (string, error) {
data := Data{
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
"CRITOOLS_VERSION": defaultCriToolsVersion,
"CRITOOLS_VERSION": criToolsVersion(cluster),
"INSTALL_DOCKER": cluster.ContainerRuntime.Docker,
"INSTALL_CONTAINERD": cluster.ContainerRuntime.Containerd,
"CILIUM": ciliumCNI(cluster),
Expand Down
19 changes: 16 additions & 3 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-force.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,29 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
baseurl=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi


sudo yum install -y \
yum-plugin-versionlock \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,29 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
baseurl=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi


sudo yum install -y \
yum-plugin-versionlock \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,29 @@ echo -n "${yum_proxy}" >> /tmp/yum.conf
sudo mv /tmp/yum.conf /etc/yum.conf


# Rebuilding the yum cache is required upon migrating from the legacy to the community-owned
# repositories, otherwise, yum will fail to upgrade the packages because it's trying to
# use old revisions (e.g. 1.27.0-0 instead of 1.27.5-150500.1.1).
repo_migration_needed=false

if sudo grep -q "packages.cloud.google.com" /etc/yum.repos.d/kubernetes.repo; then
repo_migration_needed=true
fi

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
baseurl=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.26/rpm/repodata/repomd.xml.key
EOF

if [[ $repo_migration_needed == "true" ]]; then
sudo yum clean all
sudo yum makecache
fi


sudo yum install -y \
yum-plugin-versionlock \
Expand Down
Loading