From fddc79eb3dbfedd85d1ce551bd905debfe0a7d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=AF=9A?= Date: Mon, 27 May 2024 16:22:51 +0800 Subject: [PATCH 1/2] add check support k8s version --- cmd/kk/pkg/bootstrap/confirm/tasks.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/kk/pkg/bootstrap/confirm/tasks.go b/cmd/kk/pkg/bootstrap/confirm/tasks.go index 74227cb12..180f5bb29 100644 --- a/cmd/kk/pkg/bootstrap/confirm/tasks.go +++ b/cmd/kk/pkg/bootstrap/confirm/tasks.go @@ -21,8 +21,12 @@ import ( "fmt" "os" "regexp" + "slices" "strings" + versionK8S "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/version/kubernetes" + + kubekeyapiv1alpha2 "github.com/kubesphere/kubekey/v3/cmd/kk/apis/kubekey/v1alpha2" "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/common" "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/action" "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/connector" @@ -106,6 +110,26 @@ func (i *InstallationConfirm) Execute(runtime connector.Runtime) error { fmt.Println("https://github.com/kubesphere/kubekey#requirements-and-recommendations") fmt.Println("") + // check k8s version is supported + k8sVersion := i.KubeConf.Cluster.Kubernetes.Version + if k8sVersion != kubekeyapiv1alpha2.DefaultKubeVersion { + suppportVersions := versionK8S.SupportedK8sVersionList() + if !slices.ContainsFunc(suppportVersions, func(s string) bool { + return strings.Contains(s, k8sVersion) + }) { + fmt.Printf("The Kubernetes version :%s isn't support.\n", k8sVersion) + fmt.Println("Use kk version --show-supported-k8s, show support k8s versions") + fmt.Println("") + stopFlag = true + } else { + fmt.Println("Install k8s with specify version: ", k8sVersion) + fmt.Println("") + } + } else { + fmt.Println("Install k8s with default version: ", kubekeyapiv1alpha2.DefaultKubeVersion) + fmt.Println("") + } + if i.KubeConf.Cluster.Kubernetes.IsAtLeastV124() && i.KubeConf.Cluster.Kubernetes.ContainerManager == common.Docker { fmt.Println("[Notice]") fmt.Println("For Kubernetes v1.24 and later, dockershim has been deprecated.") From f4026ef85aebca78a0adb2a51cdbd57c22da2ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=AF=9A?= Date: Tue, 28 May 2024 12:10:40 +0800 Subject: [PATCH 2/2] use k8s.io/utils/strings/slices to replace builtin slices --- cmd/kk/pkg/bootstrap/confirm/tasks.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/kk/pkg/bootstrap/confirm/tasks.go b/cmd/kk/pkg/bootstrap/confirm/tasks.go index 180f5bb29..0e4da5508 100644 --- a/cmd/kk/pkg/bootstrap/confirm/tasks.go +++ b/cmd/kk/pkg/bootstrap/confirm/tasks.go @@ -21,7 +21,6 @@ import ( "fmt" "os" "regexp" - "slices" "strings" versionK8S "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/version/kubernetes" @@ -36,6 +35,7 @@ import ( "github.com/modood/table" "github.com/pkg/errors" versionutil "k8s.io/apimachinery/pkg/util/version" + "k8s.io/utils/strings/slices" ) // PreCheckResults defines the items to be checked. @@ -114,11 +114,12 @@ func (i *InstallationConfirm) Execute(runtime connector.Runtime) error { k8sVersion := i.KubeConf.Cluster.Kubernetes.Version if k8sVersion != kubekeyapiv1alpha2.DefaultKubeVersion { suppportVersions := versionK8S.SupportedK8sVersionList() - if !slices.ContainsFunc(suppportVersions, func(s string) bool { - return strings.Contains(s, k8sVersion) - }) { - fmt.Printf("The Kubernetes version :%s isn't support.\n", k8sVersion) - fmt.Println("Use kk version --show-supported-k8s, show support k8s versions") + if !strings.HasPrefix(k8sVersion, "v") { + k8sVersion = "v" + k8sVersion + } + if !slices.Contains(suppportVersions, k8sVersion) { + fmt.Printf("The Kubernetes version: %s isn't supported.\n", k8sVersion) + fmt.Println("Use kk version --show-supported-k8s,show supported k8s versions") fmt.Println("") stopFlag = true } else {