version_upgrade_test.go 2.9 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 25 26 27
	"io"
	"io/ioutil"
	"os"
	"runtime"
	"testing"

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

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

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

	if runtime.GOOS != "windows" {
S
Sharif Elgamal 已提交
56
		if err := os.Chmod(tf.Name(), 0700); err != nil {
M
Medya Gh 已提交
57 58
			return nil, err
			// t.Fatal(errors.Wrap(err, "Failed to make binary executable."))
59 60
		}
	}
M
Medya Gh 已提交
61 62 63 64 65 66 67 68 69 70 71
	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 已提交
72 73 74
	if err != nil || tf == nil {
		t.Fatal(errors.Wrap(err, "Failed to download minikube binary."))
	}
M
Medya Gh 已提交
75
	defer os.Remove(tf.Name())
76

77 78
	releaseRunner := NewMinikubeRunner(t)
	releaseRunner.BinaryPath = tf.Name()
79 80
	// 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 已提交
81 82 83
	releaseRunner.CheckStatus(state.Running.String())
	releaseRunner.RunCommand("stop", true)
	releaseRunner.CheckStatus(state.Stopped.String())
84

85
	currentRunner.Start(fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion))
86 87 88 89
	currentRunner.CheckStatus(state.Running.String())
	currentRunner.RunCommand("delete", true)
	currentRunner.CheckStatus(state.None.String())
}