version_upgrade_test.go 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
Copyright 2019 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
20
	"fmt"
21 22 23 24
	"io"
	"io/ioutil"
	"os"
	"runtime"
T
Thomas Stromberg 已提交
25
	"strings"
26 27 28
	"testing"

	"github.com/docker/machine/libmachine/state"
M
Medya Gh 已提交
29
	retryablehttp "github.com/hashicorp/go-retryablehttp"
30
	"github.com/pkg/errors"
31
	"k8s.io/minikube/pkg/minikube/constants"
S
Sharif Elgamal 已提交
32
	pkgutil "k8s.io/minikube/pkg/util"
33 34
)

M
Medya Gh 已提交
35
func downloadMinikubeBinary(version string) (*os.File, error) {
36
	// Grab latest release binary
M
Medya Gh 已提交
37 38
	url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS)
	resp, err := retryablehttp.Get(url)
39
	if err != nil {
40
		return nil, errors.Wrap(err, "Failed to get latest release binary")
41 42 43
	}
	defer resp.Body.Close()

S
Sharif Elgamal 已提交
44
	tf, err := ioutil.TempFile("", "minikube")
45
	if err != nil {
46
		return nil, errors.Wrap(err, "Failed to create binary file")
47
	}
S
Sharif Elgamal 已提交
48
	_, err = io.Copy(tf, resp.Body)
49
	if err != nil {
50
		return nil, errors.Wrap(err, "Failed to populate temp file")
51
	}
S
Sharif Elgamal 已提交
52
	if err := tf.Close(); err != nil {
53
		return nil, errors.Wrap(err, "Failed to close temp file")
54 55 56
	}

	if runtime.GOOS != "windows" {
S
Sharif Elgamal 已提交
57
		if err := os.Chmod(tf.Name(), 0700); err != nil {
M
Medya Gh 已提交
58 59
			return nil, err
			// t.Fatal(errors.Wrap(err, "Failed to make binary executable."))
60 61
		}
	}
M
Medya Gh 已提交
62 63 64 65 66 67 68 69 70 71 72
	return tf, err
}

// TestVersionUpgrade downloads latest version of minikube and runs with
// the odlest supported k8s version and then runs the current head minikube
// and it tries to upgrade from the older supported k8s to news supported k8s
func TestVersionUpgrade(t *testing.T) {
	currentRunner := NewMinikubeRunner(t)
	currentRunner.RunCommand("delete", true)
	currentRunner.CheckStatus(state.None.String())
	tf, err := downloadMinikubeBinary("latest")
M
Medya Gh 已提交
73 74 75
	if err != nil || tf == nil {
		t.Fatal(errors.Wrap(err, "Failed to download minikube binary."))
	}
M
Medya Gh 已提交
76
	defer os.Remove(tf.Name())
77

78 79
	releaseRunner := NewMinikubeRunner(t)
	releaseRunner.BinaryPath = tf.Name()
80 81
	// For full coverage: also test upgrading from oldest to newest supported k8s release
	releaseRunner.Start(fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion))
S
Sharif Elgamal 已提交
82 83 84
	releaseRunner.CheckStatus(state.Running.String())
	releaseRunner.RunCommand("stop", true)
	releaseRunner.CheckStatus(state.Stopped.String())
85

T
Thomas Stromberg 已提交
86 87
	// Trim the leading "v" prefix to assert that we handle it properly.
	currentRunner.Start(fmt.Sprintf("--kubernetes-version=%s", strings.TrimPrefix(constants.NewestKubernetesVersion, "v")))
88 89 90 91
	currentRunner.CheckStatus(state.Running.String())
	currentRunner.RunCommand("delete", true)
	currentRunner.CheckStatus(state.None.String())
}