Skip to content

Commit 527d2aa

Browse files
committed
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: kubernetes#70248
1 parent 0b4275b commit 527d2aa

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

test/e2e/common/lifecycle_hook.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package common
1818

1919
import (
20+
"fmt"
21+
"strings"
2022
"time"
2123

2224
"k8s.io/api/core/v1"
@@ -38,7 +40,7 @@ var _ = framework.KubeDescribe("Container Lifecycle Hook", func() {
3840
preStopWaitTimeout = 30 * time.Second
3941
)
4042
Context("when create a pod with lifecycle hook", func() {
41-
var targetIP string
43+
var targetIP, targetURL string
4244
podHandleHookRequest := &v1.Pod{
4345
ObjectMeta: metav1.ObjectMeta{
4446
Name: "pod-handle-http-request",
@@ -63,6 +65,10 @@ var _ = framework.KubeDescribe("Container Lifecycle Hook", func() {
6365
By("create the container to handle the HTTPGet hook request.")
6466
newPod := podClient.CreateSync(podHandleHookRequest)
6567
targetIP = newPod.Status.PodIP
68+
targetURL = targetIP
69+
if strings.Contains(targetIP, ":") {
70+
targetURL = fmt.Sprintf("[%s]", targetIP)
71+
}
6672
})
6773
testPodWithHook := func(podWithHook *v1.Pod) {
6874
By("create the pod with lifecycle hook")
@@ -93,7 +99,7 @@ var _ = framework.KubeDescribe("Container Lifecycle Hook", func() {
9399
lifecycle := &v1.Lifecycle{
94100
PostStart: &v1.Handler{
95101
Exec: &v1.ExecAction{
96-
Command: []string{"sh", "-c", "curl http://" + targetIP + ":8080/echo?msg=poststart"},
102+
Command: []string{"sh", "-c", "curl http://" + targetURL + ":8080/echo?msg=poststart"},
97103
},
98104
},
99105
}
@@ -109,7 +115,7 @@ var _ = framework.KubeDescribe("Container Lifecycle Hook", func() {
109115
lifecycle := &v1.Lifecycle{
110116
PreStop: &v1.Handler{
111117
Exec: &v1.ExecAction{
112-
Command: []string{"sh", "-c", "curl http://" + targetIP + ":8080/echo?msg=prestop"},
118+
Command: []string{"sh", "-c", "curl http://" + targetURL + ":8080/echo?msg=prestop"},
113119
},
114120
},
115121
}

0 commit comments

Comments
 (0)