Skip to content

Commit

Permalink
e2e: Fix DoTestCreatePeerPodContainerWithExternalIPAccess
Browse files Browse the repository at this point in the history
Ping used to check external ip access requires privileged capabilities.
Introduce a new method to create priv pod and execute the test case

Signed-off-by: Pradipta Banerjee <pradipta.banerjee@gmail.com>
  • Loading branch information
bpradipt committed Jul 15, 2024
1 parent c8df9da commit 96a6e33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/cloud-api-adaptor/test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ func WithLabel(data map[string]string) PodOption {
}
}

// Option to handle SecurityContext
func WithSecurityContext(sc *corev1.SecurityContext) PodOption {
return func(p *corev1.Pod) {
p.Spec.Containers[0].SecurityContext = sc
}
}

func NewPod(namespace string, podName string, containerName string, imageName string, options ...PodOption) *corev1.Pod {
runtimeClassName := "kata-remote"
pod := &corev1.Pod{
Expand All @@ -146,6 +153,13 @@ func NewBusyboxPod(namespace string) *corev1.Pod {
return NewBusyboxPodWithName(namespace, "busybox")
}

func NewPrivPod(namespace string, podName string) *corev1.Pod {
sc := &corev1.SecurityContext{
Privileged: func(b bool) *bool { return &b }(true),
}
return NewPod(namespace, podName, "busybox", BUSYBOX_IMAGE, WithCommand([]string{"/bin/sh", "-c", "sleep 3600"}), WithSecurityContext(sc))
}

func NewCurlPodWithName(namespace, podName string) *corev1.Pod {
return NewPod(namespace, podName, "curl", CURL_IMAGE, WithCommand([]string{"/bin/sh", "-c", "sleep 3600"}))
}
Expand Down
6 changes: 5 additions & 1 deletion src/cloud-api-adaptor/test/e2e/common_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ func DoTestCreatePodWithSecret(t *testing.T, e env.Environment, assert CloudAsse
}

func DoTestCreatePeerPodContainerWithExternalIPAccess(t *testing.T, e env.Environment, assert CloudAssert) {
pod := NewBusyboxPod(E2eNamespace)
// This test requires a container with the right capability otherwise the following error will be thrown:
// / # ping 8.8.8.8
// PING 8.8.8.8 (8.8.8.8): 56 data bytes
// ping: permission denied (are you root?)
pod := NewPrivPod(E2eNamespace, "busybox-priv")
testCommands := []TestCommand{
{
Command: []string{"ping", "-c", "1", "www.google.com"},
Expand Down

0 comments on commit 96a6e33

Please sign in to comment.