/* 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, runtime.GOARCH) 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.ReplaceAll(*startArgs, "--driver", "--vm-driver"), " ") } // TestRunningBinaryUpgrade upgrades a running legacy cluster to minikube at HEAD 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() { if arm64Platform() { // arm64 KIC driver is supported starting from v1.17.0 legacyVersion = "v1.17.0" } else { // 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 { c := exec.CommandContext(ctx, tf.Name(), args...) legacyEnv := []string{} // replace the global KUBECONFIG with a fresh kubeconfig // because for minikube<1.17.0 it can not read the new kubeconfigs that have extra "Extenions" block // see: https://github.com/kubernetes/minikube/issues/10210 for _, e := range os.Environ() { if !strings.Contains(e, "KUBECONFIG") { // get all global envs except the Kubeconfig which is used by new versions of minikubes legacyEnv = append(legacyEnv, e) } } // using a fresh kubeconfig for this test legacyKubeConfig, err := ioutil.TempFile("", "legacy_kubeconfig") if err != nil { t.Fatalf("failed to create temp file for legacy kubeconfig %v", err) } defer os.Remove(legacyKubeConfig.Name()) // clean up legacyEnv = append(legacyEnv, fmt.Sprintf("KUBECONFIG=%s", legacyKubeConfig.Name())) c.Env = legacyEnv rr, err = Run(t, c) 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 starts a legacy minikube, stops it, and then upgrades to minikube at HEAD 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: