From 527d2aa2bd75fc4b7add814d124de03df7cb0eef Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Sun, 10 Mar 2019 17:24:09 +0100 Subject: [PATCH] Add IPv6 support to the Container Lifecycle tests Current e2e tests for the Container Lifecycle Hooks weren't using brackets for the IPv6 URL addresses per RFC2732, thus those tests were failing. This patches add brackets to the target URL if it's an IPv6 address. Reference: https://github.com/kubernetes/kubernetes/issues/70248 --- test/e2e/common/lifecycle_hook.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/e2e/common/lifecycle_hook.go b/test/e2e/common/lifecycle_hook.go index 1790b236b37..fbd89e0d7d0 100644 --- a/test/e2e/common/lifecycle_hook.go +++ b/test/e2e/common/lifecycle_hook.go @@ -17,6 +17,8 @@ limitations under the License. package common import ( + "fmt" + "strings" "time" "k8s.io/api/core/v1" @@ -38,7 +40,7 @@ var _ = framework.KubeDescribe("Container Lifecycle Hook", func() { preStopWaitTimeout = 30 * time.Second ) Context("when create a pod with lifecycle hook", func() { - var targetIP string + var targetIP, targetURL string podHandleHookRequest := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "pod-handle-http-request", @@ -63,6 +65,10 @@ var _ = framework.KubeDescribe("Container Lifecycle Hook", func() { By("create the container to handle the HTTPGet hook request.") newPod := podClient.CreateSync(podHandleHookRequest) targetIP = newPod.Status.PodIP + targetURL = targetIP + if strings.Contains(targetIP, ":") { + targetURL = fmt.Sprintf("[%s]", targetIP) + } }) testPodWithHook := func(podWithHook *v1.Pod) { By("create the pod with lifecycle hook") @@ -93,7 +99,7 @@ var _ = framework.KubeDescribe("Container Lifecycle Hook", func() { lifecycle := &v1.Lifecycle{ PostStart: &v1.Handler{ Exec: &v1.ExecAction{ - Command: []string{"sh", "-c", "curl http://" + targetIP + ":8080/echo?msg=poststart"}, + Command: []string{"sh", "-c", "curl http://" + targetURL + ":8080/echo?msg=poststart"}, }, }, } @@ -109,7 +115,7 @@ var _ = framework.KubeDescribe("Container Lifecycle Hook", func() { lifecycle := &v1.Lifecycle{ PreStop: &v1.Handler{ Exec: &v1.ExecAction{ - Command: []string{"sh", "-c", "curl http://" + targetIP + ":8080/echo?msg=prestop"}, + Command: []string{"sh", "-c", "curl http://" + targetURL + ":8080/echo?msg=prestop"}, }, }, }