From 40bbbcda4ff50e4c87a00a0d092d9935d806d96b Mon Sep 17 00:00:00 2001 From: Sudharshan Muralidharan Date: Fri, 29 Sep 2023 16:58:27 +0530 Subject: [PATCH] ibmcloud: Included Init Contianers along with nginx pod Added initcontianers along with nginx pods in order to add users manually Fixes: #1450 Signed-off-by: Sudharshan Muralidharan --- test/e2e/common.go | 18 ++++++++++++++++++ test/e2e/common_suite_test.go | 6 +++--- test/e2e/ibmcloud_test.go | 8 ++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/test/e2e/common.go b/test/e2e/common.go index 23e4edc67b..d421998a12 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -18,6 +18,12 @@ func withRestartPolicy(restartPolicy corev1.RestartPolicy) podOption { } } +func withContainerPort(port int32) podOption { + return func(p *corev1.Pod) { + p.Spec.Containers[0].Ports = []corev1.ContainerPort{{ContainerPort: port}} + } +} + func withCommand(command []string) podOption { return func(p *corev1.Pod) { p.Spec.Containers[0].Command = command @@ -40,6 +46,18 @@ func withImagePullSecrets(secretName string) podOption { } } +func withInitContainers() podOption { + return func(p *corev1.Pod) { + p.Spec.InitContainers = []corev1.Container{ + { + Name: "useradd-init-container", + Image: "busybox", + Command: []string{"adduser", "-D", "nginx"}, + }, + } + } +} + func withConfigMapBinding(mountPath string, configMapName string) podOption { return func(p *corev1.Pod) { p.Spec.Containers[0].VolumeMounts = append(p.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{Name: "config-volume", MountPath: mountPath}) diff --git a/test/e2e/common_suite_test.go b/test/e2e/common_suite_test.go index e68a029cc1..77db0071e8 100644 --- a/test/e2e/common_suite_test.go +++ b/test/e2e/common_suite_test.go @@ -636,7 +636,7 @@ func doTestCreatePodWithConfigMap(t *testing.T, assert CloudAssert) { configMapPath := podKubeConfigmapDir + configMapFileName configMapContents := "Hello, world" configMapData := map[string]string{configMapFileName: configMapContents} - pod := newPod(namespace, podName, containerName, imageName, withConfigMapBinding(podKubeConfigmapDir, configMapName)) + pod := newPod(namespace, podName, containerName, imageName, withConfigMapBinding(podKubeConfigmapDir, configMapName), withContainerPort(80), withInitContainers()) configMap := newConfigMap(namespace, configMapName, configMapData) testCommands := []testCommand{ { @@ -672,7 +672,7 @@ func doTestCreatePodWithSecret(t *testing.T, assert CloudAssert) { password := "password" passwordPath := podKubeSecretsDir + passwordFileName secretData := map[string][]byte{passwordFileName: []byte(password), usernameFileName: []byte(username)} - pod := newPod(namespace, podName, containerName, imageName, withSecretBinding(podKubeSecretsDir, secretName)) + pod := newPod(namespace, podName, containerName, imageName, withSecretBinding(podKubeSecretsDir, secretName), withContainerPort(80), withInitContainers()) secret := newSecret(namespace, secretName, secretData, v1.SecretTypeOpaque) testCommands := []testCommand{ @@ -781,7 +781,7 @@ func doTestCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly(t *testing.T, namespace := envconf.RandomName("default", 7) podName := "env-variable-in-config" imageName := "nginx:latest" - pod := newPod(namespace, podName, podName, imageName, withRestartPolicy(v1.RestartPolicyOnFailure), withEnvironmentalVariables([]v1.EnvVar{{Name: "ISPRODUCTION", Value: "true"}}), withCommand([]string{"/bin/sh", "-c", "env"})) + pod := newPod(namespace, podName, podName, imageName, withRestartPolicy(v1.RestartPolicyOnFailure), withEnvironmentalVariables([]v1.EnvVar{{Name: "ISPRODUCTION", Value: "true"}}), withCommand([]string{"/bin/sh", "-c", "env"}), withContainerPort(80), withInitContainers()) expectedPodLogString := "ISPRODUCTION=true" newTestCase(t, "EnvVariablePeerPodWithDeploymentOnly", assert, "Peer pod with environmental variables has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).withCustomPodState(v1.PodSucceeded).run() } diff --git a/test/e2e/ibmcloud_test.go b/test/e2e/ibmcloud_test.go index a00c8dd8b6..23493eef88 100644 --- a/test/e2e/ibmcloud_test.go +++ b/test/e2e/ibmcloud_test.go @@ -308,6 +308,14 @@ func newPodWithPVCFromIBMVPCBlockDriver(namespace, podName, containerName, image Name: containerName, Image: imageName, ImagePullPolicy: corev1.PullAlways, + Ports: []corev1.ContainerPort{{ContainerPort: 80}}, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "useradd-init-container", + Image: "busybox", + Command: []string{"adduser", "-D", "nginx"}, }, }, ServiceAccountName: "ibm-vpc-block-node-sa",