Skip to content

Commit aa9916a

Browse files
authored
Merge pull request #2057 from sbueringer/pr-drop-delete-func
🌱 Cleanup deleteFunc in VmopMachineService
2 parents dba258c + 8c1e324 commit aa9916a

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

pkg/services/vmoperator/vmopmachine.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ import (
4141
vmwareutil "sigs.k8s.io/cluster-api-provider-vsphere/pkg/util/vmware"
4242
)
4343

44-
type VmopMachineService struct {
45-
deleteFunc func(vm *vmoprv1.VirtualMachine) error
46-
}
44+
type VmopMachineService struct{}
4745

4846
func (v *VmopMachineService) FetchVSphereMachine(client client.Client, name types.NamespacedName) (context.MachineContext, error) {
4947
vsphereMachine := &vmwarev1.VSphereMachine{}
@@ -85,13 +83,6 @@ func (v *VmopMachineService) ReconcileDelete(c context.MachineContext) error {
8583
}()
8684
}
8785

88-
// Allow deleteFunc to be swappable for unit testing
89-
if v.deleteFunc == nil {
90-
v.deleteFunc = func(vm *vmoprv1.VirtualMachine) error {
91-
return ctx.Client.Delete(ctx, vm)
92-
}
93-
}
94-
9586
// First, check to see if it's already deleted
9687
vmopVM := vmoprv1.VirtualMachine{}
9788
if err := ctx.Client.Get(ctx, types.NamespacedName{Namespace: ctx.Machine.Namespace, Name: ctx.Machine.Name}, &vmopVM); err != nil {
@@ -110,7 +101,7 @@ func (v *VmopMachineService) ReconcileDelete(c context.MachineContext) error {
110101
}
111102

112103
// If none of the above are true, Delete the VM
113-
if err := v.deleteFunc(&vmopVM); err != nil {
104+
if err := ctx.Client.Delete(ctx, &vmopVM); err != nil {
114105
if apierrors.IsNotFound(err) {
115106
ctx.VSphereMachine.Status.VMStatus = vmwarev1.VirtualMachineStateNotFound
116107
return err

pkg/services/vmoperator/vmopmachine_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,6 @@ var _ = Describe("VirtualMachine tests", func() {
545545

546546
BeforeEach(func() {
547547
requeue, err = vmService.ReconcileNormal(ctx)
548-
// There is no GC behavior in the unit test environment, so simulate it
549-
vmService.deleteFunc = func(vm *vmoprv1.VirtualMachine) error {
550-
return ctx.Client.Delete(ctx, vm)
551-
}
552548
})
553549

554550
// Test expects DestroyVM to return NotFound eventually

0 commit comments

Comments
 (0)