From bec3dd014893d8f1fd266155d0b05861f2be24a3 Mon Sep 17 00:00:00 2001 From: Hyeongju Johannes Lee Date: Fri, 14 Jul 2023 14:19:06 +0300 Subject: [PATCH] e2e: remove duplicate code of testing with operator move duplicate code for testing plugins using operator to operator module replace the code for deploying operator webhook in operator module with the code using utils.Kubectl to make simple for undeploying Signed-off-by: Hyeongju Johannes Lee --- test/e2e/dsa/dsa.go | 24 ----------------- test/e2e/iaa/iaa.go | 24 ----------------- test/e2e/operator/operator.go | 49 ++++++++++++++++++++++++++++++++--- test/e2e/sgx/sgx.go | 30 --------------------- 4 files changed, 45 insertions(+), 82 deletions(-) diff --git a/test/e2e/dsa/dsa.go b/test/e2e/dsa/dsa.go index a61770562..a6598c1c2 100644 --- a/test/e2e/dsa/dsa.go +++ b/test/e2e/dsa/dsa.go @@ -119,28 +119,4 @@ func describe() { }) }) }) - - ginkgo.Describe("With using operator", func() { - ginkgo.It("deploys DSA plugin with operator", func(ctx context.Context) { - utils.Kubectl("", "apply", "-k", "deployments/operator/default/kustomization.yaml") - - if _, err := e2epod.WaitForPodsWithLabelRunningReady(ctx, f.ClientSet, ns, labels.Set{"control-plane": "controller-manager"}.AsSelector(), 1, timeout); err != nil { - framework.Failf("unable to wait for all pods to be running and ready: %v", err) - } - - utils.Kubectl("", "apply", "-f", "deployments/operator/samples/deviceplugin_v1_dsadeviceplugin.yaml") - - if _, err := e2epod.WaitForPodsWithLabelRunningReady(ctx, f.ClientSet, ns, labels.Set{"app": "intel-dsa-plugin"}.AsSelector(), 1, timeout); err != nil { - framework.Failf("unable to wait for all pods to be running and ready: %v", err) - } - - if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "dsa.intel.com/wq-user-dedicated", timeout); err != nil { - framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err) - } - - utils.Kubectl("", "delete", "-f", "deployments/operator/samples/deviceplugin_v1_dsadeviceplugin.yaml") - - utils.Kubectl("", "delete", "-k", "deployments/operator/default/kustomization.yaml") - }) - }) } diff --git a/test/e2e/iaa/iaa.go b/test/e2e/iaa/iaa.go index 379064dae..a52233940 100644 --- a/test/e2e/iaa/iaa.go +++ b/test/e2e/iaa/iaa.go @@ -119,28 +119,4 @@ func describe() { }) }) }) - - ginkgo.Describe("With using operator", func() { - ginkgo.It("deploys IAA plugin with operator", func(ctx context.Context) { - utils.Kubectl("", "apply", "-k", "deployments/operator/default/kustomization.yaml") - - if _, err := e2epod.WaitForPodsWithLabelRunningReady(ctx, f.ClientSet, ns, labels.Set{"control-plane": "controller-manager"}.AsSelector(), 1, timeout); err != nil { - framework.Failf("unable to wait for all pods to be running and ready: %v", err) - } - - utils.Kubectl("", "apply", "-f", "deployments/operator/samples/deviceplugin_v1_iaadeviceplugin.yaml") - - if _, err := e2epod.WaitForPodsWithLabelRunningReady(ctx, f.ClientSet, ns, labels.Set{"app": "intel-iaa-plugin"}.AsSelector(), 1, timeout); err != nil { - framework.Failf("unable to wait for all pods to be running and ready: %v", err) - } - - if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "iaa.intel.com/wq-user-dedicated", timeout); err != nil { - framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err) - } - - utils.Kubectl("", "delete", "-f", "deployments/operator/samples/deviceplugin_v1_iaadeviceplugin.yaml") - - utils.Kubectl("", "delete", "-k", "deployments/operator/default/kustomization.yaml") - }) - }) } diff --git a/test/e2e/operator/operator.go b/test/e2e/operator/operator.go index 78b14fdc0..6eb3122de 100644 --- a/test/e2e/operator/operator.go +++ b/test/e2e/operator/operator.go @@ -17,17 +17,22 @@ package inteldevicepluginsoperator import ( "context" + "time" "github.com/intel/intel-device-plugins-for-kubernetes/test/e2e/utils" "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/kubernetes/test/e2e/framework" + e2epod "k8s.io/kubernetes/test/e2e/framework/pod" admissionapi "k8s.io/pod-security-admission/api" ) const ( kustomizationYaml = "deployments/operator/default/kustomization.yaml" + ns = "inteldeviceplugins-system" + timeout = time.Second * 120 ) func init() { @@ -41,11 +46,17 @@ func describe() { var webhook v1.Pod ginkgo.BeforeEach(func(ctx context.Context) { - kustomizationPath, err := utils.LocateRepoFile(kustomizationYaml) - if err != nil { - framework.Failf("unable to locate %q: %v", kustomizationYaml, err) + ginkgo.By("deploying operator") + utils.Kubectl("", "apply", "-k", kustomizationYaml) + + if _, err := e2epod.WaitForPodsWithLabelRunningReady(ctx, f.ClientSet, ns, labels.Set{"control-plane": "controller-manager"}.AsSelector(), 1, timeout); err != nil { + framework.Failf("unable to wait for all pods to be running and ready: %v", err) } - webhook = utils.DeployWebhook(ctx, f, kustomizationPath) + }) + + ginkgo.AfterEach(func() { + ginkgo.By("undeploying operator") + utils.Kubectl("", "delete", "-k", kustomizationYaml) }) ginkgo.It("checks the operator webhook pod is safely configured", func(ctx context.Context) { @@ -54,4 +65,34 @@ func describe() { err = utils.TestWebhookServerTLS(ctx, f, "https://inteldeviceplugins-webhook-service") gomega.Expect(err).To(gomega.BeNil()) }) + + ginkgo.It("deploys IAA plugin with operator", func(ctx context.Context) { + testPluginWithOperator("iaa", []v1.ResourceName{"iaa.intel.com/wq-user-dedicated"}, f, ctx) + }) + + ginkgo.It("deploys DSA plugin with operator", func(ctx context.Context) { + testPluginWithOperator("dsa", []v1.ResourceName{"dsa.intel.com/wq-user-dedicated"}, f, ctx) + }) + + ginkgo.It("deploys SGX plugin with operator", func(ctx context.Context) { + testPluginWithOperator("sgx", []v1.ResourceName{"sgx.intel.com/epc", "sgx.intel.com/enclave", "sgx.intel.com/provision"}, f, ctx) + }) +} + +func testPluginWithOperator(deviceName string, resourceNames []v1.ResourceName, f *framework.Framework, ctx context.Context) { + dpSampleYaml := "deployments/operator/samples/deviceplugin_v1_" + deviceName + "deviceplugin.yaml" + + utils.Kubectl("", "apply", "-f", dpSampleYaml) + + if _, err := e2epod.WaitForPodsWithLabelRunningReady(ctx, f.ClientSet, ns, labels.Set{"app": "intel-" + deviceName + "-plugin"}.AsSelector(), 1, timeout); err != nil { + framework.Failf("unable to wait for all pods to be running and ready: %v", err) + } + + for _, resourceName := range resourceNames { + if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, resourceName, timeout); err != nil { + framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err) + } + } + + utils.Kubectl("", "delete", "-f", dpSampleYaml) } diff --git a/test/e2e/sgx/sgx.go b/test/e2e/sgx/sgx.go index 36a297892..eb661799b 100644 --- a/test/e2e/sgx/sgx.go +++ b/test/e2e/sgx/sgx.go @@ -118,34 +118,4 @@ func describe() { e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "delete", "-k", filepath.Dir(deploymentPluginPath)) }) - - ginkgo.It("deploys SGX plugin with operator", func(ctx context.Context) { - utils.Kubectl("", "apply", "-k", "deployments/operator/default/kustomization.yaml") - - if _, err := e2epod.WaitForPodsWithLabelRunningReady(ctx, f.ClientSet, ns, labels.Set{"control-plane": "controller-manager"}.AsSelector(), 1, timeout); err != nil { - framework.Failf("unable to wait for all pods to be running and ready: %v", err) - } - - utils.Kubectl("", "apply", "-f", "deployments/operator/samples/deviceplugin_v1_sgxdeviceplugin.yaml") - - if _, err := e2epod.WaitForPodsWithLabelRunningReady(ctx, f.ClientSet, ns, labels.Set{"app": "intel-sgx-plugin"}.AsSelector(), 1, timeout); err != nil { - framework.Failf("unable to wait for all pods to be running and ready: %v", err) - } - - 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) - } - - 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 enclave 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) - } - - utils.Kubectl("", "delete", "-f", "deployments/operator/samples/deviceplugin_v1_sgxdeviceplugin.yaml") - - utils.Kubectl("", "delete", "-k", "deployments/operator/default/kustomization.yaml") - }) }