Skip to content

Commit

Permalink
test: move RuntimeClass functions from utils
Browse files Browse the repository at this point in the history
Move CreateRuntimeClass and DeleteRuntimeClass
functions from utils to vmi_configuration_test to
make utils shorter.

Signed-off-by: Ben Oukhanov <[email protected]>
  • Loading branch information
codingben committed Jun 7, 2022
1 parent 8f9c7f1 commit c0a3f43
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ go_library(
"//vendor/golang.org/x/crypto/ssh:go_default_library",
"//vendor/k8s.io/api/batch/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/node/v1beta1:go_default_library",
"//vendor/k8s.io/api/storage/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
Expand Down Expand Up @@ -248,6 +247,7 @@ go_test(
"//vendor/k8s.io/api/authorization/v1:go_default_library",
"//vendor/k8s.io/api/autoscaling/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/node/v1beta1:go_default_library",
"//vendor/k8s.io/api/policy/v1:go_default_library",
"//vendor/k8s.io/api/policy/v1beta1:go_default_library",
"//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1:go_default_library",
Expand Down
26 changes: 0 additions & 26 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import (
. "github.com/onsi/gomega"
"golang.org/x/crypto/ssh"
k8sv1 "k8s.io/api/core/v1"
nodev1 "k8s.io/api/node/v1beta1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -496,31 +495,6 @@ func CreatePVC(os, size, storageClass string, recycledPV bool) *k8sv1.Persistent
return pvc
}

func CreateRuntimeClass(name, handler string) (*nodev1.RuntimeClass, error) {
virtCli, err := kubecli.GetKubevirtClient()
if err != nil {
return nil, err
}

return virtCli.NodeV1beta1().RuntimeClasses().Create(
context.Background(),
&nodev1.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Handler: handler,
},
metav1.CreateOptions{},
)
}

func DeleteRuntimeClass(name string) error {
virtCli, err := kubecli.GetKubevirtClient()
if err != nil {
return err
}

return virtCli.NodeV1beta1().RuntimeClasses().Delete(context.Background(), name, metav1.DeleteOptions{})
}

func newPVC(os, size, storageClass string, recycledPV bool) *k8sv1.PersistentVolumeClaim {
quantity, err := resource.ParseQuantity(size)
util2.PanicOnError(err)
Expand Down
30 changes: 28 additions & 2 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/pborman/uuid"
k8sv1 "k8s.io/api/core/v1"
kubev1 "k8s.io/api/core/v1"
nodev1 "k8s.io/api/node/v1beta1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -1615,12 +1616,12 @@ var _ = Describe("[sig-compute]Configurations", func() {

BeforeEach(func() {
By("Creating a runtime class")
tests.CreateRuntimeClass(runtimeClassName, "custom-handler")
createRuntimeClass(runtimeClassName, "custom-handler")
})

AfterEach(func() {
By("Cleaning up runtime class")
err = tests.DeleteRuntimeClass(runtimeClassName)
err = deleteRuntimeClass(runtimeClassName)
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -2990,3 +2991,28 @@ var _ = Describe("[sig-compute]Configurations", func() {
})
})
})

func createRuntimeClass(name, handler string) (*nodev1.RuntimeClass, error) {
virtCli, err := kubecli.GetKubevirtClient()
if err != nil {
return nil, err
}

return virtCli.NodeV1beta1().RuntimeClasses().Create(
context.Background(),
&nodev1.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Handler: handler,
},
metav1.CreateOptions{},
)
}

func deleteRuntimeClass(name string) error {
virtCli, err := kubecli.GetKubevirtClient()
if err != nil {
return err
}

return virtCli.NodeV1beta1().RuntimeClasses().Delete(context.Background(), name, metav1.DeleteOptions{})
}

0 comments on commit c0a3f43

Please sign in to comment.