e2e,sgx: divide single It() to have multiple layers

Structure is as follows:
Describe("SGX plugin")
  BeforeEach("deploys plugin")
  Context("When device resources are available")
    BeforeEach("checks if resources are available")
    It("runs a pod requesting resources")
  AfterEach("undeploys plugin")

Signed-off-by: Hyeongju Johannes Lee <hyeongju.lee@intel.com>
This commit is contained in:
Hyeongju Johannes Lee 2023-07-07 15:51:03 +03:00
parent 91d826fb63
commit 81b386400f

View File

@ -48,21 +48,20 @@ func describe() {
f := framework.NewDefaultFramework("sgxplugin") f := framework.NewDefaultFramework("sgxplugin")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
ginkgo.It("checks availability of SGX resources", func(ctx context.Context) { deploymentWebhookPath, err := utils.LocateRepoFile(kustomizationWebhook)
ginkgo.By("deploying SGX plugin") if err != nil {
framework.Failf("unable to locate %q: %v", kustomizationWebhook, err)
}
deploymentWebhookPath, err := utils.LocateRepoFile(kustomizationWebhook) deploymentPluginPath, err := utils.LocateRepoFile(kustomizationPlugin)
if err != nil { if err != nil {
framework.Failf("unable to locate %q: %v", kustomizationWebhook, err) framework.Failf("unable to locate %q: %v", kustomizationPlugin, err)
} }
ginkgo.BeforeEach(func(ctx context.Context) {
_ = utils.DeployWebhook(ctx, f, deploymentWebhookPath) _ = utils.DeployWebhook(ctx, f, deploymentWebhookPath)
deploymentPluginPath, err := utils.LocateRepoFile(kustomizationPlugin) ginkgo.By("deploying SGX plugin")
if err != nil {
framework.Failf("unable to locate %q: %v", kustomizationPlugin, err)
}
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "apply", "-k", filepath.Dir(deploymentPluginPath)) e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "apply", "-k", filepath.Dir(deploymentPluginPath))
ginkgo.By("waiting for SGX plugin's availability") ginkgo.By("waiting for SGX plugin's availability")
@ -78,44 +77,52 @@ func describe() {
if err = utils.TestPodsFileSystemInfo(podList.Items); err != nil { if err = utils.TestPodsFileSystemInfo(podList.Items); err != nil {
framework.Failf("container filesystem info checks failed: %v", err) framework.Failf("container filesystem info checks failed: %v", err)
} }
})
ginkgo.By("checking if the resource is allocatable") ginkgo.Context("When SGX resources are available", func() {
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/epc", 150*time.Second); err != nil { ginkgo.BeforeEach(func(ctx context.Context) {
framework.Failf("unable to wait for nodes to have positive allocatable epc resource: %v", err) ginkgo.By("checking if the resource is allocatable")
} if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/epc", 150*time.Second); err != nil {
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/enclave", 30*time.Second); err != nil { framework.Failf("unable to wait for nodes to have positive allocatable epc resource: %v", err)
framework.Failf("unable to wait for nodes to have positive allocatable enclave resource: %v", err) }
} if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/enclave", 30*time.Second); err != nil {
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/provision", 30*time.Second); err != nil { framework.Failf("unable to wait for nodes to have positive allocatable enclave resource: %v", err)
framework.Failf("unable to wait for nodes to have positive allocatable provision resource: %v", err) }
} if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/provision", 30*time.Second); err != nil {
framework.Failf("unable to wait for nodes to have positive allocatable provision resource: %v", err)
}
})
ginkgo.By("submitting a pod requesting SGX enclave resources") ginkgo.It("deploys a pod requesting SGX enclave resources", func(ctx context.Context) {
podSpec := &v1.Pod{ podSpec := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "sgxplugin-tester"}, ObjectMeta: metav1.ObjectMeta{Name: "sgxplugin-tester"},
Spec: v1.PodSpec{ Spec: v1.PodSpec{
Containers: []v1.Container{ Containers: []v1.Container{
{ {
Args: []string{"-c", "echo hello world"}, Args: []string{"-c", "echo hello world"},
Name: "testcontainer", Name: "testcontainer",
Image: imageutils.GetE2EImage(imageutils.BusyBox), Image: imageutils.GetE2EImage(imageutils.BusyBox),
Command: []string{"/bin/sh"}, Command: []string{"/bin/sh"},
Resources: v1.ResourceRequirements{ Resources: v1.ResourceRequirements{
Requests: v1.ResourceList{"sgx.intel.com/epc": resource.MustParse("42")}, Requests: v1.ResourceList{"sgx.intel.com/epc": resource.MustParse("42")},
Limits: v1.ResourceList{"sgx.intel.com/epc": resource.MustParse("42")}, Limits: v1.ResourceList{"sgx.intel.com/epc": resource.MustParse("42")},
},
}, },
}, },
RestartPolicy: v1.RestartPolicyNever,
}, },
RestartPolicy: v1.RestartPolicyNever, }
}, pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, podSpec, metav1.CreateOptions{})
} framework.ExpectNoError(err, "pod Create API error")
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, podSpec, metav1.CreateOptions{})
framework.ExpectNoError(err, "pod Create API error")
ginkgo.By("waiting the pod to finish successfully") ginkgo.By("waiting the pod to finish successfully")
e2epod.NewPodClient(f).WaitForSuccess(ctx, pod.ObjectMeta.Name, 60*time.Second) e2epod.NewPodClient(f).WaitForSuccess(ctx, pod.ObjectMeta.Name, 60*time.Second)
})
})
ginkgo.AfterEach(func() {
ginkgo.By("undeploying SGX plugin")
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "delete", "-k", filepath.Dir(deploymentPluginPath)) e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "delete", "-k", filepath.Dir(deploymentPluginPath))
}) })
} }