Skip to content

Commit

Permalink
ibmcloud: Included Contianer Ports along with nginx pod
Browse files Browse the repository at this point in the history
Added Containerport along with statements for debugging readiness probe

Fixes:  confidential-containers#1450

Signed-off-by: Sudharshan Muralidharan <sudharshan.muralidharan@ibm.com>
  • Loading branch information
sudharshanibm3 authored and lysliu committed Nov 9, 2023
1 parent 3bf4568 commit a4f43e9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
18 changes: 18 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

type podOption func(*corev1.Pod)
Expand All @@ -18,6 +19,23 @@ func withRestartPolicy(restartPolicy corev1.RestartPolicy) podOption {
}
}

// Optional method to add ContainerPort and ReadinessProbe to listen Port 80
func withContainerPort(port int32) podOption {
return func(p *corev1.Pod) {
p.Spec.Containers[0].Ports = []corev1.ContainerPort{{ContainerPort: port}}
p.Spec.Containers[0].ReadinessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(int(port)),
},
},
InitialDelaySeconds: 10,
PeriodSeconds: 5,
}
}
}

func withCommand(command []string) podOption {
return func(p *corev1.Pod) {
p.Spec.Containers[0].Command = command
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/common_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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))
configMap := newConfigMap(namespace, configMapName, configMapData)
testCommands := []testCommand{
{
Expand Down Expand Up @@ -79,7 +79,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))
secret := newSecret(namespace, secretName, secretData, v1.SecretTypeOpaque)

testCommands := []testCommand{
Expand Down Expand Up @@ -188,7 +188,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))
expectedPodLogString := "ISPRODUCTION=true"
newTestCase(t, "EnvVariablePeerPodWithDeploymentOnly", assert, "Peer pod with environmental variables has been created").withPod(pod).withExpectedPodLogString(expectedPodLogString).withCustomPodState(v1.PodSucceeded).run()
}
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/ibmcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
pv "github.com/confidential-containers/cloud-api-adaptor/test/provisioner"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
)

Expand Down Expand Up @@ -313,6 +314,17 @@ func newPodWithPVCFromIBMVPCBlockDriver(namespace, podName, containerName, image
Name: containerName,
Image: imageName,
ImagePullPolicy: corev1.PullAlways,
Ports: []corev1.ContainerPort{{ContainerPort: 80}},
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(80),
},
},
InitialDelaySeconds: 10,
PeriodSeconds: 5,
},
},
},
ServiceAccountName: "ibm-vpc-block-node-sa",
Expand Down

0 comments on commit a4f43e9

Please sign in to comment.