list all currently supported Kubernetes versions
parent
6059f8e92d
commit
eff4a18375
|
@ -1585,10 +1585,10 @@ func validateKubernetesVersion(old *config.ClusterConfig) {
|
|||
exitIfNotForced(reason.KubernetesTooNew, "Kubernetes {{.version}} is not supported by this release of minikube", out.V{"version": nvs})
|
||||
}
|
||||
if nvs.GT(newestVersion) {
|
||||
out.WarningT("Specified Kubernetes version {{.specified}} is newer than the newest supported version: {{.newest}}", out.V{"specified": nvs, "newest": constants.NewestKubernetesVersion})
|
||||
out.WarningT("Specified Kubernetes version {{.specified}} is newer than the newest supported version: {{.newest}}. Use `minikube version --kubernetes` for details.", out.V{"specified": nvs, "newest": constants.NewestKubernetesVersion})
|
||||
}
|
||||
if nvs.LT(oldestVersion) {
|
||||
out.WarningT("Specified Kubernetes version {{.specified}} is less than the oldest supported version: {{.oldest}}", out.V{"specified": nvs, "oldest": constants.OldestKubernetesVersion})
|
||||
out.WarningT("Specified Kubernetes version {{.specified}} is less than the oldest supported version: {{.oldest}}. Use `minikube version --kubernetes` for details.", out.V{"specified": nvs, "oldest": constants.OldestKubernetesVersion})
|
||||
if !viper.GetBool(force) {
|
||||
out.WarningT("You can force an unsupported Kubernetes version via the --force flag")
|
||||
}
|
||||
|
|
|
@ -17,14 +17,19 @@ limitations under the License.
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/v43/github"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/mod/semver"
|
||||
"gopkg.in/yaml.v2"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/exit"
|
||||
"k8s.io/minikube/pkg/minikube/mustload"
|
||||
"k8s.io/minikube/pkg/minikube/out"
|
||||
|
@ -36,6 +41,7 @@ var (
|
|||
versionOutput string
|
||||
shortVersion bool
|
||||
listComponentsVersions bool
|
||||
listKubernetesVersions bool
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
|
@ -82,6 +88,16 @@ var versionCmd = &cobra.Command{
|
|||
|
||||
}
|
||||
|
||||
if listKubernetesVersions && !shortVersion {
|
||||
skv, err := supportedKubernetesVersions(constants.OldestKubernetesVersion, constants.NewestKubernetesVersion, true)
|
||||
if err != nil {
|
||||
klog.Warningf("Unable to get supported Kubernetes versions: {{.error}}", out.V{"error": err})
|
||||
data["supportedKubernetesVersions"] = fmt.Sprintf("[%s..%s]", constants.OldestKubernetesVersion, constants.NewestKubernetesVersion)
|
||||
} else {
|
||||
data["supportedKubernetesVersions"] = fmt.Sprintf("%v", skv)
|
||||
}
|
||||
}
|
||||
|
||||
switch versionOutput {
|
||||
case "":
|
||||
if !shortVersion {
|
||||
|
@ -125,8 +141,54 @@ var versionCmd = &cobra.Command{
|
|||
},
|
||||
}
|
||||
|
||||
// supportedKubernetesVersions returns reverse-sort supported Kubernetes releases from GitHub that are in [minver, maxver] range, optionally including prereleases, and any error occurred.
|
||||
func supportedKubernetesVersions(minver, maxver string, prereleases bool) (releases []string, err error) {
|
||||
ghc := github.NewClient(nil)
|
||||
|
||||
if (minver != "" && !semver.IsValid(minver)) || (maxver != "" && !semver.IsValid(maxver)) {
|
||||
return nil, fmt.Errorf("invalid release version(s) semver format: %q or %q", minver, maxver)
|
||||
}
|
||||
if minver != "" && maxver != "" && semver.Compare(minver, maxver) == 1 {
|
||||
return nil, fmt.Errorf("invalid release versions range: min(%s) > max(%s)", minver, maxver)
|
||||
}
|
||||
|
||||
opts := &github.ListOptions{PerPage: 100}
|
||||
for (opts.Page+1)*100 <= 300 {
|
||||
rls, resp, err := ghc.Repositories.ListReleases(context.Background(), "kubernetes", "kubernetes", opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, r := range rls {
|
||||
// extract version from release name (eg, "Kubernetes v1.22.0-beta.2" => "v1.22.0-beta.2")
|
||||
v := r.GetName()
|
||||
t := strings.Fields(v)
|
||||
if len(t) > 1 {
|
||||
v = t[len(t)-1]
|
||||
}
|
||||
if !semver.IsValid(v) {
|
||||
continue
|
||||
}
|
||||
if !prereleases && r.GetPrerelease() {
|
||||
continue
|
||||
}
|
||||
// skip out-of-range versions
|
||||
if (minver != "" && semver.Compare(minver, v) == 1) || (maxver != "" && semver.Compare(v, maxver) == 1) {
|
||||
continue
|
||||
}
|
||||
releases = append(releases, v)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func init() {
|
||||
versionCmd.Flags().StringVarP(&versionOutput, "output", "o", "", "One of 'yaml' or 'json'.")
|
||||
versionCmd.Flags().BoolVar(&shortVersion, "short", false, "Print just the version number.")
|
||||
versionCmd.Flags().BoolVar(&listComponentsVersions, "components", false, "list versions of all components included with minikube. (the cluster must be running)")
|
||||
versionCmd.Flags().BoolVar(&listKubernetesVersions, "kubernetes", false, "list all Kubernetes versions supported by this minikube version.")
|
||||
}
|
||||
|
|
3
go.mod
3
go.mod
|
@ -100,6 +100,7 @@ require (
|
|||
require (
|
||||
github.com/Xuanwo/go-locale v1.1.0
|
||||
github.com/docker/go-connections v0.4.0
|
||||
github.com/google/go-github/v43 v43.0.0
|
||||
github.com/opencontainers/runc v1.0.2
|
||||
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0
|
||||
)
|
||||
|
@ -153,7 +154,7 @@ require (
|
|||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.3 // indirect
|
||||
github.com/google/gnostic v0.5.7-v3refs // indirect
|
||||
github.com/google/go-querystring v1.0.0 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/google/gofuzz v1.1.0 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.3.0 // indirect
|
||||
github.com/googleapis/go-type-adapters v1.0.0 // indirect
|
||||
|
|
5
go.sum
5
go.sum
|
@ -576,8 +576,11 @@ github.com/google/go-containerregistry v0.6.0/go.mod h1:euCCtNbZ6tKqi1E72vwDj2xZ
|
|||
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||
github.com/google/go-github/v36 v36.0.0 h1:ndCzM616/oijwufI7nBRa+5eZHLldT+4yIB68ib5ogs=
|
||||
github.com/google/go-github/v36 v36.0.0/go.mod h1:LFlKC047IOqiglRGNqNb9s/iAPTnnjtlshm+bxp+kwk=
|
||||
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
|
||||
github.com/google/go-github/v43 v43.0.0 h1:y+GL7LIsAIF2NZlJ46ZoC/D1W1ivZasT0lnWHMYPZ+U=
|
||||
github.com/google/go-github/v43 v43.0.0/go.mod h1:ZkTvvmCXBvsfPpTHXnH/d2hP9Y0cTbvN9kr5xqyXOIc=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
|
||||
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
|
|
Loading…
Reference in New Issue