func startPodAndGetBackOffs(podClient *framework.PodClient, pod *v1.Pod, sleepAmount time.Duration) (time.Duration, time.Duration) { podClient.CreateSync(pod) time.Sleep(sleepAmount) Expect(pod.Spec.Containers).NotTo(BeEmpty()) podName := pod.Name containerName := pod.Spec.Containers[0].Name By("getting restart delay-0") _, err := getRestartDelay(podClient, podName, containerName) if err != nil { framework.Failf("timed out waiting for container restart in pod=%s/%s", podName, containerName) } By("getting restart delay-1") delay1, err := getRestartDelay(podClient, podName, containerName) if err != nil { framework.Failf("timed out waiting for container restart in pod=%s/%s", podName, containerName) } By("getting restart delay-2") delay2, err := getRestartDelay(podClient, podName, containerName) if err != nil { framework.Failf("timed out waiting for container restart in pod=%s/%s", podName, containerName) } return delay1, delay2 }
func createIdlePod(podName string, podClient *framework.PodClient) { podClient.Create(&api.Pod{ ObjectMeta: api.ObjectMeta{ Name: podName, }, Spec: api.PodSpec{ RestartPolicy: api.RestartPolicyNever, Containers: []api.Container{ { Image: ImageRegistry[pauseImage], Name: podName, }, }, }, }) }
func createIdlePod(podName string, podClient *framework.PodClient) { podClient.Create(&api.Pod{ ObjectMeta: api.ObjectMeta{ Name: podName, }, Spec: api.PodSpec{ RestartPolicy: api.RestartPolicyNever, Containers: []api.Container{ { Image: framework.GetPauseImageNameForHostArch(), Name: podName, }, }, }, }) }
func createSummaryTestPods(podClient *framework.PodClient, podNamePrefix string, count int, volumeNamePrefix string) (sets.String, sets.String) { podNames := sets.NewString() volumes := sets.NewString(volumeNamePrefix) for i := 0; i < count; i++ { podNames.Insert(fmt.Sprintf("%s%v", podNamePrefix, i)) } var pods []*api.Pod for _, podName := range podNames.List() { pods = append(pods, &api.Pod{ ObjectMeta: api.ObjectMeta{ Name: podName, }, Spec: api.PodSpec{ // Don't restart the Pod since it is expected to exit RestartPolicy: api.RestartPolicyNever, Containers: []api.Container{ { Image: ImageRegistry[busyBoxImage], Command: []string{"sh", "-c", "while true; do echo 'hello world' | tee /test-empty-dir-mnt/file ; sleep 1; done"}, Name: podName + containerSuffix, VolumeMounts: []api.VolumeMount{ {MountPath: "/test-empty-dir-mnt", Name: volumeNamePrefix}, }, }, }, SecurityContext: &api.PodSecurityContext{ SELinuxOptions: &api.SELinuxOptions{ Level: "s0", }, }, Volumes: []api.Volume{ // TODO: Test secret volumes // TODO: Test hostpath volumes {Name: volumeNamePrefix, VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}, }, }, }) } podClient.CreateBatch(pods) return podNames, volumes }
func getRestartDelay(podClient *framework.PodClient, podName string, containerName string) (time.Duration, error) { beginTime := time.Now() for time.Since(beginTime) < (2 * maxBackOffTolerance) { // may just miss the 1st MaxContainerBackOff delay time.Sleep(time.Second) pod, err := podClient.Get(podName, metav1.GetOptions{}) framework.ExpectNoError(err, fmt.Sprintf("getting pod %s", podName)) status, ok := v1.GetContainerStatus(pod.Status.ContainerStatuses, containerName) if !ok { framework.Logf("getRestartDelay: status missing") continue } if status.State.Waiting == nil && status.State.Running != nil && status.LastTerminationState.Terminated != nil && status.State.Running.StartedAt.Time.After(beginTime) { startedAt := status.State.Running.StartedAt.Time finishedAt := status.LastTerminationState.Terminated.FinishedAt.Time framework.Logf("getRestartDelay: restartCount = %d, finishedAt=%s restartedAt=%s (%s)", status.RestartCount, finishedAt, startedAt, startedAt.Sub(finishedAt)) return startedAt.Sub(finishedAt), nil } } return 0, fmt.Errorf("timeout getting pod restart delay") }
// testHostIP tests that a pod gets a host IP func testHostIP(podClient *framework.PodClient, pod *v1.Pod) { By("creating pod") podClient.CreateSync(pod) // Try to make sure we get a hostIP for each pod. hostIPTimeout := 2 * time.Minute t := time.Now() for { p, err := podClient.Get(pod.Name, metav1.GetOptions{}) Expect(err).NotTo(HaveOccurred(), "Failed to get pod %q", pod.Name) if p.Status.HostIP != "" { framework.Logf("Pod %s has hostIP: %s", p.Name, p.Status.HostIP) break } if time.Since(t) >= hostIPTimeout { framework.Failf("Gave up waiting for hostIP of pod %s after %v seconds", p.Name, time.Since(t).Seconds()) } framework.Logf("Retrying to get the hostIP of pod %s", p.Name) time.Sleep(5 * time.Second) } }
continue } if status.State.Waiting == nil && status.State.Running != nil && status.LastTerminationState.Terminated != nil && status.State.Running.StartedAt.Time.After(beginTime) { startedAt := status.State.Running.StartedAt.Time finishedAt := status.LastTerminationState.Terminated.FinishedAt.Time framework.Logf("getRestartDelay: restartCount = %d, finishedAt=%s restartedAt=%s (%s)", status.RestartCount, finishedAt, startedAt, startedAt.Sub(finishedAt)) return startedAt.Sub(finishedAt), nil } } return 0, fmt.Errorf("timeout getting pod restart delay") } var _ = framework.KubeDescribe("Pods", func() { f := framework.NewDefaultFramework("pods") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) It("should get a host IP [Conformance]", func() { name := "pod-hostip-" + string(uuid.NewUUID()) testHostIP(podClient, &v1.Pod{ ObjectMeta: v1.ObjectMeta{ Name: name, }, Spec: v1.PodSpec{ Containers: []v1.Container{ { Name: "test", Image: framework.GetPauseImageName(f.ClientSet),
client "k8s.io/kubernetes/pkg/client/unversioned" ) const ( // podCheckInterval is the interval seconds between pod status checks. podCheckInterval = time.Second * 2 dummyFile = "dummy." ) // TODO: Leverage dynamic Kubelet settings when it's implemented to only modify the kubelet eviction option in this test. // To manually trigger the test on a node with disk space just over 15Gi : // make test-e2e-node FOCUS="hard eviction test" TEST_ARGS="--eviction-hard=nodefs.available<15Gi" var _ = framework.KubeDescribe("Kubelet Eviction Manager [Flaky] [Serial] [Disruptive]", func() { f := framework.NewDefaultFramework("kubelet-eviction-manager") var podClient *framework.PodClient var c *client.Client var n *api.Node BeforeEach(func() { podClient = f.PodClient() c = f.Client nodeList := framework.GetReadySchedulableNodesOrDie(c) n = &nodeList.Items[0] }) Describe("hard eviction test", func() { Context("pod using the most disk space gets evicted when the node disk usage is above the eviction hard threshold", func() { var busyPodName, idlePodName string var containersToCleanUp map[string]bool
"time" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/pkg/util/wait" "k8s.io/kubernetes/pkg/watch" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Pods Delete Grace Period", func() { f := framework.NewDefaultFramework("pods") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) It("should be submitted and removed [Conformance]", func() { By("creating the pod") name := "pod-submit-remove-" + string(uuid.NewUUID()) value := strconv.Itoa(time.Now().Nanosecond()) pod := &api.Pod{ ObjectMeta: api.ObjectMeta{ Name: name, Labels: map[string]string{ "name": "foo", "time": value, }, },
testutils "k8s.io/kubernetes/test/utils" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) const ( probTestContainerName = "test-webserver" probTestInitialDelaySeconds = 15 defaultObservationTimeout = time.Minute * 2 ) var _ = framework.KubeDescribe("Probing container", func() { f := framework.NewDefaultFramework("container-probe") var podClient *framework.PodClient probe := webserverProbeBuilder{} BeforeEach(func() { podClient = f.PodClient() }) It("with readiness probe should not be ready before initial delay and never restart [Conformance]", func() { p := podClient.Create(makePodSpec(probe.withInitialDelay().build(), nil)) f.WaitForPodReady(p.Name) p, err := podClient.Get(p.Name, metav1.GetOptions{}) framework.ExpectNoError(err) isReady, err := testutils.PodRunningReady(p) framework.ExpectNoError(err) Expect(isReady).To(BeTrue(), "pod should be ready")
"fmt" "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/kubelet/events" "k8s.io/kubernetes/pkg/kubelet/sysctl" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/pkg/util/wait" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Sysctls", func() { f := framework.NewDefaultFramework("sysctl") var podClient *framework.PodClient testPod := func() *v1.Pod { podName := "sysctl-" + string(uuid.NewUUID()) pod := v1.Pod{ ObjectMeta: v1.ObjectMeta{ Name: podName, Annotations: map[string]string{}, }, Spec: v1.PodSpec{ Containers: []v1.Container{ { Name: "test-container", Image: "gcr.io/google_containers/busybox:1.24", }, },
// podDisappearTimeout is the timeout to wait node disappear. podDisappearTimeout = time.Minute * 2 // containerGCPeriod is the period of container garbage collect loop. It should be the same // with ContainerGCPeriod in kubelet.go. However we don't want to include kubelet package // directly which will introduce a lot more dependencies. containerGCPeriod = time.Minute * 1 dummyFile = "dummy." ) // TODO: Leverage dynamic Kubelet settings when it's implemented to only modify the kubelet eviction option in this test. var _ = framework.KubeDescribe("Kubelet Eviction Manager [Serial] [Disruptive]", func() { f := framework.NewDefaultFramework("kubelet-eviction-manager") var podClient *framework.PodClient var c clientset.Interface BeforeEach(func() { podClient = f.PodClient() c = f.ClientSet }) Describe("hard eviction test", func() { Context("pod using the most disk space gets evicted when the node disk usage is above the eviction hard threshold", func() { var busyPodName, idlePodName, verifyPodName string BeforeEach(func() { if !isImageSupported() { framework.Skipf("test skipped because the image is not supported by the test") }
"time" "k8s.io/kubernetes/pkg/api/resource" "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Downward API volume", func() { // How long to wait for a log pod to be displayed const podLogTimeout = 2 * time.Minute f := framework.NewDefaultFramework("downward-api") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) It("should provide podname only [Conformance]", func() { podName := "downwardapi-volume-" + string(uuid.NewUUID()) pod := downwardAPIVolumePodForSimpleTest(podName, "/etc/podname") f.TestContainerOutput("downward API volume plugin", pod, 0, []string{ fmt.Sprintf("%s\n", podName), }) }) It("should set DefaultMode on files [Conformance]", func() { podName := "downwardapi-volume-" + string(uuid.NewUUID())
"bytes" "fmt" "time" apiUnversioned "k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Kubelet", func() { f := framework.NewDefaultFramework("kubelet-test") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) Context("when scheduling a busybox command in a pod", func() { podName := "busybox-scheduling-" + string(uuid.NewUUID()) It("it should print the output to logs [Conformance]", func() { podClient.CreateSync(&v1.Pod{ ObjectMeta: v1.ObjectMeta{ Name: podName, }, Spec: v1.PodSpec{ // Don't restart the Pod since it is expected to exit RestartPolicy: v1.RestartPolicyNever, Containers: []v1.Container{ {
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/kubelet/events" "k8s.io/kubernetes/pkg/kubelet/sysctl" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Sysctls", func() { f := framework.NewDefaultFramework("sysctl") var podClient *framework.PodClient testPod := func() *v1.Pod { podName := "sysctl-" + string(uuid.NewUUID()) pod := v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: podName, Annotations: map[string]string{}, }, Spec: v1.PodSpec{ Containers: []v1.Container{ { Name: "test-container", Image: "gcr.io/google_containers/busybox:1.24", }, },
"k8s.io/kubernetes/pkg/api/v1" metav1 "k8s.io/kubernetes/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/pkg/util/wait" "k8s.io/kubernetes/pkg/watch" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Pods Delete Grace Period", func() { f := framework.NewDefaultFramework("pods") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) It("should be submitted and removed [Conformance]", func() { By("creating the pod") name := "pod-submit-remove-" + string(uuid.NewUUID()) value := strconv.Itoa(time.Now().Nanosecond()) pod := &v1.Pod{ ObjectMeta: v1.ObjectMeta{ Name: name, Labels: map[string]string{ "name": "foo", "time": value, }, },
import ( "fmt" "time" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/util/intstr" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" ) var _ = framework.KubeDescribe("Container Lifecycle Hook", func() { f := framework.NewDefaultFramework("container-lifecycle-hook") var podClient *framework.PodClient var file string const podWaitTimeout = 2 * time.Minute testPodWithHook := func(podWithHook *api.Pod) { podCheckHook := getLifecycleHookTestPod("pod-check-hook", // Wait until the file is created. []string{"sh", "-c", fmt.Sprintf("while [ ! -e %s ]; do sleep 1; done", file)}, ) By("create the pod with lifecycle hook") podClient.CreateSync(podWithHook) if podWithHook.Spec.Containers[0].Lifecycle.PostStart != nil { By("create the hook check pod") podClient.Create(podCheckHook) By("wait for the hook check pod to success") podClient.WaitForSuccess(podCheckHook.Name, podWaitTimeout)
"k8s.io/kubernetes/pkg/api" apiUnversioned "k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/stats" "k8s.io/kubernetes/pkg/util/sets" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/test/e2e/framework" "github.com/davecgh/go-spew/spew" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Kubelet", func() { f := framework.NewDefaultFramework("kubelet-test") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) Context("when scheduling a busybox command in a pod", func() { podName := "busybox-scheduling-" + string(uuid.NewUUID()) It("it should print the output to logs", func() { podClient.CreateSync(&api.Pod{ ObjectMeta: api.ObjectMeta{ Name: podName, }, Spec: api.PodSpec{ // Don't restart the Pod since it is expected to exit RestartPolicy: api.RestartPolicyNever, Containers: []api.Container{ {
"k8s.io/kubernetes/pkg/api/resource" "k8s.io/kubernetes/pkg/api/v1" podutil "k8s.io/kubernetes/pkg/api/v1/pod" "k8s.io/kubernetes/pkg/client/conditions" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/pkg/watch" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("InitContainer", func() { f := framework.NewDefaultFramework("init-container") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) It("should invoke init containers on a RestartNever pod", func() { framework.SkipIfContainerRuntimeIs("rkt") // #25988 By("creating the pod") name := "pod-init-" + string(uuid.NewUUID()) value := strconv.Itoa(time.Now().Nanosecond()) pod := &v1.Pod{ ObjectMeta: v1.ObjectMeta{ Name: name, Labels: map[string]string{ "name": "foo",
import ( "fmt" "time" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Kubelet Container Manager", func() { f := framework.NewDefaultFramework("kubelet-container-manager") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) Describe("oom score adjusting", func() { Context("when scheduling a busybox command that always fails in a pod", func() { var podName string BeforeEach(func() { podName = "bin-false" + string(util.NewUUID()) podClient.Create(&api.Pod{ ObjectMeta: api.ObjectMeta{ Name: podName, },
"time" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/resource" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Downward API volume", func() { // How long to wait for a log pod to be displayed const podLogTimeout = 2 * time.Minute f := framework.NewDefaultFramework("downward-api") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) It("should provide podname only [Conformance]", func() { podName := "downwardapi-volume-" + string(uuid.NewUUID()) pod := downwardAPIVolumePodForSimpleTest(podName, "/etc/podname") f.TestContainerOutput("downward API volume plugin", pod, 0, []string{ fmt.Sprintf("%s\n", podName), }) }) It("should set DefaultMode on files [Conformance]", func() { podName := "downwardapi-volume-" + string(uuid.NewUUID())
import ( "fmt" "time" "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/util/intstr" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("Container Lifecycle Hook", func() { f := framework.NewDefaultFramework("container-lifecycle-hook") var podClient *framework.PodClient const ( podCheckInterval = 1 * time.Second podWaitTimeout = 2 * time.Minute postStartWaitTimeout = 2 * time.Minute preStopWaitTimeout = 30 * time.Second ) Context("when create a pod with lifecycle hook", func() { BeforeEach(func() { podClient = f.PodClient() }) Context("when it is exec hook", func() { var file string testPodWithExecHook := func(podWithHook *v1.Pod) { podCheckHook := getExecHookTestPod("pod-check-hook",
"time" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/resource" client "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/util/uuid" "k8s.io/kubernetes/pkg/watch" "k8s.io/kubernetes/test/e2e/framework" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = framework.KubeDescribe("InitContainer", func() { f := framework.NewDefaultFramework("init-container") var podClient *framework.PodClient BeforeEach(func() { podClient = f.PodClient() }) It("should invoke init containers on a RestartNever pod", func() { framework.SkipIfContainerRuntimeIs("rkt") // #25988 By("creating the pod") name := "pod-init-" + string(uuid.NewUUID()) value := strconv.Itoa(time.Now().Nanosecond()) pod := &api.Pod{ ObjectMeta: api.ObjectMeta{ Name: name, Labels: map[string]string{ "name": "foo",