diff --git a/pkg/virt-controller/watch/pool.go b/pkg/virt-controller/watch/pool.go index b089d8c5dbc5..f7f2d2c4d8b7 100644 --- a/pkg/virt-controller/watch/pool.go +++ b/pkg/virt-controller/watch/pool.go @@ -532,7 +532,7 @@ func (c *PoolController) scaleIn(pool *poolv1.VirtualMachinePool, vms []*virtv1. vm := deleteList[idx] foreGround := metav1.DeletePropagationForeground - err := c.clientset.VirtualMachine(vm.Namespace).Delete(vm.Name, &metav1.DeleteOptions{PropagationPolicy: &foreGround}) + err := c.clientset.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{PropagationPolicy: &foreGround}) if err != nil { c.expectations.DeletionObserved(poolKey, controller.VirtualMachineKey(vm)) c.recorder.Eventf(pool, k8score.EventTypeWarning, FailedDeleteVirtualMachineReason, "Error deleting virtual machine %s: %v", vm.ObjectMeta.Name, err) diff --git a/pkg/virt-controller/watch/pool_test.go b/pkg/virt-controller/watch/pool_test.go index 4b914fb33378..0d0b8f3757ee 100644 --- a/pkg/virt-controller/watch/pool_test.go +++ b/pkg/virt-controller/watch/pool_test.go @@ -581,7 +581,7 @@ var _ = Describe("Pool", func() { }) // Check if only 10 are deleted - vmInterface.EXPECT().Delete(gomock.Any(), gomock.Any()).Times(10).Return(nil) + vmInterface.EXPECT().Delete(context.Background(), gomock.Any(), gomock.Any()).Times(10).Return(nil) controller.Execute() @@ -618,7 +618,7 @@ var _ = Describe("Pool", func() { }) // Check if only 5 are deleted - vmInterface.EXPECT().Delete(gomock.Any(), gomock.Any()).Times(5).Return(nil) + vmInterface.EXPECT().Delete(context.Background(), gomock.Any(), gomock.Any()).Times(5).Return(nil) controller.Execute() diff --git a/staging/src/kubevirt.io/client-go/kubecli/generated_mock_kubevirt.go b/staging/src/kubevirt.io/client-go/kubecli/generated_mock_kubevirt.go index ede445775223..740695100e34 100644 --- a/staging/src/kubevirt.io/client-go/kubecli/generated_mock_kubevirt.go +++ b/staging/src/kubevirt.io/client-go/kubecli/generated_mock_kubevirt.go @@ -1514,14 +1514,14 @@ func (_mr *_MockVirtualMachineInterfaceRecorder) Update(arg0, arg1 interface{}) return _mr.mock.ctrl.RecordCall(_mr.mock, "Update", arg0, arg1) } -func (_m *MockVirtualMachineInterface) Delete(name string, options *v12.DeleteOptions) error { - ret := _m.ctrl.Call(_m, "Delete", name, options) +func (_m *MockVirtualMachineInterface) Delete(ctx context.Context, name string, options *v12.DeleteOptions) error { + ret := _m.ctrl.Call(_m, "Delete", ctx, name, options) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockVirtualMachineInterfaceRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Delete", arg0, arg1) +func (_mr *_MockVirtualMachineInterfaceRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "Delete", arg0, arg1, arg2) } func (_m *MockVirtualMachineInterface) Patch(name string, pt types.PatchType, data []byte, patchOptions *v12.PatchOptions, subresources ...string) (*v120.VirtualMachine, error) { diff --git a/staging/src/kubevirt.io/client-go/kubecli/kubevirt.go b/staging/src/kubevirt.io/client-go/kubecli/kubevirt.go index de6c0a6b0167..e336025e79cc 100644 --- a/staging/src/kubevirt.io/client-go/kubecli/kubevirt.go +++ b/staging/src/kubevirt.io/client-go/kubecli/kubevirt.go @@ -284,7 +284,7 @@ type VirtualMachineInterface interface { List(ctx context.Context, opts *metav1.ListOptions) (*v1.VirtualMachineList, error) Create(ctx context.Context, vm *v1.VirtualMachine) (*v1.VirtualMachine, error) Update(ctx context.Context, vm *v1.VirtualMachine) (*v1.VirtualMachine, error) - Delete(name string, options *metav1.DeleteOptions) error + Delete(ctx context.Context, name string, options *metav1.DeleteOptions) error Patch(name string, pt types.PatchType, data []byte, patchOptions *metav1.PatchOptions, subresources ...string) (result *v1.VirtualMachine, err error) UpdateStatus(*v1.VirtualMachine) (*v1.VirtualMachine, error) PatchStatus(name string, pt types.PatchType, data []byte, patchOptions *metav1.PatchOptions) (result *v1.VirtualMachine, err error) diff --git a/staging/src/kubevirt.io/client-go/kubecli/vm.go b/staging/src/kubevirt.io/client-go/kubecli/vm.go index 6af6db3b1290..07e828c050ca 100644 --- a/staging/src/kubevirt.io/client-go/kubecli/vm.go +++ b/staging/src/kubevirt.io/client-go/kubecli/vm.go @@ -115,13 +115,13 @@ func (v *vm) Update(ctx context.Context, vm *v1.VirtualMachine) (*v1.VirtualMach } // Delete the defined VirtualMachine in the cluster in defined namespace -func (v *vm) Delete(name string, options *k8smetav1.DeleteOptions) error { +func (v *vm) Delete(ctx context.Context, name string, options *k8smetav1.DeleteOptions) error { err := v.restClient.Delete(). Resource(v.resource). Namespace(v.namespace). Name(name). Body(options). - Do(context.Background()). + Do(ctx). Error() return err diff --git a/staging/src/kubevirt.io/client-go/kubecli/vm_test.go b/staging/src/kubevirt.io/client-go/kubecli/vm_test.go index a6aaec321a5a..23e0844a27bf 100644 --- a/staging/src/kubevirt.io/client-go/kubecli/vm_test.go +++ b/staging/src/kubevirt.io/client-go/kubecli/vm_test.go @@ -202,7 +202,7 @@ var _ = Describe("Kubevirt VirtualMachine Client", func() { ghttp.VerifyRequest("DELETE", path.Join(proxyPath, vmPath)), ghttp.RespondWithJSONEncoded(http.StatusOK, nil), )) - err = client.VirtualMachine(k8sv1.NamespaceDefault).Delete("testvm", &k8smetav1.DeleteOptions{}) + err = client.VirtualMachine(k8sv1.NamespaceDefault).Delete(context.Background(), "testvm", &k8smetav1.DeleteOptions{}) Expect(server.ReceivedRequests()).To(HaveLen(1)) Expect(err).ToNot(HaveOccurred()) diff --git a/tests/clone_test.go b/tests/clone_test.go index 21d8144d76b6..165792ee44bf 100644 --- a/tests/clone_test.go +++ b/tests/clone_test.go @@ -322,7 +322,7 @@ var _ = Describe("[Serial][sig-compute]VirtualMachineClone Tests", Serial, decor // of snapshot tests scope. By("Deleting VM") - err = virtClient.VirtualMachine(sourceVM.Namespace).Delete(sourceVM.Name, &v1.DeleteOptions{}) + err = virtClient.VirtualMachine(sourceVM.Namespace).Delete(context.Background(), sourceVM.Name, &v1.DeleteOptions{}) Expect(err).ToNot(HaveOccurred()) By("Creating a clone with a snapshot source") @@ -547,7 +547,7 @@ var _ = Describe("[Serial][sig-compute]VirtualMachineClone Tests", Serial, decor snapshot = waitSnapshotReady(snapshot) By("Deleting VM") - err = virtClient.VirtualMachine(sourceVM.Namespace).Delete(sourceVM.Name, &v1.DeleteOptions{}) + err = virtClient.VirtualMachine(sourceVM.Namespace).Delete(context.Background(), sourceVM.Name, &v1.DeleteOptions{}) Expect(err).ToNot(HaveOccurred()) By("Creating a clone and expecting error") diff --git a/tests/dryrun_test.go b/tests/dryrun_test.go index 7af002dc9143..982fb5663e1a 100644 --- a/tests/dryrun_test.go +++ b/tests/dryrun_test.go @@ -173,7 +173,7 @@ var _ = Describe("[sig-compute]Dry-Run requests", decorators.SigCompute, func() DryRun: []string{metav1.DryRunAll}, PropagationPolicy: &deletePolicy, } - err = virtClient.VirtualMachine(vm.Namespace).Delete(vm.Name, &opts) + err = virtClient.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, &opts) Expect(err).ToNot(HaveOccurred()) By("Check that no Virtual Machine was actually deleted") diff --git a/tests/instancetype_test.go b/tests/instancetype_test.go index fbf286fc2f18..ad29e9df800a 100644 --- a/tests/instancetype_test.go +++ b/tests/instancetype_test.go @@ -610,7 +610,7 @@ var _ = Describe("[crit:medium][vendor:cnv-qe@redhat.com][level:component][sig-c By("Stopping and removing VM") vm = tests.StopVirtualMachine(vm) - err = virtClient.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(vm.Name, &metav1.DeleteOptions{}) + err = virtClient.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{}) Expect(err).ToNot(HaveOccurred()) // Wait until ControllerRevision is deleted diff --git a/tests/kubectl_test.go b/tests/kubectl_test.go index 5efe2e296aa0..b2970c6b807a 100644 --- a/tests/kubectl_test.go +++ b/tests/kubectl_test.go @@ -98,7 +98,7 @@ var _ = Describe("[sig-compute]oc/kubectl integration", decorators.SigCompute, f }) AfterEach(func() { - virtCli.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(vm.Name, &metav1.DeleteOptions{}) + virtCli.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{}) }) DescribeTable("should verify set of columns for", func(verb, resource string, expectedHeader []string) { diff --git a/tests/operator/operator.go b/tests/operator/operator.go index a0e694f2c380..d587272da8a2 100644 --- a/tests/operator/operator.go +++ b/tests/operator/operator.go @@ -2395,7 +2395,7 @@ spec: } if vm != nil && vm.DeletionTimestamp == nil { - err = virtClient.VirtualMachine(vm.Namespace).Delete(vm.Name, &metav1.DeleteOptions{}) + err = virtClient.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{}) Expect(err).ToNot(HaveOccurred()) } vm = nil diff --git a/tests/pool_test.go b/tests/pool_test.go index 80263575fda6..56b16a2c01d7 100644 --- a/tests/pool_test.go +++ b/tests/pool_test.go @@ -264,7 +264,7 @@ var _ = Describe("[sig-compute]VirtualMachinePool", decorators.SigCompute, func( By("deleting a VM") foreGround := metav1.DeletePropagationForeground - Expect(virtClient.VirtualMachine(newPool.ObjectMeta.Namespace).Delete(name, &k8smetav1.DeleteOptions{PropagationPolicy: &foreGround})).To(Succeed()) + Expect(virtClient.VirtualMachine(newPool.ObjectMeta.Namespace).Delete(context.Background(), name, &k8smetav1.DeleteOptions{PropagationPolicy: &foreGround})).To(Succeed()) By("Waiting for deleted VM to be replaced") Eventually(func() error { @@ -338,7 +338,7 @@ var _ = Describe("[sig-compute]VirtualMachinePool", decorators.SigCompute, func( name := vms.Items[1].Name By("deleting a VM") - Expect(virtClient.VirtualMachine(newPool.ObjectMeta.Namespace).Delete(name, &k8smetav1.DeleteOptions{})).To(Succeed()) + Expect(virtClient.VirtualMachine(newPool.ObjectMeta.Namespace).Delete(context.Background(), name, &k8smetav1.DeleteOptions{})).To(Succeed()) By("Waiting for deleted VM to be replaced") Eventually(func() error { diff --git a/tests/storage/datavolume.go b/tests/storage/datavolume.go index ff4d902278f5..e722e4af7f20 100644 --- a/tests/storage/datavolume.go +++ b/tests/storage/datavolume.go @@ -681,7 +681,7 @@ var _ = SIGDescribe("DataVolume Integration", func() { Expect(err).ToNot(HaveOccurred()) Expect(domXml).ToNot(ContainSubstring("discard='unmap'")) vm = tests.StopVirtualMachine(vm) - Expect(virtClient.VirtualMachine(vm.Namespace).Delete(vm.Name, &metav1.DeleteOptions{})).To(Succeed()) + Expect(virtClient.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{})).To(Succeed()) }) DescribeTable("[test_id:3191]should be successfully started and stopped multiple times", func(isHTTP bool) { @@ -737,7 +737,7 @@ var _ = SIGDescribe("DataVolume Integration", func() { // Delete the VM with orphan Propagation orphanPolicy := metav1.DeletePropagationOrphan Expect(virtClient.VirtualMachine(vm.Namespace). - Delete(vm.Name, &metav1.DeleteOptions{PropagationPolicy: &orphanPolicy})).To(Succeed()) + Delete(context.Background(), vm.Name, &metav1.DeleteOptions{PropagationPolicy: &orphanPolicy})).To(Succeed()) // Wait for the owner reference to disappear Eventually(ThisDVWith(vm.Namespace, vm.Spec.DataVolumeTemplates[0].Name), 100).Should(Not(BeOwned())) @@ -799,7 +799,7 @@ var _ = SIGDescribe("DataVolume Integration", func() { } if createdVirtualMachine != nil { - err := virtClient.VirtualMachine(createdVirtualMachine.Namespace).Delete(createdVirtualMachine.Name, &metav1.DeleteOptions{}) + err := virtClient.VirtualMachine(createdVirtualMachine.Namespace).Delete(context.Background(), createdVirtualMachine.Name, &metav1.DeleteOptions{}) Expect(err).ToNot(HaveOccurred()) } }) diff --git a/tests/storage/hotplug.go b/tests/storage/hotplug.go index dbedf77b8d01..6daee70d0eae 100644 --- a/tests/storage/hotplug.go +++ b/tests/storage/hotplug.go @@ -102,7 +102,7 @@ var _ = SIGDescribe("Hotplug", func() { } deleteVirtualMachine := func(vm *v1.VirtualMachine) error { - return virtClient.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(vm.Name, &metav1.DeleteOptions{}) + return virtClient.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{}) } getAddVolumeOptions := func(volumeName string, bus v1.DiskBus, volumeSource *v1.HotplugVolumeSource, dryRun bool, cache v1.DriverCache) *v1.AddVolumeOptions { @@ -1091,7 +1091,7 @@ var _ = SIGDescribe("Hotplug", func() { AfterEach(func() { if vm != nil { - err := virtClient.VirtualMachine(vm.Namespace).Delete(vm.Name, &metav1.DeleteOptions{}) + err := virtClient.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{}) Expect(err).ToNot(HaveOccurred()) vm = nil } diff --git a/tests/storage/memorydump.go b/tests/storage/memorydump.go index 8cdf1e04ad52..6e6f485c8128 100644 --- a/tests/storage/memorydump.go +++ b/tests/storage/memorydump.go @@ -130,7 +130,7 @@ var _ = SIGDescribe("Memory dump", func() { deleteVirtualMachine := func(vm *v1.VirtualMachine) { waitDeleted(func() error { - return virtClient.VirtualMachine(vm.Namespace).Delete(vm.Name, &metav1.DeleteOptions{}) + return virtClient.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{}) }) vm = nil } diff --git a/tests/storage/restore.go b/tests/storage/restore.go index c8be7a1452f2..1cc2834f6ac5 100644 --- a/tests/storage/restore.go +++ b/tests/storage/restore.go @@ -192,7 +192,7 @@ var _ = SIGDescribe("VirtualMachineRestore Tests", func() { } deleteVM := func(vm *v1.VirtualMachine) { - err := virtClient.VirtualMachine(vm.Namespace).Delete(vm.Name, &metav1.DeleteOptions{}) + err := virtClient.VirtualMachine(vm.Namespace).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{}) if errors.IsNotFound(err) { err = nil } diff --git a/tests/template_test.go b/tests/template_test.go index e9b81f53b9ec..ca914991e6e6 100644 --- a/tests/template_test.go +++ b/tests/template_test.go @@ -132,7 +132,7 @@ var _ = Describe("[Serial][sig-compute]Templates", Serial, decorators.SigCompute return func() { if vm, err := virtClient.VirtualMachine(util.NamespaceTestDefault).Get(context.Background(), vmName, &metav1.GetOptions{}); err == nil && vm.ObjectMeta.DeletionTimestamp == nil { By("Deleting the VirtualMachine") - ExpectWithOffset(1, virtClient.VirtualMachine(util.NamespaceTestDefault).Delete(vmName, &metav1.DeleteOptions{})).To(Succeed(), "failed to delete VirtualMachine %q: %v", vmName, err) + ExpectWithOffset(1, virtClient.VirtualMachine(util.NamespaceTestDefault).Delete(context.Background(), vmName, &metav1.DeleteOptions{})).To(Succeed(), "failed to delete VirtualMachine %q: %v", vmName, err) EventuallyWithOffset(1, func() bool { obj, err := virtClient.VirtualMachine(util.NamespaceTestDefault).Get(context.Background(), vmName, &metav1.GetOptions{}) return k8serrors.IsNotFound(err) || obj.ObjectMeta.DeletionTimestamp != nil diff --git a/tests/vm_test.go b/tests/vm_test.go index c853708cc028..9e5ceaafcc44 100644 --- a/tests/vm_test.go +++ b/tests/vm_test.go @@ -430,7 +430,7 @@ var _ = Describe("[rfe_id:1177][crit:medium][vendor:cnv-qe@redhat.com][level:com defer libstorage.DeleteDataVolume(&dv) newVM := createVirtualMachine(true, template) // Delete it - Expect(virtClient.VirtualMachine(newVM.Namespace).Delete(newVM.Name, &k8smetav1.DeleteOptions{})).To(Succeed()) + Expect(virtClient.VirtualMachine(newVM.Namespace).Delete(context.Background(), newVM.Name, &k8smetav1.DeleteOptions{})).To(Succeed()) // Wait until VMI is gone Eventually(func() int { vmis, err := virtClient.VirtualMachineInstance(newVM.Namespace).List(context.Background(), &k8smetav1.ListOptions{}) @@ -457,7 +457,7 @@ var _ = Describe("[rfe_id:1177][crit:medium][vendor:cnv-qe@redhat.com][level:com orphanPolicy := k8smetav1.DeletePropagationOrphan By("Deleting VM") Expect(virtClient.VirtualMachine(newVM.Namespace). - Delete(newVM.Name, &k8smetav1.DeleteOptions{PropagationPolicy: &orphanPolicy})).To(Succeed()) + Delete(context.Background(), newVM.Name, &k8smetav1.DeleteOptions{PropagationPolicy: &orphanPolicy})).To(Succeed()) // Wait until the virtual machine is deleted By("Waiting for VM to delete") Eventually(func() bool { @@ -2381,7 +2381,7 @@ status: Expect(err).ToNot(HaveOccurred()) } - err = virtClient.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(vm.Name, &metav1.DeleteOptions{}) + err = virtClient.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{}) Expect(err).ToNot(HaveOccurred()) By("Ensure the vm has disappeared") @@ -2412,7 +2412,7 @@ status: g.Expect(controller.HasFinalizer(vm, v1.VirtualMachineControllerFinalizer)).To(BeTrue()) }, 2*time.Minute, 1*time.Second) - err = virtClient.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(vm.Name, &metav1.DeleteOptions{}) + err = virtClient.VirtualMachine(testsuite.GetTestNamespace(vm)).Delete(context.Background(), vm.Name, &metav1.DeleteOptions{}) Expect(err).ToNot(HaveOccurred()) Eventually(func(g Gomega) {