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) {
ginkgo.By("deploying SGX plugin")
deploymentWebhookPath, err := utils.LocateRepoFile(kustomizationWebhook) deploymentWebhookPath, err := utils.LocateRepoFile(kustomizationWebhook)
if err != nil { if err != nil {
framework.Failf("unable to locate %q: %v", kustomizationWebhook, err) framework.Failf("unable to locate %q: %v", kustomizationWebhook, err)
} }
_ = utils.DeployWebhook(ctx, f, deploymentWebhookPath)
deploymentPluginPath, err := utils.LocateRepoFile(kustomizationPlugin) deploymentPluginPath, err := utils.LocateRepoFile(kustomizationPlugin)
if err != nil { if err != nil {
framework.Failf("unable to locate %q: %v", kustomizationPlugin, err) framework.Failf("unable to locate %q: %v", kustomizationPlugin, err)
} }
ginkgo.BeforeEach(func(ctx context.Context) {
_ = utils.DeployWebhook(ctx, f, deploymentWebhookPath)
ginkgo.By("deploying SGX plugin")
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,7 +77,10 @@ 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.Context("When SGX resources are available", func() {
ginkgo.BeforeEach(func(ctx context.Context) {
ginkgo.By("checking if the resource is allocatable") 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/epc", 150*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 epc resource: %v", err)
@ -89,8 +91,9 @@ func describe() {
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/provision", 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 provision resource: %v", err) 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{
@ -115,7 +118,11 @@ func describe() {
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))
}) })
} }