From ccd368211635d4d69835a6a46cc73bf39c163a0c Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 17:34:46 -0700 Subject: [PATCH 01/15] Refactor upgrade tests --- cmd/minikube/cmd/start_flags.go | 7 +- pkg/minikube/config/types.go | 1 + test/integration/version_upgrade_test.go | 120 ++++++++++++++++++----- 3 files changed, 102 insertions(+), 26 deletions(-) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 698b7d307c..ee80bda4ba 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -358,6 +358,11 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k // updateExistingConfigFromFlags will update the existing config from the flags - used on a second start // skipping updating existing docker env , docker opt, InsecureRegistry, registryMirror, extra-config, apiserver-ips func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterConfig) config.ClusterConfig { //nolint to suppress cyclomatic complexity 45 of func `updateExistingConfigFromFlags` is high (> 30) + // Upgrade legacy config + if existing.VMDriver != "" { + existing.Driver = existing.VMDriver + } + validateFlags(cmd, existing.Driver) cc := *existing @@ -553,7 +558,7 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC cc.VerifyComponents = interpretWaitFlag(*cmd) } - if cmd.Flags().Changed(kicBaseImage) { + if cmd.Flags().Changed(kicBaseImage) || cc.KicBaseImage == "" { cc.KicBaseImage = viper.GetString(kicBaseImage) } diff --git a/pkg/minikube/config/types.go b/pkg/minikube/config/types.go index 6adfb82124..47df5d1480 100644 --- a/pkg/minikube/config/types.go +++ b/pkg/minikube/config/types.go @@ -39,6 +39,7 @@ type ClusterConfig struct { Memory int CPUs int DiskSize int + VMDriver string // Legacy use only Driver string HyperkitVpnKitSock string // Only used by the Hyperkit driver HyperkitVSockPorts []string // Only used by the Hyperkit driver diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index 7a80a70231..006cbdb0c6 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -24,12 +24,9 @@ import ( "os" "os/exec" "runtime" - "strings" "testing" "time" - "github.com/docker/machine/libmachine/state" - "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/util/retry" @@ -37,24 +34,29 @@ import ( pkgutil "k8s.io/minikube/pkg/util" ) -// TestVersionUpgrade downloads the latest version of minikube and runs with -// the oldest supported k8s version and then runs the current head minikube -// and tries to upgrade from the oldest supported k8s to newest supported k8s -func TestVersionUpgrade(t *testing.T) { +// TestBinaryUpgrade does a basic upgrade test +func TestBinaryUpgrade(t *testing.T) { + MaybeParallel(t) - profile := UniqueProfileName("vupgrade") + profile := UniqueProfileName("binary-upgrade") ctx, cancel := context.WithTimeout(context.Background(), Minutes(55)) defer CleanupWithLogs(t, profile, cancel) - tf, err := ioutil.TempFile("", "minikube-release.*.exe") + // This should ideally be v1.0.0, but we aren't there yet + legacyVersion := "v1.0.0" + if DockerDriver() { + legacyVersion = "v1.7.2" + } + + tf, err := ioutil.TempFile("", fmt.Sprintf("minikube-%s.*.exe", legacyVersion)) if err != nil { t.Fatalf("tempfile: %v", err) } defer os.Remove(tf.Name()) tf.Close() - url := pkgutil.GetBinaryDownloadURL("latest", runtime.GOOS) + url := pkgutil.GetBinaryDownloadURL(legacyVersion, runtime.GOOS) if err := retry.Expo(func() error { return getter.GetFile(tf.Name(), url) }, 3*time.Second, Minutes(3)); err != nil { t.Fatalf("get failed: %v", err) } @@ -65,10 +67,7 @@ func TestVersionUpgrade(t *testing.T) { } } - // Assert that --iso-url works without a sha checksum, and that we can upgrade from old ISO's - // Some day, this will break an implicit assumption that a tool is available in the ISO :) - oldISO := "https://storage.googleapis.com/minikube/iso/integration-test.iso" - args := append([]string{"start", "-p", profile, "--memory=2200", fmt.Sprintf("--iso-url=%s", oldISO), fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion), "--alsologtostderr"}, StartArgs()...) + args := append([]string{"start", "-p", profile, "--memory=2200"}, StartArgs()...) rr := &RunResult{} r := func() error { rr, err = Run(t, exec.CommandContext(ctx, tf.Name(), args...)) @@ -80,25 +79,36 @@ func TestVersionUpgrade(t *testing.T) { t.Fatalf("release start failed: %v", err) } - rr, err = Run(t, exec.CommandContext(ctx, tf.Name(), "stop", "-p", profile)) + 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("%s failed: %v", rr.Command(), err) + t.Errorf("failed to start minikube HEAD with newest k8s version. args: %s : %v", rr.Command(), err) + } +} + +// TestKubernetesUpgrade tests an upgrade of Kubernetes +func TestKubernetesUpgrade(t *testing.T) { + MaybeParallel(t) + profile := UniqueProfileName("vupgrade") + ctx, cancel := context.WithTimeout(context.Background(), Minutes(55)) + + defer CleanupWithLogs(t, profile, cancel) + + args := append([]string{"start", "-p", profile, "--memory=2200", fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion), "--alsologtostderr", "-v=1"}, StartArgs()...) + rr, err := Run(t, exec.CommandContext(ctx, Target(), args...)) + if err != nil { + t.Errorf("failed to start minikube HEAD with oldest k8s version: %s: %v", rr.Command(), err) } - rr, err = Run(t, exec.CommandContext(ctx, tf.Name(), "-p", profile, "status", "--format={{.Host}}")) + rr, err = Run(t, exec.CommandContext(ctx, Target(), "stop")) if err != nil { - t.Logf("status error: %v (may be ok)", err) - } - - got := strings.TrimSpace(rr.Stdout.String()) - if got != state.Stopped.String() { - t.Errorf("FAILED: status = %q; want = %q", got, state.Stopped.String()) + t.Errorf("failed to stop cluster: %s: %v", rr.Command(), err) } args = append([]string{"start", "-p", profile, "--memory=2200", fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion), "--alsologtostderr", "-v=1"}, StartArgs()...) rr, err = Run(t, exec.CommandContext(ctx, Target(), args...)) if err != nil { - t.Errorf("failed to start minikube HEAD with newest k8s version. args: %s : %v", rr.Command(), err) + t.Errorf("failed to upgrade with newest k8s version. args: %s : %v", rr.Command(), err) } s, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "version", "--output=json")) @@ -122,7 +132,7 @@ func TestVersionUpgrade(t *testing.T) { t.Logf("Attempting to downgrade Kubernetes (should fail)") args = append([]string{"start", "-p", profile, "--memory=2200", fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion)}, StartArgs()...) - if rr, err := Run(t, exec.CommandContext(ctx, tf.Name(), args...)); err == nil { + if rr, err := Run(t, exec.CommandContext(ctx, Target(), args...)); err == nil { t.Fatalf("downgrading Kubernetes should not be allowed. expected to see error but got %v for %q", err, rr.Command()) } @@ -133,3 +143,63 @@ func TestVersionUpgrade(t *testing.T) { t.Errorf("start after failed upgrade: %v", err) } } + +// TestMissingUpgrade tests a Docker upgrade where the underlying container is missing +func TestMissingUpgrade(t *testing.T) { + if !DockerDriver() { + t.Skipf("This test is only for Docker") + } + + MaybeParallel(t) + profile := UniqueProfileName("missing-upgrade") + ctx, cancel := context.WithTimeout(context.Background(), Minutes(55)) + + defer CleanupWithLogs(t, profile, cancel) + + legacyVersion := "v1.9.1" + tf, err := ioutil.TempFile("", fmt.Sprintf("minikube-%s.*.exe", legacyVersion)) + if err != nil { + t.Fatalf("tempfile: %v", err) + } + defer os.Remove(tf.Name()) + tf.Close() + + url := pkgutil.GetBinaryDownloadURL(legacyVersion, runtime.GOOS) + if err := retry.Expo(func() error { return getter.GetFile(tf.Name(), url) }, 3*time.Second, Minutes(3)); err != nil { + t.Fatalf("get failed: %v", err) + } + + if runtime.GOOS != "windows" { + if err := os.Chmod(tf.Name(), 0700); err != nil { + t.Errorf("chmod: %v", err) + } + } + + args := append([]string{"start", "-p", profile, "--memory=2200"}, StartArgs()...) + 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 previous release + if err := retry.Expo(r, 1*time.Second, Minutes(30), 2); err != nil { + t.Fatalf("release start failed: %v", err) + } + + rr, err = Run(t, exec.CommandContext(ctx, "docker", "stop", profile)) + if err != nil { + t.Fatalf("%s failed: %v", rr.Command(), err) + } + + rr, err = Run(t, exec.CommandContext(ctx, "docker", "rm", profile)) + if err != nil { + t.Fatalf("%s failed: %v", rr.Command(), 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.Errorf("failed to start minikube HEAD with newest k8s version. args: %s : %v", rr.Command(), err) + } +} From 51cc36589808d49723a7353a752ac0e23ebb4bbc Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 19:35:44 -0700 Subject: [PATCH 02/15] Handle case where VMDriver is set, but Driver is not --- cmd/minikube/cmd/start.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index f04e22fc8d..729833cb57 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -155,6 +155,8 @@ func runStart(cmd *cobra.Command, args []string) { exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err}) } + upgradeExistingConfig(existing) + validateSpecifiedDriver(existing) validateKubernetesVersion(existing) ds, alts, specified := selectDriver(existing) @@ -562,7 +564,10 @@ func hostDriver(existing *config.ClusterConfig) string { machineName := driver.MachineName(*existing, cp) h, err := api.Load(machineName) if err != nil { - glog.Warningf("selectDriver api.Load: %v", err) + glog.Warningf("api.Load failed for %s: %v", machineName, err) + if existing.VMDriver != "" { + return existing.VMDriver + } return existing.Driver } From 78f7b3cc66834171c898a14bbe9f4ab22ba70228 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 19:36:50 -0700 Subject: [PATCH 03/15] Add upgradeExistingConfig to upgrade legacy configurations --- cmd/minikube/cmd/start_flags.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index ee80bda4ba..d3e7913178 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -337,6 +337,8 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k } } + glog.Infof("config:\n%+v", cc) + r, err := cruntime.New(cruntime.Config{Type: cc.KubernetesConfig.ContainerRuntime}) if err != nil { return cc, config.Node{}, errors.Wrap(err, "new runtime manager") @@ -355,13 +357,22 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k return createNode(cc, kubeNodeName, existing) } +// upgradeExistingConfig upgrades legacy configuration files +func upgradeExistingConfig(cc *config.ClusterConfig) { + if cc.VMDriver != "" && cc.Driver == "" { + glog.Infof("config upgrade: Driver=%s", cc.VMDriver) + cc.Driver = cc.VMDriver + } + + if cc.Name == "" { + glog.Infof("config upgrade: Name=%s", ClusterFlagValue()) + cc.Name = ClusterFlagValue() + } +} + // updateExistingConfigFromFlags will update the existing config from the flags - used on a second start // skipping updating existing docker env , docker opt, InsecureRegistry, registryMirror, extra-config, apiserver-ips func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterConfig) config.ClusterConfig { //nolint to suppress cyclomatic complexity 45 of func `updateExistingConfigFromFlags` is high (> 30) - // Upgrade legacy config - if existing.VMDriver != "" { - existing.Driver = existing.VMDriver - } validateFlags(cmd, existing.Driver) From be2c27efe06ececb57c1dbc03062fa488535b022 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 19:37:15 -0700 Subject: [PATCH 04/15] Find and copy legacy certificate/key paths --- pkg/minikube/localpath/localpath.go | 39 +++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/pkg/minikube/localpath/localpath.go b/pkg/minikube/localpath/localpath.go index bfe5f9c9e3..6086dd834a 100644 --- a/pkg/minikube/localpath/localpath.go +++ b/pkg/minikube/localpath/localpath.go @@ -24,6 +24,7 @@ import ( "strings" "github.com/golang/glog" + "github.com/otiai10/copy" "github.com/pkg/errors" "k8s.io/client-go/util/homedir" ) @@ -62,12 +63,46 @@ func Profile(name string) string { // ClientCert returns client certificate path, used by kubeconfig func ClientCert(name string) string { - return filepath.Join(Profile(name), "client.crt") + new := filepath.Join(Profile(name), "client.crt") + if _, err := os.Stat(new); err == nil { + return new + } + + // minikube v1.5.x + legacy := filepath.Join(MiniPath(), "client.crt") + if _, err := os.Stat(legacy); err == nil { + glog.Infof("copying %s -> %s", legacy, new) + if err := copy.Copy(legacy, new); err != nil { + glog.Errorf("failed copy %s -> %s: %v", legacy, new, err) + return legacy + } + return new + } + + glog.Errorf("unable to find a client cert, returning default: %s", new) + return new } // ClientKey returns client certificate path, used by kubeconfig func ClientKey(name string) string { - return filepath.Join(Profile(name), "client.key") + new := filepath.Join(Profile(name), "client.key") + if _, err := os.Stat(new); err == nil { + return new + } + + // minikube v1.5.x + legacy := filepath.Join(MiniPath(), "client.key") + if _, err := os.Stat(legacy); err == nil { + glog.Infof("copying %s -> %s", legacy, new) + if err := copy.Copy(legacy, new); err != nil { + glog.Errorf("failed copy %s -> %s: %v", legacy, new, err) + return legacy + } + return new + } + + glog.Errorf("unable to find a client key, returning default: %s", new) + return new } // CACert returns the minikube CA certificate shared between profiles From 798196d0adedf63c90e5561a2284ed84d2e28bd6 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 19:37:28 -0700 Subject: [PATCH 05/15] Remove stray log line --- pkg/minikube/machine/start.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/minikube/machine/start.go b/pkg/minikube/machine/start.go index 3d76133303..64aaa718f3 100644 --- a/pkg/minikube/machine/start.go +++ b/pkg/minikube/machine/start.go @@ -268,7 +268,6 @@ func showHostInfo(cfg config.ClusterConfig) { // AddHostAlias makes fine adjustments to pod resources that aren't possible via kubeadm config. func AddHostAlias(c command.Runner, name string, ip net.IP) error { - glog.Infof("checking") record := fmt.Sprintf("%s\t%s", ip, name) if _, err := c.RunCmd(exec.Command("grep", record+"$", "/etc/hosts")); err == nil { return nil From 89b8a6e545dedcc1a414292cf7bf057509718c86 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 19:37:52 -0700 Subject: [PATCH 06/15] Separate legacy integration tests, test more cases --- test/integration/version_upgrade_test.go | 129 ++++++++++++++++------- 1 file changed, 88 insertions(+), 41 deletions(-) diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index 006cbdb0c6..cf97bbf461 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -34,38 +34,48 @@ import ( pkgutil "k8s.io/minikube/pkg/util" ) -// TestBinaryUpgrade does a basic upgrade test -func TestBinaryUpgrade(t *testing.T) { +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 +} + +// TestRunningBinaryUpgrade does an upgrade test on a running cluster +func TestRunningBinaryUpgrade(t *testing.T) { MaybeParallel(t) profile := UniqueProfileName("binary-upgrade") ctx, cancel := context.WithTimeout(context.Background(), Minutes(55)) defer CleanupWithLogs(t, profile, cancel) - // This should ideally be v1.0.0, but we aren't there yet - legacyVersion := "v1.0.0" - if DockerDriver() { - legacyVersion = "v1.7.2" + // 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 := ioutil.TempFile("", fmt.Sprintf("minikube-%s.*.exe", legacyVersion)) + tf, err := installRelease(legacyVersion) if err != nil { - t.Fatalf("tempfile: %v", err) + t.Fatalf("%s release installation failed: %v", legacyVersion, err) } defer os.Remove(tf.Name()) - tf.Close() - - url := pkgutil.GetBinaryDownloadURL(legacyVersion, runtime.GOOS) - if err := retry.Expo(func() error { return getter.GetFile(tf.Name(), url) }, 3*time.Second, Minutes(3)); err != nil { - t.Fatalf("get failed: %v", err) - } - - if runtime.GOOS != "windows" { - if err := os.Chmod(tf.Name(), 0700); err != nil { - t.Errorf("chmod: %v", err) - } - } args := append([]string{"start", "-p", profile, "--memory=2200"}, StartArgs()...) rr := &RunResult{} @@ -74,22 +84,70 @@ func TestBinaryUpgrade(t *testing.T) { return err } - // Retry up to two times, to allow flakiness for the previous release + // 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("release start failed: %v", err) + 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.Errorf("failed to start minikube HEAD with newest k8s version. args: %s : %v", rr.Command(), err) + t.Fatalf("upgrade from %s to HEAD failed: %s: %v", legacyVersion, rr.Command(), err) } } -// TestKubernetesUpgrade tests an upgrade of Kubernetes +// TestStoppedBinaryUpgrade does an upgrade test on a stopped cluster +func TestStoppedBinaryUpgrade(t *testing.T) { + + MaybeParallel(t) + profile := UniqueProfileName("binary-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: Date: Thu, 16 Jul 2020 19:44:07 -0700 Subject: [PATCH 07/15] Move KicBaseImage adjustment to upgradeExistingConfig --- cmd/minikube/cmd/start_flags.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index d3e7913178..45f7889254 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -368,6 +368,12 @@ func upgradeExistingConfig(cc *config.ClusterConfig) { glog.Infof("config upgrade: Name=%s", ClusterFlagValue()) cc.Name = ClusterFlagValue() } + + if cc.KicBaseImage == "" { + // defaults to kic.BaseImage + cc.KicBaseImage = viper.GetString(kicBaseImage) + glog.Infof("config upgrade: KicBaseImage=%s", cc.KicBaseImage) + } } // updateExistingConfigFromFlags will update the existing config from the flags - used on a second start @@ -569,7 +575,7 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC cc.VerifyComponents = interpretWaitFlag(*cmd) } - if cmd.Flags().Changed(kicBaseImage) || cc.KicBaseImage == "" { + if cmd.Flags().Changed(kicBaseImage) { cc.KicBaseImage = viper.GetString(kicBaseImage) } From 2fd749237720a0e4e10f073de895d5eed56ae405 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 19:50:00 -0700 Subject: [PATCH 08/15] Guard against nil panics --- cmd/minikube/cmd/start.go | 4 +++- cmd/minikube/cmd/start_flags.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 729833cb57..c3029a6376 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -155,7 +155,9 @@ func runStart(cmd *cobra.Command, args []string) { exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err}) } - upgradeExistingConfig(existing) + if existing != nil { + upgradeExistingConfig(existing) + } validateSpecifiedDriver(existing) validateKubernetesVersion(existing) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 45f7889254..62d480d50b 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -359,6 +359,10 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k // upgradeExistingConfig upgrades legacy configuration files func upgradeExistingConfig(cc *config.ClusterConfig) { + if cc == nil { + return + } + if cc.VMDriver != "" && cc.Driver == "" { glog.Infof("config upgrade: Driver=%s", cc.VMDriver) cc.Driver = cc.VMDriver From 5a6a2bca170a595b82a629d9b35f7e296913e57d Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 19:50:11 -0700 Subject: [PATCH 09/15] Rename binary upgrade prefixes --- test/integration/version_upgrade_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index cf97bbf461..dde1e20e88 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -59,7 +59,7 @@ func installRelease(version string) (f *os.File, err error) { // TestRunningBinaryUpgrade does an upgrade test on a running cluster func TestRunningBinaryUpgrade(t *testing.T) { MaybeParallel(t) - profile := UniqueProfileName("binary-upgrade") + profile := UniqueProfileName("running-upgrade") ctx, cancel := context.WithTimeout(context.Background(), Minutes(55)) defer CleanupWithLogs(t, profile, cancel) @@ -100,7 +100,7 @@ func TestRunningBinaryUpgrade(t *testing.T) { func TestStoppedBinaryUpgrade(t *testing.T) { MaybeParallel(t) - profile := UniqueProfileName("binary-upgrade") + profile := UniqueProfileName("stopped-upgrade") ctx, cancel := context.WithTimeout(context.Background(), Minutes(55)) defer CleanupWithLogs(t, profile, cancel) From 0f12f109e4f4c5ac60b53bc12576e5aecb5c1398 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 20:16:29 -0700 Subject: [PATCH 10/15] Add stop/state checks back to TestKubernetesUpgrade --- test/integration/version_upgrade_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index dde1e20e88..d6b23a4355 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -24,12 +24,14 @@ import ( "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" ) @@ -158,9 +160,19 @@ func TestKubernetesUpgrade(t *testing.T) { t.Errorf("failed to start minikube HEAD with oldest k8s version: %s: %v", rr.Command(), err) } - rr, err = Run(t, exec.CommandContext(ctx, Target(), "stop")) + rr, err = Run(t, exec.CommandContext(ctx, Target(), "stop", "-p", profile)) if err != nil { - t.Errorf("failed to stop cluster: %s: %v", rr.Command(), err) + t.Fatalf("%s failed: %v", rr.Command(), err) + } + + rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status", "--format={{.Host}}")) + if err != nil { + t.Logf("status error: %v (may be ok)", err) + } + + got := strings.TrimSpace(rr.Stdout.String()) + if got != state.Stopped.String() { + t.Errorf("FAILED: status = %q; want = %q", got, state.Stopped.String()) } args = append([]string{"start", "-p", profile, "--memory=2200", fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion), "--alsologtostderr", "-v=1"}, StartArgs()...) From a14e48a9b77dbb9976bd358732dccd8720c8bbde Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 20:19:01 -0700 Subject: [PATCH 11/15] Rename TestMissingUpgrade to TestMissingContainerUpgrade --- test/integration/version_upgrade_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index d6b23a4355..56165d26f0 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -214,8 +214,8 @@ func TestKubernetesUpgrade(t *testing.T) { } } -// TestMissingUpgrade tests a Docker upgrade where the underlying container is missing -func TestMissingUpgrade(t *testing.T) { +// TestMissingContainerUpgrade tests a Docker upgrade where the underlying container is missing +func TestMissingContainerUpgrade(t *testing.T) { if !DockerDriver() { t.Skipf("This test is only for Docker") } From d5631ca84c5ed189969adb1421b2b6a72be86a78 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 23:03:16 -0700 Subject: [PATCH 12/15] version upgrade test: replace --driver with --vm-driver --- test/integration/version_upgrade_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index 56165d26f0..e07b084ea6 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -58,6 +58,11 @@ func installRelease(version string) (f *os.File, err error) { 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) { MaybeParallel(t) @@ -79,7 +84,7 @@ func TestRunningBinaryUpgrade(t *testing.T) { } defer os.Remove(tf.Name()) - args := append([]string{"start", "-p", profile, "--memory=2200"}, StartArgs()...) + args := append([]string{"start", "-p", profile, "--memory=2200"}, legacyStartArgs()...) rr := &RunResult{} r := func() error { rr, err = Run(t, exec.CommandContext(ctx, tf.Name(), args...)) @@ -122,7 +127,7 @@ func TestStoppedBinaryUpgrade(t *testing.T) { } defer os.Remove(tf.Name()) - args := append([]string{"start", "-p", profile, "--memory=2200"}, StartArgs()...) + args := append([]string{"start", "-p", profile, "--memory=2200"}, legacyStartArgs()...) rr := &RunResult{} r := func() error { rr, err = Run(t, exec.CommandContext(ctx, tf.Name(), args...)) From b72eee4e361e23914dada5e84ee5ab23cd4c22ae Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 16 Jul 2020 23:07:37 -0700 Subject: [PATCH 13/15] Turn Errorf into Infof --- pkg/minikube/localpath/localpath.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/localpath/localpath.go b/pkg/minikube/localpath/localpath.go index 6086dd834a..864a0ad4c3 100644 --- a/pkg/minikube/localpath/localpath.go +++ b/pkg/minikube/localpath/localpath.go @@ -79,7 +79,7 @@ func ClientCert(name string) string { return new } - glog.Errorf("unable to find a client cert, returning default: %s", new) + glog.Infof("unable to find a client cert, returning default: %s", new) return new } From 3b1dc975d0ed47f65b9d5296bc36bafb6306de86 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Fri, 17 Jul 2020 07:23:48 -0700 Subject: [PATCH 14/15] legacy client certs: simplify logic --- pkg/minikube/localpath/localpath.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/minikube/localpath/localpath.go b/pkg/minikube/localpath/localpath.go index 864a0ad4c3..b380354032 100644 --- a/pkg/minikube/localpath/localpath.go +++ b/pkg/minikube/localpath/localpath.go @@ -76,10 +76,8 @@ func ClientCert(name string) string { glog.Errorf("failed copy %s -> %s: %v", legacy, new, err) return legacy } - return new } - glog.Infof("unable to find a client cert, returning default: %s", new) return new } @@ -98,10 +96,8 @@ func ClientKey(name string) string { glog.Errorf("failed copy %s -> %s: %v", legacy, new, err) return legacy } - return new } - glog.Errorf("unable to find a client key, returning default: %s", new) return new } From 4f22ec9e3c47b9c3a71e83f47017918af6e36ac9 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Fri, 17 Jul 2020 11:10:29 -0700 Subject: [PATCH 15/15] Remove TestMissingContainerUpgrade merge conflict --- test/integration/version_upgrade_test.go | 60 ------------------------ 1 file changed, 60 deletions(-) diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index 97990e6362..e07b084ea6 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -267,63 +267,3 @@ func TestMissingContainerUpgrade(t *testing.T) { t.Errorf("failed missing container upgrade from %s. args: %s : %v", legacyVersion, rr.Command(), err) } } - -// TestMissingContainerUpgrade tests a Docker upgrade where the underlying container is missing -func TestMissingContainerUpgrade(t *testing.T) { - if !DockerDriver() { - t.Skipf("This test is only for Docker") - } - - MaybeParallel(t) - profile := UniqueProfileName("missing-upgrade") - ctx, cancel := context.WithTimeout(context.Background(), Minutes(55)) - - defer CleanupWithLogs(t, profile, cancel) - - legacyVersion := "v1.9.1" - tf, err := ioutil.TempFile("", fmt.Sprintf("minikube-%s.*.exe", legacyVersion)) - if err != nil { - t.Fatalf("tempfile: %v", err) - } - defer os.Remove(tf.Name()) - tf.Close() - - url := pkgutil.GetBinaryDownloadURL(legacyVersion, runtime.GOOS) - if err := retry.Expo(func() error { return getter.GetFile(tf.Name(), url) }, 3*time.Second, Minutes(3)); err != nil { - t.Fatalf("get failed: %v", err) - } - - if runtime.GOOS != "windows" { - if err := os.Chmod(tf.Name(), 0700); err != nil { - t.Errorf("chmod: %v", err) - } - } - - args := append([]string{"start", "-p", profile, "--memory=2200"}, StartArgs()...) - 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 previous release - if err := retry.Expo(r, 1*time.Second, Minutes(30), 2); err != nil { - t.Fatalf("release start failed: %v", err) - } - - rr, err = Run(t, exec.CommandContext(ctx, "docker", "stop", profile)) - if err != nil { - t.Fatalf("%s failed: %v", rr.Command(), err) - } - - rr, err = Run(t, exec.CommandContext(ctx, "docker", "rm", profile)) - if err != nil { - t.Fatalf("%s failed: %v", rr.Command(), 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.Errorf("failed missing container upgrade from %s. args: %s : %v", legacyVersion, rr.Command(), err) - } -}