Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: remove duplicate code of testing with operator #1472

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions test/e2e/dsa/dsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
}
24 changes: 0 additions & 24 deletions test/e2e/iaa/iaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
}
49 changes: 45 additions & 4 deletions test/e2e/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -41,11 +46,17 @@ func describe() {
var webhook v1.Pod

ginkgo.BeforeEach(func(ctx context.Context) {
hj-johannes-lee marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand All @@ -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)
mythi marked this conversation as resolved.
Show resolved Hide resolved
})

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)
}
30 changes: 0 additions & 30 deletions test/e2e/sgx/sgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}