Skip to content

Commit

Permalink
ibmcloud: Added test cases to check peer pod logs environment variables
Browse files Browse the repository at this point in the history
Added test cases to check peer pod logs environment variables in ibmcloud cloud-provider

Fixes: confidential-containers#1044, kata-containers/kata-containers#5730

Signed-off-by: Sudharshan Muralidharan <[email protected]>
  • Loading branch information
sudharshanibm3 authored and stevenhorsman committed Jun 23, 2023
1 parent 48742e9 commit ae85da0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
6 changes: 6 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func withCommand(command []string) podOption {
}
}

func withEnvironmentalVariables(envVar []corev1.EnvVar) podOption {
return func(p *corev1.Pod) {
p.Spec.Containers[0].Env = envVar
}
}

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})
Expand Down
32 changes: 30 additions & 2 deletions test/e2e/common_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (tc *testCase) run() {
if tc.expectedPodLogString != "" {
LogString, err := comparePodLogString(ctx, client, *tc.pod, tc.expectedPodLogString)
if err != nil {
t.Logf("Output:%s", LogString)
t.Fatal(err)
}
t.Logf("Log output of peer pod:%s", LogString)
Expand Down Expand Up @@ -291,8 +292,8 @@ func comparePodLogString(ctx context.Context, client klient.Client, customPod v1
return podLogString, err
}

if podLogString != expectedPodlogString {
return podLogString, errors.New("Error: Pod Log doesn't match with Expected String")
if !strings.Contains(podLogString, expectedPodlogString) {
return podLogString, errors.New("Error: Pod Log doesn't contain Expected String")
}

return podLogString, nil
Expand Down Expand Up @@ -493,3 +494,30 @@ func doTestCreatePeerPodAndCheckWorkDirLogs(t *testing.T, assert CloudAssert) {
expectedPodLogString := "/other"
newTestCase(t, "WorkDirPeerPod", assert, "Peer pod with work directory has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).withCustomPodState(v1.PodSucceeded).run()
}

func doTestCreatePeerPodAndCheckEnvVariableLogsWithImageOnly(t *testing.T, assert CloudAssert) {
namespace := envconf.RandomName("default", 7)
podName := "env-variable-in-image"
imageName := "quay.io/confidential-containers/test-images:testenv"
pod := newPod(namespace, podName, podName, imageName, withRestartPolicy(v1.RestartPolicyNever))
expectedPodLogString := "ISPRODUCTION=false"
newTestCase(t, "EnvVariablePeerPodWithImageOnly", assert, "Peer pod with environmental variables has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).withCustomPodState(v1.PodSucceeded).run()
}

func doTestCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly(t *testing.T, assert CloudAssert) {
namespace := envconf.RandomName("default", 7)
podName := "env-variable-in-config"
imageName := "nginx:latest"
pod := newPod(namespace, podName, podName, imageName, withRestartPolicy(v1.RestartPolicyNever), withEnvironmentalVariables([]v1.EnvVar{{Name: "ISPRODUCTION", Value: "true"}}), withCommand([]string{"/bin/sh", "-c", "env"}))
expectedPodLogString := "ISPRODUCTION=true"
newTestCase(t, "EnvVariablePeerPodWithDeploymentOnly", assert, "Peer pod with environmental variables has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).run()
}

func doTestCreatePeerPodAndCheckEnvVariableLogsWithImageAndDeployment(t *testing.T, assert CloudAssert) {
namespace := envconf.RandomName("default", 7)
podName := "env-variable-in-both"
imageName := "quay.io/confidential-containers/test-images:testenv"
pod := newPod(namespace, podName, podName, imageName, withRestartPolicy(v1.RestartPolicyNever), withEnvironmentalVariables([]v1.EnvVar{{Name: "ISPRODUCTION", Value: "true"}}))
expectedPodLogString := "ISPRODUCTION=true"
newTestCase(t, "EnvVariablePeerPodWithBoth", assert, "Peer pod with environmental variables has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).withCustomPodState(v1.PodSucceeded).run()
}
3 changes: 3 additions & 0 deletions test/e2e/fixtures/Dockerfile.testenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM --platform="${TARGETPLATFORM}" alpine:latest
ENV ISPRODUCTION=false
ENTRYPOINT [ "/bin/sh", "-c", "env" ]
21 changes: 21 additions & 0 deletions test/e2e/ibmcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ func TestCreatePeerPodAndCheckWorkDirLogs(t *testing.T) {
doTestCreatePeerPodAndCheckWorkDirLogs(t, assert)
}

func TestCreatePeerPodAndCheckEnvVariableLogsWithImageOnly(t *testing.T) {
assert := IBMCloudAssert{
vpc: pv.IBMCloudProps.VPC,
}
doTestCreatePeerPodAndCheckEnvVariableLogsWithImageOnly(t, assert)
}

func TestCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly(t *testing.T) {
assert := IBMCloudAssert{
vpc: pv.IBMCloudProps.VPC,
}
doTestCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly(t, assert)
}

func TestCreatePeerPodAndCheckEnvVariableLogsWithImageAndDeployment(t *testing.T) {
assert := IBMCloudAssert{
vpc: pv.IBMCloudProps.VPC,
}
doTestCreatePeerPodAndCheckEnvVariableLogsWithImageAndDeployment(t, assert)
}

// IBMCloudAssert implements the CloudAssert interface for ibmcloud.
type IBMCloudAssert struct {
vpc *vpcv1.VpcV1
Expand Down

0 comments on commit ae85da0

Please sign in to comment.