Skip to content

Commit

Permalink
Merge pull request #4568 from kubernetes/allow-naked-version
Browse files Browse the repository at this point in the history
Allow --kubernetes-version to be specified without the leading v
  • Loading branch information
tstromberg authored Jun 24, 2019
2 parents ce74af2 + 7d394fa commit e851619
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,17 @@ func validateNetwork(h *host.Host) string {

// validateKubernetesVersions ensures that the requested version is reasonable
func validateKubernetesVersions(old *cfg.Config) (string, bool) {
nv := viper.GetString(kubernetesVersion)
rawVersion := viper.GetString(kubernetesVersion)
isUpgrade := false
if nv == "" {
nv = constants.DefaultKubernetesVersion
if rawVersion == "" {
rawVersion = constants.DefaultKubernetesVersion
}
nvs, err := semver.Make(strings.TrimPrefix(nv, version.VersionPrefix))

nvs, err := semver.Make(strings.TrimPrefix(rawVersion, version.VersionPrefix))
if err != nil {
exit.WithCode(exit.Data, "Unable to parse %q: %v", nv, err)
exit.WithCode(exit.Data, "Unable to parse %q: %v", rawVersion, err)
}
nv := version.VersionPrefix + nvs.String()

if old == nil || old.KubernetesConfig.KubernetesVersion == "" {
return nv, isUpgrade
Expand Down
4 changes: 3 additions & 1 deletion test/integration/version_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io/ioutil"
"os"
"runtime"
"strings"
"testing"

"github.com/docker/machine/libmachine/state"
Expand Down Expand Up @@ -82,7 +83,8 @@ func TestVersionUpgrade(t *testing.T) {
releaseRunner.RunCommand("stop", true)
releaseRunner.CheckStatus(state.Stopped.String())

currentRunner.Start(fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion))
// Trim the leading "v" prefix to assert that we handle it properly.
currentRunner.Start(fmt.Sprintf("--kubernetes-version=%s", strings.TrimPrefix(constants.NewestKubernetesVersion, "v")))
currentRunner.CheckStatus(state.Running.String())
currentRunner.RunCommand("delete", true)
currentRunner.CheckStatus(state.None.String())
Expand Down

0 comments on commit e851619

Please sign in to comment.