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) {
|
2019-07-30 01:42:09 +00:00
|
|
|
p := profile(t) // profile name
|
2019-07-26 22:27:05 +00:00
|
|
|
if isTestNoneDriver() {
|
|
|
|
p = "minikube"
|
|
|
|
} else {
|
|
|
|
t.Parallel()
|
|
|
|
}
|
2019-07-24 20:32:32 +00:00
|
|
|
|
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-06-28 21:12:58 +00:00
|
|
|
"--kvm-qemu-uri=qemu:///system",
|
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
|
|
|
|
2019-07-24 20:32:32 +00:00
|
|
|
for _, tc := range tests {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2019-07-26 22:27:05 +00:00
|
|
|
mk := NewMinikubeRunner(t, p)
|
|
|
|
// TODO : check does this ever happen ?
|
|
|
|
if !strings.Contains(tc.name, "docker") && isTestNoneDriver() {
|
2019-07-24 20:32:32 +00:00
|
|
|
t.Skipf("skipping %s - incompatible with none driver", tc.name)
|
2018-12-05 18:23:36 +00:00
|
|
|
}
|
2016-04-29 23:18:49 +00:00
|
|
|
|
2019-07-23 21:58:36 +00:00
|
|
|
mk.RunCommand("config set WantReportErrorPrompt false", true)
|
|
|
|
mk.RunCommand("delete", false)
|
|
|
|
mk.CheckStatus(state.None.String())
|
2019-07-27 05:35:15 +00:00
|
|
|
|
|
|
|
stdout, stderr, err := mk.StartWithStds(15 * time.Minute)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%s minikube start failed : %v\nstdout: %s\nstderr: %s", p, err, stdout, stderr)
|
|
|
|
}
|
|
|
|
|
2019-07-23 21:58:36 +00:00
|
|
|
mk.CheckStatus(state.Running.String())
|
2016-04-29 23:18:49 +00:00
|
|
|
|
2019-07-23 21:58:36 +00:00
|
|
|
ip := mk.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-07-24 20:32:32 +00:00
|
|
|
// TODO: medya move this test to its own test so we can do more parallel
|
|
|
|
// kr := util.NewKubectlRunner(t, p)
|
|
|
|
// currentContext, err := kr.RunCommand([]string{"config", "current-context"}, false)
|
|
|
|
// if err != nil {
|
|
|
|
// t.Fatalf("Failed to fetch current-context")
|
|
|
|
// }
|
|
|
|
// if strings.TrimRight(string(currentContext), "\n") != p {
|
|
|
|
// t.Fatalf("got current-context - %q, want current-context %q", string(currentContext), p)
|
|
|
|
// }
|
2019-04-30 22:32:40 +00:00
|
|
|
|
2018-12-05 18:23:36 +00:00
|
|
|
checkStop := func() error {
|
2019-07-23 21:58:36 +00:00
|
|
|
mk.RunCommand("stop", true)
|
|
|
|
return mk.CheckStatusNoFail(state.Stopped.String())
|
2018-12-05 18:23:36 +00:00
|
|
|
}
|
|
|
|
|
2019-07-26 22:27:05 +00:00
|
|
|
if err := util.Retry(t, checkStop, 10*time.Second, 3); err != nil {
|
2018-12-05 18:23:36 +00:00
|
|
|
t.Fatalf("timed out while checking stopped status: %v", err)
|
|
|
|
}
|
2016-04-29 23:18:49 +00:00
|
|
|
|
2019-07-23 23:39:39 +00:00
|
|
|
// TODO medyagh: the commented code beollow was not correct ! I leave it for another PR
|
|
|
|
// https://github.com/kubernetes/minikube/issues/4854
|
|
|
|
|
2019-05-07 20:58:33 +00:00
|
|
|
// running this command results in error when the current-context is not set
|
2019-07-23 23:39:39 +00:00
|
|
|
// if err := mk.Run("config current-context"); err != nil {
|
|
|
|
// t.Logf("current-context is not set to minikube")
|
|
|
|
// }
|
2019-05-07 20:58:33 +00:00
|
|
|
|
2019-07-24 20:32:32 +00:00
|
|
|
mk.Start(tc.args...)
|
2019-07-23 21:58:36 +00:00
|
|
|
mk.CheckStatus(state.Running.String())
|
2016-04-29 23:18:49 +00:00
|
|
|
|
2019-07-23 21:58:36 +00:00
|
|
|
mk.RunCommand("delete", true)
|
|
|
|
mk.CheckStatus(state.None.String())
|
2018-12-05 18:23:36 +00:00
|
|
|
})
|
|
|
|
}
|
2016-04-29 23:18:49 +00:00
|
|
|
}
|