Skip to content

Commit

Permalink
Merge pull request kubevirt#8620 from iholder-redhat/functest/Serial-…
Browse files Browse the repository at this point in the history
…using-defaultRuntimeClass-configuration

[Functest] several fixes to default runtime class configuration tests
  • Loading branch information
kubevirt-bot authored Oct 26, 2022
2 parents cfdd33b + f70615d commit 140b580
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,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/node/v1: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
6 changes: 5 additions & 1 deletion tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,13 @@ func RunVMIAndExpectLaunchIgnoreWarnings(vmi *v1.VirtualMachineInstance, timeout
}

func RunVMIAndExpectScheduling(vmi *v1.VirtualMachineInstance, timeout int) *v1.VirtualMachineInstance {
wp := watcher.WarningsPolicy{FailOnWarnings: true}
return RunVMIAndExpectSchedulingWithWarningPolicy(vmi, timeout, wp)
}

func RunVMIAndExpectSchedulingWithWarningPolicy(vmi *v1.VirtualMachineInstance, timeout int, wp watcher.WarningsPolicy) *v1.VirtualMachineInstance {
obj := RunVMI(vmi, timeout)
By("Waiting until the VirtualMachineInstance will be scheduled")
wp := watcher.WarningsPolicy{FailOnWarnings: true}
return waitForVMIScheduling(obj, timeout, wp)
}

Expand Down
30 changes: 14 additions & 16 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +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"
nodev1 "k8s.io/api/node/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -1671,17 +1671,18 @@ var _ = Describe("[sig-compute]Configurations", func() {
})

Context("[Serial]using defaultRuntimeClass configuration", func() {
runtimeClassName := "custom-runtime-class"
const runtimeClassName = "fake-runtime-class"

BeforeEach(func() {
By("Creating a runtime class")
createRuntimeClass(runtimeClassName, "custom-handler")
_, err := createRuntimeClass(runtimeClassName, "fake-handler")
Expect(err).NotTo(HaveOccurred(), "cannot create runtime-class "+runtimeClassName)
})

AfterEach(func() {
By("Cleaning up runtime class")
err = deleteRuntimeClass(runtimeClassName)
Expect(err).NotTo(HaveOccurred())
err := deleteRuntimeClass(runtimeClassName)
Expect(err).NotTo(HaveOccurred(), "cannot delete runtime-class "+runtimeClassName)
})

It("should apply runtimeClassName to pod when set", func() {
Expand All @@ -1691,23 +1692,20 @@ var _ = Describe("[sig-compute]Configurations", func() {
tests.UpdateKubeVirtConfigValueAndWait(*config)

By("Creating a new VMI")
var vmi = tests.NewRandomVMI()
vmi = tests.RunVMIAndExpectScheduling(vmi, 30)
Expect(err).NotTo(HaveOccurred())
vmi := tests.NewRandomVMI()
// Runtime class related warnings are expected since we created a fake runtime class that isn't supported
wp := watcher.WarningsPolicy{FailOnWarnings: true, WarningsIgnoreList: []string{"RuntimeClass"}}
vmi = tests.RunVMIAndExpectSchedulingWithWarningPolicy(vmi, 30, wp)

By("Checking for presence of runtimeClassName")
pod := tests.GetPodByVirtualMachineInstance(vmi)
Expect(pod.Spec.RuntimeClassName).ToNot(BeNil())
Expect(*pod.Spec.RuntimeClassName).To(BeEquivalentTo(runtimeClassName))
})

It("should not apply runtimeClassName to pod when not set", func() {
By("Creating a VMI")
var vmi = tests.NewRandomVMI()
vmi, err = virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Create(vmi)
Expect(err).NotTo(HaveOccurred())

By("Waiting for successful start of VMI")
tests.WaitForSuccessfulVMIStart(vmi)
vmi := tests.RunVMIAndExpectLaunch(tests.NewRandomVMI(), 60)

By("Checking for absence of runtimeClassName")
pod := tests.GetRunningPodByVirtualMachineInstance(vmi, util.NamespaceTestDefault)
Expand Down Expand Up @@ -3095,7 +3093,7 @@ func createRuntimeClass(name, handler string) (*nodev1.RuntimeClass, error) {
return nil, err
}

return virtCli.NodeV1beta1().RuntimeClasses().Create(
return virtCli.NodeV1().RuntimeClasses().Create(
context.Background(),
&nodev1.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Expand All @@ -3111,7 +3109,7 @@ func deleteRuntimeClass(name string) error {
return err
}

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

func withNoRng() libvmi.Option {
Expand Down

0 comments on commit 140b580

Please sign in to comment.