add support for checking github k8s versions
parent
820d14aeea
commit
54d1939b9b
|
|
@ -17,6 +17,10 @@ limitations under the License.
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/google/go-github/github"
|
||||||
"golang.org/x/mod/semver"
|
"golang.org/x/mod/semver"
|
||||||
"k8s.io/minikube/pkg/minikube/constants"
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
)
|
)
|
||||||
|
|
@ -34,3 +38,29 @@ func supportedKubernetesVersions() (releases []string) {
|
||||||
}
|
}
|
||||||
return releases
|
return releases
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGithubKubernetesVersions returns reverse-sort Kubernetes releases
|
||||||
|
func GetGithubKubernetesVersions(ver string) ([]string, error) {
|
||||||
|
ghc := github.NewClient(nil)
|
||||||
|
|
||||||
|
opts := &github.ListOptions{PerPage: 100}
|
||||||
|
var releases []string
|
||||||
|
for {
|
||||||
|
rls, resp, err := ghc.Repositories.ListReleases(context.Background(), "kubernetes", "kubernetes", opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, rl := range rls {
|
||||||
|
tag := rl.GetTagName()
|
||||||
|
if semver.IsValid(tag) {
|
||||||
|
releases = append(releases, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if resp.NextPage == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
opts.Page = resp.NextPage
|
||||||
|
}
|
||||||
|
sort.Slice(releases, func(i, j int) bool { return semver.Compare(releases[i], releases[j]) == -1 })
|
||||||
|
return releases, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1771,6 +1771,21 @@ func validateKubernetesVersion(old *config.ClusterConfig) {
|
||||||
}
|
}
|
||||||
if nvs.GT(newestVersion) {
|
if nvs.GT(newestVersion) {
|
||||||
out.WarningT("Specified Kubernetes version {{.specified}} is newer than the newest supported version: {{.newest}}. Use `minikube config defaults kubernetes-version` for details.", out.V{"specified": nvs, "newest": constants.NewestKubernetesVersion})
|
out.WarningT("Specified Kubernetes version {{.specified}} is newer than the newest supported version: {{.newest}}. Use `minikube config defaults kubernetes-version` for details.", out.V{"specified": nvs, "newest": constants.NewestKubernetesVersion})
|
||||||
|
if contains(constants.ValidKubernetesVersions, kubernetesVer) {
|
||||||
|
out.Styled(style.Check, "Kubernetes version {{.specified}} found in version list", out.V{"specified": nvs})
|
||||||
|
} else {
|
||||||
|
out.WarningT("Specified Kubernetes version {{.specified}} not found in Kubernetes version list. Searching the internet...", out.V{"specified": nvs})
|
||||||
|
k8sVersions, err := cmdcfg.GetGithubKubernetesVersions(kubernetesVer)
|
||||||
|
if err != nil && !viper.GetBool(force) {
|
||||||
|
exit.Error(reason.KubernetesNotConnect, "error fetching Kubernetes version list from Github", err)
|
||||||
|
}
|
||||||
|
if k8sVersions != nil && contains(k8sVersions, kubernetesVer) {
|
||||||
|
out.Styled(style.Check, "Kubernetes version {{.specified}} found in Github version list", out.V{"specified": nvs})
|
||||||
|
} else if !viper.GetBool(force) {
|
||||||
|
out.WarningT("Kubernetes version not found in Github version list. You can force a Kubernetes version via the --force flag")
|
||||||
|
exitIfNotForced(reason.KubernetesTooNew, "Kubernetes {{.version}} is not supported by this release of minikube", out.V{"version": nvs})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if nvs.LT(oldestVersion) {
|
if nvs.LT(oldestVersion) {
|
||||||
out.WarningT("Specified Kubernetes version {{.specified}} is less than the oldest supported version: {{.oldest}}. Use `minikube config defaults kubernetes-version` for details.", out.V{"specified": nvs, "oldest": constants.OldestKubernetesVersion})
|
out.WarningT("Specified Kubernetes version {{.specified}} is less than the oldest supported version: {{.oldest}}. Use `minikube config defaults kubernetes-version` for details.", out.V{"specified": nvs, "oldest": constants.OldestKubernetesVersion})
|
||||||
|
|
@ -2007,3 +2022,14 @@ func isTwoDigitSemver(ver string) bool {
|
||||||
majorMinorOnly := regexp.MustCompile(`^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)$`)
|
majorMinorOnly := regexp.MustCompile(`^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)$`)
|
||||||
return majorMinorOnly.MatchString(ver)
|
return majorMinorOnly.MatchString(ver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// contains checks whether the parameter slice contains the parameter string
|
||||||
|
func contains(sl []string, s string) bool {
|
||||||
|
for _, k := range sl {
|
||||||
|
if s == k {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
||||||
1
go.mod
1
go.mod
|
|
@ -86,6 +86,7 @@ require (
|
||||||
github.com/blang/semver v3.5.1+incompatible
|
github.com/blang/semver v3.5.1+incompatible
|
||||||
github.com/docker/cli v24.0.2+incompatible
|
github.com/docker/cli v24.0.2+incompatible
|
||||||
github.com/docker/go-connections v0.4.0
|
github.com/docker/go-connections v0.4.0
|
||||||
|
github.com/google/go-github v17.0.0+incompatible
|
||||||
github.com/google/go-github/v53 v53.2.0
|
github.com/google/go-github/v53 v53.2.0
|
||||||
github.com/juju/clock v1.0.3
|
github.com/juju/clock v1.0.3
|
||||||
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b
|
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b
|
||||||
|
|
|
||||||
1
go.sum
1
go.sum
|
|
@ -834,6 +834,7 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
|
||||||
github.com/google/go-containerregistry v0.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0=
|
github.com/google/go-containerregistry v0.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0=
|
||||||
github.com/google/go-containerregistry v0.15.2 h1:MMkSh+tjSdnmJZO7ljvEqV1DjfekB6VUEAZgy3a+TQE=
|
github.com/google/go-containerregistry v0.15.2 h1:MMkSh+tjSdnmJZO7ljvEqV1DjfekB6VUEAZgy3a+TQE=
|
||||||
github.com/google/go-containerregistry v0.15.2/go.mod h1:wWK+LnOv4jXMM23IT/F1wdYftGWGr47Is8CG+pmHK1Q=
|
github.com/google/go-containerregistry v0.15.2/go.mod h1:wWK+LnOv4jXMM23IT/F1wdYftGWGr47Is8CG+pmHK1Q=
|
||||||
|
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
|
||||||
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||||
github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI=
|
github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI=
|
||||||
github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao=
|
github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao=
|
||||||
|
|
|
||||||
|
|
@ -466,6 +466,8 @@ var (
|
||||||
KubernetesTooOld = Kind{ID: "K8S_OLD_UNSUPPORTED", ExitCode: ExControlPlaneUnsupported}
|
KubernetesTooOld = Kind{ID: "K8S_OLD_UNSUPPORTED", ExitCode: ExControlPlaneUnsupported}
|
||||||
// a too new Kubernetes version was specified for minikube to use
|
// a too new Kubernetes version was specified for minikube to use
|
||||||
KubernetesTooNew = Kind{ID: "K8S_NEW_UNSUPPORTED", ExitCode: ExControlPlaneUnsupported}
|
KubernetesTooNew = Kind{ID: "K8S_NEW_UNSUPPORTED", ExitCode: ExControlPlaneUnsupported}
|
||||||
|
// error fetching github kubernetes version list
|
||||||
|
KubernetesNotConnect = Kind{ID: "K8S_FAIL_CONNECT"}
|
||||||
// minikube was unable to safely downgrade installed Kubernetes version
|
// minikube was unable to safely downgrade installed Kubernetes version
|
||||||
KubernetesDowngrade = Kind{
|
KubernetesDowngrade = Kind{
|
||||||
ID: "K8S_DOWNGRADE_UNSUPPORTED",
|
ID: "K8S_DOWNGRADE_UNSUPPORTED",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue