Skip to content

Commit 81b3864

Browse files
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 <[email protected]>
1 parent 91d826f commit 81b3864

File tree

1 file changed

+49
-42
lines changed

1 file changed

+49
-42
lines changed

test/e2e/sgx/sgx.go

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,20 @@ func describe() {
4848
f := framework.NewDefaultFramework("sgxplugin")
4949
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
5050

51-
ginkgo.It("checks availability of SGX resources", func(ctx context.Context) {
52-
ginkgo.By("deploying SGX plugin")
51+
deploymentWebhookPath, err := utils.LocateRepoFile(kustomizationWebhook)
52+
if err != nil {
53+
framework.Failf("unable to locate %q: %v", kustomizationWebhook, err)
54+
}
5355

54-
deploymentWebhookPath, err := utils.LocateRepoFile(kustomizationWebhook)
55-
if err != nil {
56-
framework.Failf("unable to locate %q: %v", kustomizationWebhook, err)
57-
}
56+
deploymentPluginPath, err := utils.LocateRepoFile(kustomizationPlugin)
57+
if err != nil {
58+
framework.Failf("unable to locate %q: %v", kustomizationPlugin, err)
59+
}
5860

61+
ginkgo.BeforeEach(func(ctx context.Context) {
5962
_ = utils.DeployWebhook(ctx, f, deploymentWebhookPath)
6063

61-
deploymentPluginPath, err := utils.LocateRepoFile(kustomizationPlugin)
62-
if err != nil {
63-
framework.Failf("unable to locate %q: %v", kustomizationPlugin, err)
64-
}
65-
64+
ginkgo.By("deploying SGX plugin")
6665
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "apply", "-k", filepath.Dir(deploymentPluginPath))
6766

6867
ginkgo.By("waiting for SGX plugin's availability")
@@ -78,44 +77,52 @@ func describe() {
7877
if err = utils.TestPodsFileSystemInfo(podList.Items); err != nil {
7978
framework.Failf("container filesystem info checks failed: %v", err)
8079
}
80+
})
8181

82-
ginkgo.By("checking if the resource is allocatable")
83-
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/epc", 150*time.Second); err != nil {
84-
framework.Failf("unable to wait for nodes to have positive allocatable epc resource: %v", err)
85-
}
86-
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/enclave", 30*time.Second); err != nil {
87-
framework.Failf("unable to wait for nodes to have positive allocatable enclave resource: %v", err)
88-
}
89-
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/provision", 30*time.Second); err != nil {
90-
framework.Failf("unable to wait for nodes to have positive allocatable provision resource: %v", err)
91-
}
92-
93-
ginkgo.By("submitting a pod requesting SGX enclave resources")
94-
podSpec := &v1.Pod{
95-
ObjectMeta: metav1.ObjectMeta{Name: "sgxplugin-tester"},
96-
Spec: v1.PodSpec{
97-
Containers: []v1.Container{
98-
{
99-
Args: []string{"-c", "echo hello world"},
100-
Name: "testcontainer",
101-
Image: imageutils.GetE2EImage(imageutils.BusyBox),
102-
Command: []string{"/bin/sh"},
103-
Resources: v1.ResourceRequirements{
104-
Requests: v1.ResourceList{"sgx.intel.com/epc": resource.MustParse("42")},
105-
Limits: v1.ResourceList{"sgx.intel.com/epc": resource.MustParse("42")},
82+
ginkgo.Context("When SGX resources are available", func() {
83+
ginkgo.BeforeEach(func(ctx context.Context) {
84+
ginkgo.By("checking if the resource is allocatable")
85+
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/epc", 150*time.Second); err != nil {
86+
framework.Failf("unable to wait for nodes to have positive allocatable epc resource: %v", err)
87+
}
88+
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/enclave", 30*time.Second); err != nil {
89+
framework.Failf("unable to wait for nodes to have positive allocatable enclave resource: %v", err)
90+
}
91+
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/provision", 30*time.Second); err != nil {
92+
framework.Failf("unable to wait for nodes to have positive allocatable provision resource: %v", err)
93+
}
94+
})
95+
96+
ginkgo.It("deploys a pod requesting SGX enclave resources", func(ctx context.Context) {
97+
podSpec := &v1.Pod{
98+
ObjectMeta: metav1.ObjectMeta{Name: "sgxplugin-tester"},
99+
Spec: v1.PodSpec{
100+
Containers: []v1.Container{
101+
{
102+
Args: []string{"-c", "echo hello world"},
103+
Name: "testcontainer",
104+
Image: imageutils.GetE2EImage(imageutils.BusyBox),
105+
Command: []string{"/bin/sh"},
106+
Resources: v1.ResourceRequirements{
107+
Requests: v1.ResourceList{"sgx.intel.com/epc": resource.MustParse("42")},
108+
Limits: v1.ResourceList{"sgx.intel.com/epc": resource.MustParse("42")},
109+
},
106110
},
107111
},
112+
RestartPolicy: v1.RestartPolicyNever,
108113
},
109-
RestartPolicy: v1.RestartPolicyNever,
110-
},
111-
}
112-
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, podSpec, metav1.CreateOptions{})
113-
framework.ExpectNoError(err, "pod Create API error")
114+
}
115+
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, podSpec, metav1.CreateOptions{})
116+
framework.ExpectNoError(err, "pod Create API error")
114117

115-
ginkgo.By("waiting the pod to finish successfully")
118+
ginkgo.By("waiting the pod to finish successfully")
116119

117-
e2epod.NewPodClient(f).WaitForSuccess(ctx, pod.ObjectMeta.Name, 60*time.Second)
120+
e2epod.NewPodClient(f).WaitForSuccess(ctx, pod.ObjectMeta.Name, 60*time.Second)
121+
})
122+
})
118123

124+
ginkgo.AfterEach(func() {
125+
ginkgo.By("undeploying SGX plugin")
119126
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "delete", "-k", filepath.Dir(deploymentPluginPath))
120127
})
121128
}

0 commit comments

Comments
 (0)