Skip to content

Commit

Permalink
Merge pull request #516 from codingben/CNV-45450
Browse files Browse the repository at this point in the history
refactor: use spec.runStrategy instead of spec.running
  • Loading branch information
kubevirt-bot authored Sep 9, 2024
2 parents 7c1566f + 2e332f6 commit af757d5
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ spec:
labels:
app: flasker-vm
spec:
running: true
runStrategy: Always
template:
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion examples/pipelines/unit-tester/unit-tester-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
metadata:
name: $(params.vmName)
spec:
running: false
runStrategy: Halted
template:
metadata:
labels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
labels:
app: virt-sysprep-updated-vm
spec:
running: false
runStrategy: Halted
template:
metadata:
labels:
Expand Down
6 changes: 4 additions & 2 deletions modules/sharedtest/testobjects/alpine-vm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package testobjects

import v1 "kubevirt.io/api/core/v1"
import (
v1 "kubevirt.io/api/core/v1"
)

func NewTestAlpineVM(name string) *TestVM {
containerDiskName := "containerdisk"
Expand Down Expand Up @@ -30,6 +32,6 @@ func NewTestAlpineVM(name string) *TestVM {
},
}
return (&TestVM{
Data: newRandomVirtualMachine(vmi, false),
Data: newRandomVirtualMachine(vmi, v1.RunStrategyHalted),
}).WithMemory("128Mi")
}
6 changes: 4 additions & 2 deletions modules/sharedtest/testobjects/fedora-cloud-vm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package testobjects

import v1 "kubevirt.io/api/core/v1"
import (
v1 "kubevirt.io/api/core/v1"
)

func NewTestFedoraCloudVM(name string) *TestVM {
cloudConfig := &CloudConfig{
Expand Down Expand Up @@ -49,6 +51,6 @@ func NewTestFedoraCloudVM(name string) *TestVM {
},
}
return (&TestVM{
Data: newRandomVirtualMachine(vmi, false),
Data: newRandomVirtualMachine(vmi, v1.RunStrategyHalted),
}).WithMemory("1Gi")
}
2 changes: 1 addition & 1 deletion modules/sharedtest/testobjects/template/cirros-tiny.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ objects:
vm.kubevirt.io/template.version: 0.3.2
name: '${NAME}'
spec:
running: false
runStrategy: Halted
template:
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion modules/sharedtest/testobjects/template/fedora-tiny.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ objects:
vm.kubevirt.io/template.version: 0.3.2
name: ${NAME}
spec:
running: false
runStrategy: Halted
template:
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion modules/sharedtest/testobjects/template/rhel-tiny.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ objects:
kind: DataSource
name: ${DATA_SOURCE_NAME}
namespace: ${DATA_SOURCE_NAMESPACE}
running: false
runStrategy: Halted
template:
metadata:
annotations:
Expand Down
6 changes: 3 additions & 3 deletions modules/sharedtest/testobjects/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func newRandomVMIWithNS(namespace string) *v1.VirtualMachineInstance {
return vmi
}

func newRandomVirtualMachine(vmi *v1.VirtualMachineInstance, running bool) *v1.VirtualMachine {
func newRandomVirtualMachine(vmi *v1.VirtualMachineInstance, runStrategy v1.VirtualMachineRunStrategy) *v1.VirtualMachine {
name := vmi.Name
namespace := vmi.Namespace
labels := map[string]string{"name": name}
Expand All @@ -52,7 +52,7 @@ func newRandomVirtualMachine(vmi *v1.VirtualMachineInstance, running bool) *v1.V
Namespace: namespace,
},
Spec: v1.VirtualMachineSpec{
Running: &running,
RunStrategy: &runStrategy,
Template: &v1.VirtualMachineInstanceTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Expand All @@ -69,7 +69,7 @@ func newRandomVirtualMachine(vmi *v1.VirtualMachineInstance, running bool) *v1.V

func NewTestVM() *TestVM {
return &TestVM{
Data: newRandomVirtualMachine(newRandomVMI(), false),
Data: newRandomVirtualMachine(newRandomVMI(), v1.RunStrategyHalted),
}
}

Expand Down
2 changes: 1 addition & 1 deletion release/tasks/create-vm-from-manifest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ metadata:
labels:
kubevirt.io/vm: vm-fedora
spec:
running: false
runStrategy: Halted
template:
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion templates/create-vm-from-manifest/examples/vm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
kubevirt.io/vm: vm-fedora
generateName: vm-fedora-
spec:
running: false
runStrategy: Halted
template:
metadata:
labels:
Expand Down
10 changes: 5 additions & 5 deletions test/create_vm_from_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ var _ = Describe("Create VM from manifest", func() {
})

Context("with StartVM", func() {
DescribeTable("VM is created successfully", func(config *testconfigs.CreateVMTestConfig, phase kubevirtv1.VirtualMachineInstancePhase, running bool) {
DescribeTable("VM is created successfully", func(config *testconfigs.CreateVMTestConfig, phase kubevirtv1.VirtualMachineInstancePhase, runStrategy kubevirtv1.VirtualMachineRunStrategy) {
f.TestSetup(config)

expectedVMStub := config.TaskData.GetExpectedVMStubMeta()
Expand All @@ -366,7 +366,7 @@ var _ = Describe("Create VM from manifest", func() {
phase, config.GetTaskRunTimeout(), false)
Expect(err).ShouldNot(HaveOccurred())

Expect(*vm.Spec.Running).To(Equal(running), "vm should be in correct running phase")
Expect(*vm.Spec.RunStrategy).To(Equal(runStrategy), "vm should be in correct running phase")
},
Entry("with false StartVM value", &testconfigs.CreateVMTestConfig{
TaskRunTestConfig: testconfigs.TaskRunTestConfig{
Expand All @@ -380,7 +380,7 @@ var _ = Describe("Create VM from manifest", func() {
Build(),
StartVM: "false",
},
}, kubevirtv1.VirtualMachineInstancePhase(""), false),
}, kubevirtv1.VirtualMachineInstancePhase(""), kubevirtv1.RunStrategyHalted),
Entry("with invalid StartVM value", &testconfigs.CreateVMTestConfig{
TaskRunTestConfig: testconfigs.TaskRunTestConfig{
ExpectedLogs: ExpectedSuccessfulVMCreation,
Expand All @@ -393,7 +393,7 @@ var _ = Describe("Create VM from manifest", func() {
Build(),
StartVM: "invalid_value",
},
}, kubevirtv1.VirtualMachineInstancePhase(""), false),
}, kubevirtv1.VirtualMachineInstancePhase(""), kubevirtv1.RunStrategyHalted),
Entry("with true StartVM value", &testconfigs.CreateVMTestConfig{
TaskRunTestConfig: testconfigs.TaskRunTestConfig{
ExpectedLogs: ExpectedSuccessfulVMCreation,
Expand All @@ -406,7 +406,7 @@ var _ = Describe("Create VM from manifest", func() {
Build(),
StartVM: "true",
},
}, kubevirtv1.Running, true),
}, kubevirtv1.Running, kubevirtv1.RunStrategyAlways),
)
})

Expand Down
10 changes: 5 additions & 5 deletions test/create_vm_from_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ var _ = Describe("Create VM from template", func() {
})

Context("with StartVM", func() {
DescribeTable("VM is created from template with StartVM attribute", func(config *testconfigs.CreateVMTestConfig, phase kubevirtv1.VirtualMachineInstancePhase, running bool) {
DescribeTable("VM is created from template with StartVM attribute", func(config *testconfigs.CreateVMTestConfig, phase kubevirtv1.VirtualMachineInstancePhase, runStrategy kubevirtv1.VirtualMachineRunStrategy) {
f.TestSetup(config)
template, err := f.TemplateClient.Templates(config.TaskData.Template.Namespace).Create(context.Background(), config.TaskData.Template, v1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
Expand All @@ -331,7 +331,7 @@ var _ = Describe("Create VM from template", func() {
vm, err := vm.WaitForVM(f.KubevirtClient, expectedVMStub.Namespace, expectedVMStub.Name,
phase, config.GetTaskRunTimeout(), false)
Expect(err).ShouldNot(HaveOccurred())
Expect(*vm.Spec.Running).To(Equal(running), "vm should be in correct running phase")
Expect(*vm.Spec.RunStrategy).To(Equal(runStrategy), "vm should be in correct running phase")
},
Entry("with invalid StartVM value", &testconfigs.CreateVMTestConfig{
TaskRunTestConfig: testconfigs.TaskRunTestConfig{
Expand All @@ -344,7 +344,7 @@ var _ = Describe("Create VM from template", func() {
},
StartVM: "invalid_value",
},
}, kubevirtv1.VirtualMachineInstancePhase(""), false),
}, kubevirtv1.VirtualMachineInstancePhase(""), kubevirtv1.RunStrategyHalted),
Entry("with false StartVM value", &testconfigs.CreateVMTestConfig{
TaskRunTestConfig: testconfigs.TaskRunTestConfig{
ExpectedLogs: ExpectedSuccessfulVMCreation,
Expand All @@ -356,7 +356,7 @@ var _ = Describe("Create VM from template", func() {
},
StartVM: "false",
},
}, kubevirtv1.VirtualMachineInstancePhase(""), false),
}, kubevirtv1.VirtualMachineInstancePhase(""), kubevirtv1.RunStrategyHalted),
Entry("with true StartVM value", &testconfigs.CreateVMTestConfig{
TaskRunTestConfig: testconfigs.TaskRunTestConfig{
ExpectedLogs: ExpectedSuccessfulVMCreation,
Expand All @@ -368,7 +368,7 @@ var _ = Describe("Create VM from template", func() {
},
StartVM: "true",
},
}, kubevirtv1.Running, true),
}, kubevirtv1.Running, kubevirtv1.RunStrategyAlways),
)
})

Expand Down
2 changes: 1 addition & 1 deletion test/execute_and_cleanup_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ var _ = Describe("Execute in VM / Cleanup VM", func() {
Expect(err).Should(HaveOccurred())
} else if config.TaskData.Stop {
Expect(err).ShouldNot(HaveOccurred())
Expect(*vm.Spec.Running).To(BeFalse())
Expect(*vm.Spec.RunStrategy).To(Equal(kubevirtv1.RunStrategyHalted))
}
},
// negative cases
Expand Down

0 comments on commit af757d5

Please sign in to comment.