2016-06-29 21:52:10 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright 2016 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 (
|
2016-07-12 17:50:44 +00:00
|
|
|
"fmt"
|
2016-06-29 21:52:10 +00:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2017-05-18 16:56:07 +00:00
|
|
|
"github.com/docker/machine/libmachine/state"
|
2016-06-29 21:52:10 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/minikube/test/integration/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPersistence(t *testing.T) {
|
|
|
|
minikubeRunner := util.MinikubeRunner{BinaryPath: *binaryPath, T: t}
|
|
|
|
minikubeRunner.EnsureRunning()
|
|
|
|
|
|
|
|
kubectlRunner := util.NewKubectlRunner(t)
|
|
|
|
podName := "busybox"
|
|
|
|
podPath, _ := filepath.Abs("testdata/busybox.yaml")
|
|
|
|
|
|
|
|
podNamespace := kubectlRunner.CreateRandomNamespace()
|
|
|
|
defer kubectlRunner.DeleteNamespace(podNamespace)
|
|
|
|
|
|
|
|
// Create a pod and wait for it to be running.
|
|
|
|
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath, "--namespace=" + podNamespace}); err != nil {
|
|
|
|
t.Fatalf("Error creating test pod: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
checkPod := func() error {
|
2017-04-26 23:53:41 +00:00
|
|
|
p, err := kubectlRunner.GetPod(podName, podNamespace)
|
|
|
|
if err != nil {
|
2017-08-23 15:51:14 +00:00
|
|
|
return err
|
2017-04-26 23:53:41 +00:00
|
|
|
}
|
2016-10-25 18:43:49 +00:00
|
|
|
if kubectlRunner.IsPodReady(p) {
|
2016-07-18 22:35:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-08-23 15:51:14 +00:00
|
|
|
return fmt.Errorf("Pod %s is not ready yet.", podName)
|
2016-06-29 21:52:10 +00:00
|
|
|
}
|
2016-07-18 22:35:37 +00:00
|
|
|
|
2017-08-23 15:51:14 +00:00
|
|
|
if err := util.Retry(t, checkPod, 6*time.Second, 20); err != nil {
|
2016-06-29 21:52:10 +00:00
|
|
|
t.Fatalf("Error checking the status of pod %s. Err: %s", podName, err)
|
|
|
|
}
|
2016-07-12 17:50:44 +00:00
|
|
|
|
|
|
|
checkDashboard := func() error {
|
|
|
|
pods := api.PodList{}
|
|
|
|
cmd := []string{"get", "pods", "--namespace=kube-system", "--selector=app=kubernetes-dashboard"}
|
|
|
|
if err := kubectlRunner.RunCommandParseOutput(cmd, &pods); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(pods.Items) < 1 {
|
2017-08-23 15:51:14 +00:00
|
|
|
return fmt.Errorf("No pods found matching query: %v", cmd)
|
2016-07-12 17:50:44 +00:00
|
|
|
}
|
|
|
|
db := pods.Items[0]
|
2016-10-25 18:43:49 +00:00
|
|
|
if kubectlRunner.IsPodReady(&db) {
|
2016-07-18 22:35:37 +00:00
|
|
|
return nil
|
2016-07-12 17:50:44 +00:00
|
|
|
}
|
2017-08-23 15:51:14 +00:00
|
|
|
return fmt.Errorf("Dashboard pod is not ready yet.")
|
2016-07-18 22:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the dashboard is running before we stop the VM.
|
|
|
|
// On slow networks it can take several minutes to pull the addon-manager then the dashboard image.
|
2017-08-23 15:51:14 +00:00
|
|
|
if err := util.Retry(t, checkDashboard, 20*time.Second, 25); err != nil {
|
2016-07-18 22:35:37 +00:00
|
|
|
t.Fatalf("Dashboard pod is not healthy: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now restart minikube and make sure the pod is still there.
|
2017-02-22 03:27:51 +00:00
|
|
|
// minikubeRunner.RunCommand("stop", true)
|
|
|
|
// minikubeRunner.CheckStatus("Stopped")
|
|
|
|
checkStop := func() error {
|
|
|
|
minikubeRunner.RunCommand("stop", true)
|
|
|
|
return minikubeRunner.CheckStatusNoFail(state.Stopped.String())
|
|
|
|
}
|
|
|
|
|
2017-08-23 15:51:14 +00:00
|
|
|
if err := util.Retry(t, checkStop, 5*time.Second, 6); err != nil {
|
2017-02-22 03:27:51 +00:00
|
|
|
t.Fatalf("timed out while checking stopped status: %s", err)
|
|
|
|
}
|
2016-07-18 22:35:37 +00:00
|
|
|
|
2017-05-18 16:56:07 +00:00
|
|
|
minikubeRunner.Start()
|
|
|
|
minikubeRunner.CheckStatus(state.Running.String())
|
2016-07-18 22:35:37 +00:00
|
|
|
|
2017-08-23 15:51:14 +00:00
|
|
|
if err := util.Retry(t, checkPod, 3*time.Second, 5); err != nil {
|
2016-07-18 22:35:37 +00:00
|
|
|
t.Fatalf("Error checking the status of pod %s. Err: %s", podName, err)
|
2016-07-12 17:50:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-18 22:35:37 +00:00
|
|
|
// Now make sure it's still running after.
|
2017-08-23 15:51:14 +00:00
|
|
|
if err := util.Retry(t, checkDashboard, 3*time.Second, 5); err != nil {
|
2016-07-12 17:50:44 +00:00
|
|
|
t.Fatalf("Dashboard pod is not healthy: %s", err)
|
|
|
|
}
|
2016-06-29 21:52:10 +00:00
|
|
|
}
|