/* 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 ( "context" "encoding/json" "fmt" "io/ioutil" "os" "os/exec" "runtime" "strings" "testing" "time" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/util/retry" "github.com/docker/machine/libmachine/state" "github.com/hashicorp/go-getter" pkgutil "k8s.io/minikube/pkg/util" ) func installRelease(version string) (f *os.File, err error) { tf, err := ioutil.TempFile("", fmt.Sprintf("minikube-%s.*.exe", version)) if err != nil { return tf, err } tf.Close() url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS) if err := retry.Expo(func() error { return getter.GetFile(tf.Name(), url) }, 3*time.Second, Minutes(3)); err != nil { return tf, err } if runtime.GOOS != "windows" { if err := os.Chmod(tf.Name(), 0700); err != nil { return tf, err } } return tf, nil } // legacyStartArgs returns the arguments normally used for starting older versions of minikube func legacyStartArgs() []string { return strings.Split(strings.Replace(*startArgs, "--driver", "--vm-driver", -1), " ") } // TestRunningBinaryUpgrade does an upgrade test on a running cluster func TestRunningBinaryUpgrade(t *testing.T) { // not supported till v1.10, and passing new images to old releases isn't supported anyways if TestingKicBaseImage() { t.Skipf("Skipping, test does not make sense with --base-image") } MaybeParallel(t) profile := UniqueProfileName("running-upgrade") ctx, cancel := context.WithTimeout(context.Background(), Minutes(55)) defer CleanupWithLogs(t, profile, cancel) // Should be a version from the last 6 months legacyVersion := "v1.6.2" if KicDriver() { // v1.8.0 would be selected, but: https://github.com/kubernetes/minikube/issues/8740 legacyVersion = "v1.9.0" } tf, err := installRelease(legacyVersion) if err != nil { t.Fatalf("%s release installation failed: %v", legacyVersion, err) } defer os.Remove(tf.Name()) args := append([]string{"start", "-p", profile, "--memory=2200"}, legacyStartArgs()...) rr := &RunResult{} r := func() error { rr, err = Run(t, exec.CommandContext(ctx, tf.Name(), args...)) return err } // Retry up to two times, to allow flakiness for the legacy release if err := retry.Expo(r, 1*time.Second, Minutes(30), 2); err != nil { t.Fatalf("legacy %s start failed: %v", legacyVersion, err) } args = append([]string{"start", "-p", profile, "--memory=2200", "--alsologtostderr", "-v=1"}, StartArgs()...) rr, err = Run(t, exec.CommandContext(ctx, Target(), args...)) if err != nil { t.Fatalf("upgrade from %s to HEAD failed: %s: %v", legacyVersion, rr.Command(), err) } } // TestStoppedBinaryUpgrade does an upgrade test on a stopped cluster func TestStoppedBinaryUpgrade(t *testing.T) { // not supported till v1.10, and passing new images to old releases isn't supported anyways if TestingKicBaseImage() { t.Skipf("Skipping, test does not make sense with --base-image") } MaybeParallel(t) profile := UniqueProfileName("stopped-upgrade") ctx, cancel := context.WithTimeout(context.Background(), Minutes(55)) defer CleanupWithLogs(t, profile, cancel) // Guarantee stopped upgrade compatibility from a release that is at least 1 year old // NOTE: