Skip to content

Commit

Permalink
Merge pull request kubernetes#101063 from claudiubelu/tests/lifecycle…
Browse files Browse the repository at this point in the history
…-hooks

tests: Spawn poststart / prestop pods on the same node as the http pod
  • Loading branch information
k8s-ci-robot authored Aug 12, 2021
2 parents 98e5263 + f9e4a01 commit e6c7837
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
12 changes: 6 additions & 6 deletions test/conformance/testdata/conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1641,9 +1641,9 @@
hook should execute poststart http hook properly [NodeConformance] [Conformance]'
description: When a post start handler is specified in the container lifecycle using
a HttpGet action, then the handler MUST be invoked after the start of the container.
A server pod is created that will serve http requests, create a second pod with
a container lifecycle specifying a post start that invokes the server pod to validate
that the post start is executed.
A server pod is created that will serve http requests, create a second pod on
the same node with a container lifecycle specifying a post start that invokes
the server pod to validate that the post start is executed.
release: v1.9
file: test/e2e/common/node/lifecycle_hook.go
- testname: Pod Lifecycle, prestop exec hook
Expand All @@ -1661,9 +1661,9 @@
hook should execute prestop http hook properly [NodeConformance] [Conformance]'
description: When a pre-stop handler is specified in the container lifecycle using
a 'HttpGet' action, then the handler MUST be invoked before the container is terminated.
A server pod is created that will serve http requests, create a second pod with
a container lifecycle specifying a pre-stop that invokes the server pod to validate
that the pre-stop is executed.
A server pod is created that will serve http requests, create a second pod on
the same node with a container lifecycle specifying a pre-stop that invokes the
server pod to validate that the pre-stop is executed.
release: v1.9
file: test/e2e/common/node/lifecycle_hook.go
- testname: Container Runtime, TerminationMessage, from log output of succeeding container
Expand Down
23 changes: 20 additions & 3 deletions test/e2e/common/node/lifecycle_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/kubernetes/test/e2e/framework"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
imageutils "k8s.io/kubernetes/test/utils/image"

Expand All @@ -41,7 +42,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
preStopWaitTimeout = 30 * time.Second
)
ginkgo.Context("when create a pod with lifecycle hook", func() {
var targetIP, targetURL string
var targetIP, targetURL, targetNode string
ports := []v1.ContainerPort{
{
ContainerPort: 8080,
Expand All @@ -50,6 +51,13 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
}
podHandleHookRequest := e2epod.NewAgnhostPod("", "pod-handle-http-request", nil, nil, ports, "netexec")
ginkgo.BeforeEach(func() {
node, err := e2enode.GetRandomReadySchedulableNode(f.ClientSet)
framework.ExpectNoError(err)
targetNode = node.Name
nodeSelection := e2epod.NodeSelection{}
e2epod.SetAffinity(&nodeSelection, targetNode)
e2epod.SetNodeSelection(&podHandleHookRequest.Spec, nodeSelection)

podClient = f.PodClient()
ginkgo.By("create the container to handle the HTTPGet hook request.")
newPod := podClient.CreateSync(podHandleHookRequest)
Expand Down Expand Up @@ -93,6 +101,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
},
}
podWithHook := getPodWithHook("pod-with-poststart-exec-hook", imageutils.GetE2EImage(imageutils.Agnhost), lifecycle)

testPodWithHook(podWithHook)
})
/*
Expand All @@ -114,7 +123,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
/*
Release: v1.9
Testname: Pod Lifecycle, post start http hook
Description: When a post start handler is specified in the container lifecycle using a HttpGet action, then the handler MUST be invoked after the start of the container. A server pod is created that will serve http requests, create a second pod with a container lifecycle specifying a post start that invokes the server pod to validate that the post start is executed.
Description: When a post start handler is specified in the container lifecycle using a HttpGet action, then the handler MUST be invoked after the start of the container. A server pod is created that will serve http requests, create a second pod on the same node with a container lifecycle specifying a post start that invokes the server pod to validate that the post start is executed.
*/
framework.ConformanceIt("should execute poststart http hook properly [NodeConformance]", func() {
lifecycle := &v1.Lifecycle{
Expand All @@ -127,12 +136,16 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
},
}
podWithHook := getPodWithHook("pod-with-poststart-http-hook", imageutils.GetPauseImageName(), lifecycle)
// make sure we spawn the test pod on the same node as the webserver.
nodeSelection := e2epod.NodeSelection{}
e2epod.SetAffinity(&nodeSelection, targetNode)
e2epod.SetNodeSelection(&podWithHook.Spec, nodeSelection)
testPodWithHook(podWithHook)
})
/*
Release: v1.9
Testname: Pod Lifecycle, prestop http hook
Description: When a pre-stop handler is specified in the container lifecycle using a 'HttpGet' action, then the handler MUST be invoked before the container is terminated. A server pod is created that will serve http requests, create a second pod with a container lifecycle specifying a pre-stop that invokes the server pod to validate that the pre-stop is executed.
Description: When a pre-stop handler is specified in the container lifecycle using a 'HttpGet' action, then the handler MUST be invoked before the container is terminated. A server pod is created that will serve http requests, create a second pod on the same node with a container lifecycle specifying a pre-stop that invokes the server pod to validate that the pre-stop is executed.
*/
framework.ConformanceIt("should execute prestop http hook properly [NodeConformance]", func() {
lifecycle := &v1.Lifecycle{
Expand All @@ -145,6 +158,10 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
},
}
podWithHook := getPodWithHook("pod-with-prestop-http-hook", imageutils.GetPauseImageName(), lifecycle)
// make sure we spawn the test pod on the same node as the webserver.
nodeSelection := e2epod.NodeSelection{}
e2epod.SetAffinity(&nodeSelection, targetNode)
e2epod.SetNodeSelection(&podWithHook.Spec, nodeSelection)
testPodWithHook(podWithHook)
})
})
Expand Down

0 comments on commit e6c7837

Please sign in to comment.