From 3ad1dfb4bb3d8e4a016a3aca1585a3b07b4b78e9 Mon Sep 17 00:00:00 2001 From: Vincent Link Date: Tue, 24 Mar 2020 20:19:13 +0100 Subject: [PATCH] Add 'stable' and 'latest' as valid kubernetes-version values --- cmd/minikube/cmd/start.go | 22 ++++++++++++---------- cmd/minikube/cmd/start_test.go | 12 +++++++++++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 01f27f68c465..595058f4f960 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -179,7 +179,7 @@ func initMinikubeFlags() { // initKubernetesFlags inits the commandline flags for kubernetes related options func initKubernetesFlags() { - startCmd.Flags().String(kubernetesVersion, "", "The kubernetes version that the minikube VM will use (ex: v1.2.3)") + startCmd.Flags().String(kubernetesVersion, "", fmt.Sprintf("The kubernetes version that the minikube VM will use (ex: v1.2.3, 'stable' for %s, 'latest' for %s). Defaults to 'stable'.", constants.DefaultKubernetesVersion, constants.NewestKubernetesVersion)) startCmd.Flags().Var(&config.ExtraOptions, "extra-config", `A set of key=value pairs that describe configuration that may be passed to different components. The key should be '.' separated, and the first part before the dot is the component to apply the configuration to. @@ -480,10 +480,10 @@ func selectDriver(existing *config.ClusterConfig) registry.DriverState { if vmd := viper.GetString("vm-driver"); vmd != "" { // Output a warning warning := `Both driver={{.driver}} and vm-driver={{.vmd}} have been set. - + Since vm-driver is deprecated, minikube will default to driver={{.driver}}. - If vm-driver is set in the global config, please run "minikube config unset vm-driver" to resolve this warning. + If vm-driver is set in the global config, please run "minikube config unset vm-driver" to resolve this warning. ` out.T(out.Warning, warning, out.V{"driver": d, "vmd": vmd}) } @@ -1065,13 +1065,15 @@ func autoSetDriverOptions(cmd *cobra.Command, drvName string) (err error) { func getKubernetesVersion(old *config.ClusterConfig) string { paramVersion := viper.GetString(kubernetesVersion) - if paramVersion == "" { // if the user did not specify any version then ... - if old != nil { // .. use the old version from config (if any) - paramVersion = old.KubernetesConfig.KubernetesVersion - } - if paramVersion == "" { // .. otherwise use the default version - paramVersion = constants.DefaultKubernetesVersion - } + // try to load the old version first if the user didn't specify anything + if paramVersion == "" && old != nil { + paramVersion = old.KubernetesConfig.KubernetesVersion + } + + if paramVersion == "" || strings.EqualFold(paramVersion, "stable") { + paramVersion = constants.DefaultKubernetesVersion + } else if strings.EqualFold(paramVersion, "latest") { + paramVersion = constants.NewestKubernetesVersion } nvs, err := semver.Make(strings.TrimPrefix(paramVersion, version.VersionPrefix)) diff --git a/cmd/minikube/cmd/start_test.go b/cmd/minikube/cmd/start_test.go index ef7e4b74033f..0a443aa50793 100644 --- a/cmd/minikube/cmd/start_test.go +++ b/cmd/minikube/cmd/start_test.go @@ -26,7 +26,7 @@ import ( "k8s.io/minikube/pkg/minikube/constants" ) -func TestGetKuberneterVersion(t *testing.T) { +func TestGetKubernetesVersion(t *testing.T) { var tests = []struct { description string expectedVersion string @@ -55,6 +55,16 @@ func TestGetKuberneterVersion(t *testing.T) { paramVersion: "v1.16.0", cfg: &cfg.ClusterConfig{KubernetesConfig: cfg.KubernetesConfig{KubernetesVersion: "v1.15.0"}}, }, + { + description: "kubernetes-version given as 'stable', no config", + expectedVersion: constants.DefaultKubernetesVersion, + paramVersion: "stable", + }, + { + description: "kubernetes-version given as 'latest', no config", + expectedVersion: constants.NewestKubernetesVersion, + paramVersion: "latest", + }, } for _, test := range tests {