Skip to content

Commit

Permalink
Merge pull request #7212 from linkvt/kubernetes-parameters-latest-stable
Browse files Browse the repository at this point in the history
Add 'stable' and 'latest' as valid kubernetes-version values
  • Loading branch information
medyagh committed Mar 25, 2020
2 parents 1f30cfc + 3ad1dfb commit 5ea20f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
22 changes: 12 additions & 10 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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})
}
Expand Down Expand Up @@ -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))
Expand Down
12 changes: 11 additions & 1 deletion cmd/minikube/cmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5ea20f5

Please sign in to comment.