minikube/test/integration/start_stop_delete_test.go

145 lines
4.5 KiB
Go
Raw Normal View History

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-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-04-29 23:18:49 +00:00
http://www.apache.org/licenses/LICENSE-2.0
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 (
"context"
"fmt"
"os/exec"
"path/filepath"
2016-05-17 15:48:57 +00:00
"strings"
2016-04-29 23:18:49 +00:00
"testing"
"time"
2017-02-22 03:27:51 +00:00
"github.com/docker/machine/libmachine/state"
"k8s.io/minikube/pkg/minikube/constants"
2016-04-29 23:18:49 +00:00
)
func TestStartStop(t *testing.T) {
MaybeParallel(t)
2019-08-01 05:50:04 +00:00
t.Run("group", func(t *testing.T) {
2019-07-30 23:36:53 +00:00
tests := []struct {
name string
args []string
}{
{"docker", []string{
2019-07-30 23:36:53 +00:00
"--cache-images=false",
fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion),
// 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",
"--kvm-qemu-uri=qemu:///system",
"--disable-driver-mounts",
"--keep-context=false",
"--container-runtime=docker",
2019-07-30 23:36:53 +00:00
}},
2019-08-09 00:12:33 +00:00
{"cni", []string{
2019-07-30 23:36:53 +00:00
"--feature-gates",
"ServerSideApply=true",
"--network-plugin=cni",
"--extra-config=kubelet.network-plugin=cni",
"--extra-config=kubeadm.pod-network-cidr=192.168.111.111/16",
fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion),
}},
2019-08-09 00:12:33 +00:00
{"containerd", []string{
2019-07-30 23:36:53 +00:00
"--container-runtime=containerd",
"--docker-opt",
"containerd=/var/run/containerd/containerd.sock",
2019-07-30 23:36:53 +00:00
"--apiserver-port=8444",
}},
2019-08-09 00:12:33 +00:00
{"crio", []string{
2019-07-30 23:36:53 +00:00
"--container-runtime=crio",
2019-08-09 00:12:33 +00:00
"--disable-driver-mounts",
"--extra-config=kubeadm.ignore-preflight-errors=SystemVerification",
2019-07-30 23:36:53 +00:00
}},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
MaybeParallel(t)
2019-08-01 05:50:04 +00:00
if !strings.Contains(tc.name, "docker") && NoneDriver() {
t.Skipf("skipping %s - incompatible with none driver", t.Name())
}
profile := UniqueProfileName(tc.name)
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Minute)
defer CleanupWithLogs(t, profile, cancel)
2019-09-13 14:42:30 +00:00
startArgs := append([]string{"start", "-p", profile, "--alsologtostderr", "-v=1"}, tc.args...)
startArgs = append(startArgs, StartArgs()...)
rr, err := Run(t, exec.CommandContext(ctx, Target(), startArgs...))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
// SADNESS: 0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.
if strings.Contains(tc.name, "cni") {
t.Logf("WARNING: cni mode requires additional setup before pods can schedule :(")
} else {
// schedule a pod to assert persistence
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "create", "-f", filepath.Join(*testdataDir, "busybox.yaml")))
if err != nil {
t.Fatalf("%s failed: %v", rr.Args, err)
}
if _, err := PodWait(ctx, t, profile, "default", "integration-test=busybox", 2*time.Minute); err != nil {
t.Fatalf("wait: %v", err)
}
}
rr, err = Run(t, exec.CommandContext(ctx, Target(), "stop", "-p", profile))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
got := Status(ctx, t, Target(), profile)
if got != state.Stopped.String() {
t.Errorf("status = %q; want = %q", got, state.Stopped)
}
rr, err = Run(t, exec.CommandContext(ctx, Target(), startArgs...))
if err != nil {
// Explicit fatal so that failures don't move directly to deletion
t.Fatalf("%s failed: %v", rr.Args, err)
}
if strings.Contains(tc.name, "cni") {
t.Logf("WARNING: cni mode requires additional setup before pods can schedule :(")
} else if _, err := PodWait(ctx, t, profile, "default", "integration-test=busybox", 2*time.Minute); err != nil {
t.Fatalf("wait: %v", err)
}
got = Status(ctx, t, Target(), profile)
if got != state.Running.String() {
t.Errorf("status = %q; want = %q", got, state.Running)
}
// Normally handled by cleanuprofile, but not fatal there
rr, err = Run(t, exec.CommandContext(ctx, Target(), "delete", "-p", profile))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
})
}
})
2016-04-29 23:18:49 +00:00
}