Change:
The prestop and poststart exec tests volume mount /tmp from the host and attempt to create a file there from inside the pod. This is blocked by selinux. Failure:
we need to have a mechanism to say that a test should not be run if selinux is enabled (if legitimately required) or fix each test (where appropriate)

Discussion:
package e2e_node import ( <del> "fmt" </del> "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" <del> "k8s.io/apimachinery/pkg/util/uuid" </del> "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/test/e2e/framework"

var podClient *framework.PodClient const ( podCheckInterval     = 1 * time.Second <del> podWaitTimeout       = 3 * time.Minute </del> postStartWaitTimeout = 2 * time.Minute preStopWaitTimeout   = 30 * time.Second ) Context("when create a pod with lifecycle hook", func() { <ins> var targetIP string podHandleHookRequest := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "pod-handle-http-request", }, Spec: v1.PodSpec{ Containers: []v1.Container{ { Name:  "pod-handle-http-request", Image: "gcr.io/google_containers/netexec:1.7", Ports: []v1.ContainerPort{ { ContainerPort: 8080, Protocol:      v1.ProtocolTCP, }, }, }, }, }, } </ins> BeforeEach(func() { podClient = f.PodClient() <ins> By("create the container to handle the HTTPGet hook request.") newPod := podClient.CreateSync(podHandleHookRequest) targetIP = newPod.Status.PodIP </ins> }) <del> Context("when it is exec hook", func() { var file string testPodWithExecHook := func(podWithHook *v1.Pod) { podCheckHook := getExecHookTestPod("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, postStartWaitTimeout) } By("delete the pod with lifecycle hook") podClient.DeleteSync(podWithHook.Name, metav1.NewDeleteOptions(15), framework.DefaultPodDeletionTimeout) if podWithHook.Spec.Containers[0].Lifecycle.PreStop != nil { By("create the hook check pod") podClient.Create(podCheckHook) By("wait for the prestop check pod to success") podClient.WaitForSuccess(podCheckHook.Name, preStopWaitTimeout) } </del> <ins> testPodWithHook := func(podWithHook *v1.Pod) { By("create the pod with lifecycle hook") podClient.CreateSync(podWithHook) if podWithHook.Spec.Containers[0].Lifecycle.PostStart != nil { By("check poststart hook") Eventually(func() error { return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[0].Name, `GET /echo?msg=poststart`) }, postStartWaitTimeout, podCheckInterval).Should(BeNil()) </ins> } <del> BeforeEach(func() { file = "/tmp/test-" + string(uuid.NewUUID()) }) AfterEach(func() { By("cleanup the temporary file created in the test.") cleanupPod := getExecHookTestPod("pod-clean-up", []string{"rm", file}) podClient.Create(cleanupPod) podClient.WaitForSuccess(cleanupPod.Name, podWaitTimeout) }) It("should execute poststart exec hook properly [Conformance]", func() { podWithHook := getExecHookTestPod("pod-with-poststart-exec-hook", // Block forever []string{"tail", "-f", "/dev/null"}, ) podWithHook.Spec.Containers[0].Lifecycle = &v1.Lifecycle{ PostStart: &v1.Handler{ Exec: &v1.ExecAction{Command: []string{"touch", file}}, }, } testPodWithExecHook(podWithHook) }) It("should execute prestop exec hook properly [Conformance]", func() { podWithHook := getExecHookTestPod("pod-with-prestop-exec-hook", // Block forever []string{"tail", "-f", "/dev/null"}, ) podWithHook.Spec.Containers[0].Lifecycle = &v1.Lifecycle{ PreStop: &v1.Handler{ Exec: &v1.ExecAction{Command: []string{"touch", file}}, </del> <ins> By("delete the pod with lifecycle hook") podClient.DeleteSync(podWithHook.Name, metav1.NewDeleteOptions(15), framework.DefaultPodDeletionTimeout) if podWithHook.Spec.Containers[0].Lifecycle.PreStop != nil { By("check prestop hook") Eventually(func() error { return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[0].Name, `GET /echo?msg=prestop`) }, preStopWaitTimeout, podCheckInterval).Should(BeNil()) } } It("should execute poststart exec hook properly [Conformance]", func() { lifecycle := &v1.Lifecycle{ PostStart: &v1.Handler{ Exec: &v1.ExecAction{ Command: []string{"sh", "-c", "curl http://" + targetIP + ":8080/echo?msg=poststart"}, </ins> }, <del> } testPodWithExecHook(podWithHook) }) }) Context("when it is http hook", func() { var targetIP string podHandleHookRequest := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "pod-handle-http-request", </del> }, <del> Spec: v1.PodSpec{ Containers: []v1.Container{ { Name:  "pod-handle-http-request", Image: "gcr.io/google_containers/netexec:1.7", Ports: []v1.ContainerPort{ { ContainerPort: 8080, Protocol:      v1.ProtocolTCP, }, }, }, </del> <ins> } podWithHook := getPodWithHook("pod-with-poststart-exec-hook", "gcr.io/google_containers/hostexec:1.2", lifecycle) testPodWithHook(podWithHook) }) It("should execute prestop exec hook properly [Conformance]", func() { lifecycle := &v1.Lifecycle{ PreStop: &v1.Handler{ Exec: &v1.ExecAction{ Command: []string{"sh", "-c", "curl http://" + targetIP + ":8080/echo?msg=prestop"}, </ins> }, }, } <del> BeforeEach(func() { By("create the container to handle the HTTPGet hook request.") newPod := podClient.CreateSync(podHandleHookRequest) targetIP = newPod.Status.PodIP }) testPodWithHttpHook := func(podWithHook *v1.Pod) { By("create the pod with lifecycle hook") podClient.CreateSync(podWithHook) if podWithHook.Spec.Containers[0].Lifecycle.PostStart != nil { By("check poststart hook") Eventually(func() error { return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[0].Name, `GET /echo?msg=poststart`) }, postStartWaitTimeout, podCheckInterval).Should(BeNil()) } By("delete the pod with lifecycle hook") podClient.DeleteSync(podWithHook.Name, metav1.NewDeleteOptions(15), framework.DefaultPodDeletionTimeout) if podWithHook.Spec.Containers[0].Lifecycle.PreStop != nil { By("check prestop hook") Eventually(func() error { return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[0].Name, `GET /echo?msg=prestop`) }, preStopWaitTimeout, podCheckInterval).Should(BeNil()) } } It("should execute poststart http hook properly [Conformance]", func() { podWithHook := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "pod-with-poststart-http-hook", }, Spec: v1.PodSpec{ Containers: []v1.Container{ { Name:  "pod-with-poststart-http-hook", Image: framework.GetPauseImageNameForHostArch(), Lifecycle: &v1.Lifecycle{ PostStart: &v1.Handler{ HTTPGet: &v1.HTTPGetAction{ Path: "/echo?msg=poststart", Host: targetIP, Port: intstr.FromInt(8080), }, }, }, }, }, }, } testPodWithHttpHook(podWithHook) }) It("should execute prestop http hook properly [Conformance]", func() { podWithHook := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "pod-with-prestop-http-hook", </del> <ins> podWithHook := getPodWithHook("pod-with-prestop-exec-hook", "gcr.io/google_containers/hostexec:1.2", lifecycle) testPodWithHook(podWithHook) }) It("should execute poststart http hook properly [Conformance]", func() { lifecycle := &v1.Lifecycle{ PostStart: &v1.Handler{ HTTPGet: &v1.HTTPGetAction{ Path: "/echo?msg=poststart", Host: targetIP, Port: intstr.FromInt(8080), </ins> }, <del> Spec: v1.PodSpec{ Containers: []v1.Container{ { Name:  "pod-with-prestop-http-hook", Image: framework.GetPauseImageNameForHostArch(), Lifecycle: &v1.Lifecycle{ PreStop: &v1.Handler{ HTTPGet: &v1.HTTPGetAction{ Path: "/echo?msg=prestop", Host: targetIP, Port: intstr.FromInt(8080), }, }, }, }, }, </del> <ins> }, } podWithHook := getPodWithHook("pod-with-poststart-http-hook", framework.GetPauseImageNameForHostArch(), lifecycle) testPodWithHook(podWithHook) }) It("should execute prestop http hook properly [Conformance]", func() { lifecycle := &v1.Lifecycle{ PreStop: &v1.Handler{ HTTPGet: &v1.HTTPGetAction{ Path: "/echo?msg=prestop", Host: targetIP, Port: intstr.FromInt(8080), </ins> }, <del> } testPodWithHttpHook(podWithHook) }) </del> <ins> }, } podWithHook := getPodWithHook("pod-with-prestop-http-hook", framework.GetPauseImageNameForHostArch(), lifecycle) testPodWithHook(podWithHook) </ins> }) }) }) <del> func getExecHookTestPod(name string, cmd []string) *v1.Pod { </del> <ins> func getPodWithHook(name string, image string, lifecycle *v1.Lifecycle) *v1.Pod { </ins> return &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: name,

Spec: v1.PodSpec{ Containers: []v1.Container{ { <del> Name:  name, Image: "gcr.io/google_containers/busybox:1.24", VolumeMounts: []v1.VolumeMount{ { Name:      "tmpfs", MountPath: "/tmp", }, }, Command: cmd, }, }, RestartPolicy: v1.RestartPolicyNever, Volumes: []v1.Volume{ { Name:         "tmpfs", VolumeSource: v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: "/tmp"}}, </del> <ins> Name:      name, Image:     image, Lifecycle: lifecycle, </ins> }, }, },