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 <hyeongju.lee@intel.com>
This commit is contained in:
Hyeongju Johannes Lee 2023-07-14 14:19:06 +03:00
parent e57723c19c
commit bec3dd0148
4 changed files with 45 additions and 82 deletions

View File

@ -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")
})
})
}

View File

@ -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")
})
})
}

View File

@ -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)
}

View File

@ -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")
})
}