2016-04-29 23:18:49 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
/*
|
2016-05-01 15:49:51 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
2016-05-02 17:37:01 +00:00
|
|
|
|
2016-04-29 23:18:49 +00:00
|
|
|
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
|
2016-05-02 17:37:01 +00:00
|
|
|
|
2016-04-29 23:18:49 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2016-05-02 17:37:01 +00:00
|
|
|
|
2016-04-29 23:18:49 +00:00
|
|
|
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 (
|
2019-03-26 01:25:01 +00:00
|
|
|
"fmt"
|
2016-05-17 15:48:57 +00:00
|
|
|
"net"
|
|
|
|
"strings"
|
2016-04-29 23:18:49 +00:00
|
|
|
"testing"
|
2016-11-04 16:43:40 +00:00
|
|
|
"time"
|
2016-05-14 01:47:43 +00:00
|
|
|
|
2017-02-22 03:27:51 +00:00
|
|
|
"github.com/docker/machine/libmachine/state"
|
2019-03-26 01:25:01 +00:00
|
|
|
"k8s.io/minikube/pkg/minikube/constants"
|
2016-05-14 01:47:43 +00:00
|
|
|
"k8s.io/minikube/test/integration/util"
|
2016-04-29 23:18:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStartStop(t *testing.T) {
|
2018-12-05 18:23:36 +00:00
|
|
|
tests := []struct {
|
2019-05-04 04:24:32 +00:00
|
|
|
name string
|
|
|
|
args []string
|
2018-12-05 18:23:36 +00:00
|
|
|
}{
|
2019-03-26 04:02:44 +00:00
|
|
|
{"nocache_oldest", []string{
|
2019-03-26 01:25:01 +00:00
|
|
|
"--cache-images=false",
|
|
|
|
fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion),
|
2019-05-23 05:30:21 +00:00
|
|
|
// default is the network created by libvirt, if we change the name minikube won't boot
|
|
|
|
// because the given network doesn't exist
|
|
|
|
"--kvm-network=default",
|
2019-05-04 04:24:32 +00:00
|
|
|
}},
|
2019-03-27 03:26:47 +00:00
|
|
|
{"feature_gates_newest_cni", []string{
|
2019-03-26 01:25:01 +00:00
|
|
|
"--feature-gates",
|
2019-03-26 04:02:44 +00:00
|
|
|
"ServerSideApply=true",
|
2019-03-27 03:26:47 +00:00
|
|
|
"--network-plugin=cni",
|
|
|
|
"--extra-config=kubelet.network-plugin=cni",
|
2019-05-04 04:24:32 +00:00
|
|
|
"--extra-config=kubeadm.pod-network-cidr=192.168.111.111/16",
|
2019-03-26 01:25:01 +00:00
|
|
|
fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion),
|
|
|
|
}},
|
2019-04-05 22:36:35 +00:00
|
|
|
{"containerd_and_non_default_apiserver_port", []string{
|
2019-03-26 01:25:01 +00:00
|
|
|
"--container-runtime=containerd",
|
|
|
|
"--docker-opt containerd=/var/run/containerd/containerd.sock",
|
2019-04-05 22:36:35 +00:00
|
|
|
"--apiserver-port=8444",
|
2019-03-26 01:25:01 +00:00
|
|
|
}},
|
2019-03-26 04:02:44 +00:00
|
|
|
{"crio_ignore_preflights", []string{
|
2019-03-26 01:25:01 +00:00
|
|
|
"--container-runtime=crio",
|
2019-03-26 04:02:44 +00:00
|
|
|
"--extra-config",
|
|
|
|
"kubeadm.ignore-preflight-errors=SystemVerification",
|
2019-05-04 04:24:32 +00:00
|
|
|
}},
|
2018-12-05 18:23:36 +00:00
|
|
|
}
|
2016-04-29 23:18:49 +00:00
|
|
|
|
2018-12-05 18:23:36 +00:00
|
|
|
for _, test := range tests {
|
2019-02-27 21:58:33 +00:00
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
r := NewMinikubeRunner(t)
|
|
|
|
if !strings.Contains(test.name, "docker") && usingNoneDriver(r) {
|
|
|
|
t.Skipf("skipping %s - incompatible with none driver", test.name)
|
2018-12-05 18:23:36 +00:00
|
|
|
}
|
2016-04-29 23:18:49 +00:00
|
|
|
|
2019-02-27 21:58:33 +00:00
|
|
|
r.RunCommand("config set WantReportErrorPrompt false", true)
|
|
|
|
r.RunCommand("delete", false)
|
|
|
|
r.CheckStatus(state.None.String())
|
|
|
|
r.Start(test.args...)
|
|
|
|
r.CheckStatus(state.Running.String())
|
2016-04-29 23:18:49 +00:00
|
|
|
|
2019-02-27 21:58:33 +00:00
|
|
|
ip := r.RunCommand("ip", true)
|
2018-12-05 18:23:36 +00:00
|
|
|
ip = strings.TrimRight(ip, "\n")
|
|
|
|
if net.ParseIP(ip) == nil {
|
|
|
|
t.Fatalf("IP command returned an invalid address: %s", ip)
|
|
|
|
}
|
2016-11-04 16:43:40 +00:00
|
|
|
|
2019-04-30 23:24:30 +00:00
|
|
|
// check for the current-context before and after the stop
|
2019-05-02 16:47:08 +00:00
|
|
|
kubectlRunner := util.NewKubectlRunner(t)
|
|
|
|
currentContext, err := kubectlRunner.RunCommand([]string{"config", "current-context"})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to fetch current-context")
|
|
|
|
}
|
2019-05-03 21:12:11 +00:00
|
|
|
if strings.TrimRight(string(currentContext), "\n") != "minikube" {
|
2019-05-02 19:17:33 +00:00
|
|
|
t.Fatalf("got current-context - %q, want current-context %q", string(currentContext), "minikube")
|
2019-04-30 22:32:40 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 18:23:36 +00:00
|
|
|
checkStop := func() error {
|
2019-02-27 21:58:33 +00:00
|
|
|
r.RunCommand("stop", true)
|
|
|
|
return r.CheckStatusNoFail(state.Stopped.String())
|
2018-12-05 18:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := util.Retry(t, checkStop, 5*time.Second, 6); err != nil {
|
|
|
|
t.Fatalf("timed out while checking stopped status: %v", err)
|
|
|
|
}
|
2016-04-29 23:18:49 +00:00
|
|
|
|
2019-05-07 20:58:33 +00:00
|
|
|
// running this command results in error when the current-context is not set
|
|
|
|
if err := r.Run("config current-context"); err != nil {
|
|
|
|
t.Logf("current-context is not set to minikube")
|
|
|
|
}
|
|
|
|
|
2019-03-06 23:50:57 +00:00
|
|
|
r.Start(test.args...)
|
2019-02-27 21:58:33 +00:00
|
|
|
r.CheckStatus(state.Running.String())
|
2016-04-29 23:18:49 +00:00
|
|
|
|
2019-02-27 21:58:33 +00:00
|
|
|
r.RunCommand("delete", true)
|
|
|
|
r.CheckStatus(state.None.String())
|
2018-12-05 18:23:36 +00:00
|
|
|
})
|
|
|
|
}
|
2016-04-29 23:18:49 +00:00
|
|
|
}
|