diff --git a/pkg/apis/kubeone/helpers.go b/pkg/apis/kubeone/helpers.go index 30ed6347c..401be0529 100644 --- a/pkg/apis/kubeone/helpers.go +++ b/pkg/apis/kubeone/helpers.go @@ -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()) +} diff --git a/pkg/scripts/os.go b/pkg/scripts/os.go index a9e2ad86f..fa341500c 100644 --- a/pkg/scripts/os.go +++ b/pkg/scripts/os.go @@ -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 @@ -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" + } +} diff --git a/pkg/scripts/os_amzn.go b/pkg/scripts/os_amzn.go index bffae1868..77be93b9c 100644 --- a/pkg/scripts/os_amzn.go +++ b/pkg/scripts/os_amzn.go @@ -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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <> /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 <