Align lifecycle handlers and probes
Align the behavior of HTTP-based lifecycle handlers and HTTP-based probers, converging on the probers implementation. This fixes multiple deficiencies in the current implementation of lifecycle handlers surrounding what functionality is available. The functionality is gated by the features.ConsistentHTTPGetHandlers feature gate.
This commit is contained in:

committed by
Billie Cleek

parent
429f71d958
commit
5a6acf85fa
@@ -44,14 +44,36 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
|
||||
preStopWaitTimeout = 30 * time.Second
|
||||
)
|
||||
ginkgo.Context("when create a pod with lifecycle hook", func() {
|
||||
var targetIP, targetURL, targetNode string
|
||||
ports := []v1.ContainerPort{
|
||||
{
|
||||
ContainerPort: 8080,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
}
|
||||
podHandleHookRequest := e2epod.NewAgnhostPod("", "pod-handle-http-request", nil, nil, ports, "netexec")
|
||||
var (
|
||||
targetIP, targetURL, targetNode string
|
||||
|
||||
httpPorts = []v1.ContainerPort{
|
||||
{
|
||||
ContainerPort: 8080,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
}
|
||||
httpsPorts = []v1.ContainerPort{
|
||||
{
|
||||
ContainerPort: 9090,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
}
|
||||
httpsArgs = []string{
|
||||
"netexec",
|
||||
"--http-port", "9090",
|
||||
"--udp-port", "9091",
|
||||
"--tls-cert-file", "/localhost.crt",
|
||||
"--tls-private-key-file", "/localhost.key",
|
||||
}
|
||||
)
|
||||
|
||||
podHandleHookRequest := e2epod.NewAgnhostPodFromContainers(
|
||||
"", "pod-handle-http-request", nil,
|
||||
e2epod.NewAgnhostContainer("container-handle-http-request", nil, httpPorts, "netexec"),
|
||||
e2epod.NewAgnhostContainer("container-handle-https-request", nil, httpsPorts, httpsArgs...),
|
||||
)
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
node, err := e2enode.GetRandomReadySchedulableNode(f.ClientSet)
|
||||
framework.ExpectNoError(err)
|
||||
@@ -72,10 +94,20 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
|
||||
testPodWithHook := func(podWithHook *v1.Pod) {
|
||||
ginkgo.By("create the pod with lifecycle hook")
|
||||
podClient.CreateSync(podWithHook)
|
||||
const (
|
||||
defaultHandler = iota
|
||||
httpsHandler
|
||||
)
|
||||
handlerContainer := defaultHandler
|
||||
if podWithHook.Spec.Containers[0].Lifecycle.PostStart != nil {
|
||||
ginkgo.By("check poststart hook")
|
||||
if podWithHook.Spec.Containers[0].Lifecycle.PostStart.HTTPGet != nil {
|
||||
if v1.URISchemeHTTPS == podWithHook.Spec.Containers[0].Lifecycle.PostStart.HTTPGet.Scheme {
|
||||
handlerContainer = httpsHandler
|
||||
}
|
||||
}
|
||||
gomega.Eventually(func() error {
|
||||
return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[0].Name,
|
||||
return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[handlerContainer].Name,
|
||||
`GET /echo\?msg=poststart`)
|
||||
}, postStartWaitTimeout, podCheckInterval).Should(gomega.BeNil())
|
||||
}
|
||||
@@ -83,8 +115,13 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
|
||||
podClient.DeleteSync(podWithHook.Name, *metav1.NewDeleteOptions(15), e2epod.DefaultPodDeletionTimeout)
|
||||
if podWithHook.Spec.Containers[0].Lifecycle.PreStop != nil {
|
||||
ginkgo.By("check prestop hook")
|
||||
if podWithHook.Spec.Containers[0].Lifecycle.PreStop.HTTPGet != nil {
|
||||
if v1.URISchemeHTTPS == podWithHook.Spec.Containers[0].Lifecycle.PreStop.HTTPGet.Scheme {
|
||||
handlerContainer = httpsHandler
|
||||
}
|
||||
}
|
||||
gomega.Eventually(func() error {
|
||||
return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[0].Name,
|
||||
return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[handlerContainer].Name,
|
||||
`GET /echo\?msg=prestop`)
|
||||
}, preStopWaitTimeout, podCheckInterval).Should(gomega.BeNil())
|
||||
}
|
||||
@@ -145,7 +182,26 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
|
||||
testPodWithHook(podWithHook)
|
||||
})
|
||||
/*
|
||||
Release: v1.9
|
||||
Release : v1.23
|
||||
Testname: Pod Lifecycle, poststart https hook
|
||||
Description: When a post-start 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 https 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.
|
||||
*/
|
||||
ginkgo.It("should execute poststart https hook properly [MinimumKubeletVersion:1.23] [NodeConformance]", func() {
|
||||
lifecycle := &v1.Lifecycle{
|
||||
PostStart: &v1.LifecycleHandler{
|
||||
HTTPGet: &v1.HTTPGetAction{
|
||||
Scheme: v1.URISchemeHTTPS,
|
||||
Path: "/echo?msg=poststart",
|
||||
Host: targetIP,
|
||||
Port: intstr.FromInt(9090),
|
||||
},
|
||||
},
|
||||
}
|
||||
podWithHook := getPodWithHook("pod-with-poststart-https-hook", imageutils.GetPauseImageName(), lifecycle)
|
||||
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 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.
|
||||
*/
|
||||
@@ -166,6 +222,25 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
|
||||
e2epod.SetNodeSelection(&podWithHook.Spec, nodeSelection)
|
||||
testPodWithHook(podWithHook)
|
||||
})
|
||||
/*
|
||||
Release : v1.23
|
||||
Testname: Pod Lifecycle, prestop https 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 https 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.
|
||||
*/
|
||||
ginkgo.It("should execute prestop https hook properly [MinimumKubeletVersion:1.23] [NodeConformance]", func() {
|
||||
lifecycle := &v1.Lifecycle{
|
||||
PreStop: &v1.LifecycleHandler{
|
||||
HTTPGet: &v1.HTTPGetAction{
|
||||
Scheme: v1.URISchemeHTTPS,
|
||||
Path: "/echo?msg=prestop",
|
||||
Host: targetIP,
|
||||
Port: intstr.FromInt(9090),
|
||||
},
|
||||
},
|
||||
}
|
||||
podWithHook := getPodWithHook("pod-with-prestop-https-hook", imageutils.GetPauseImageName(), lifecycle)
|
||||
testPodWithHook(podWithHook)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user