From f7f959a290e905d2c88ee32aa69342ce74083499 Mon Sep 17 00:00:00 2001 From: Bryan Venteicher Date: Mon, 28 Oct 2024 17:46:08 -0500 Subject: [PATCH] Move instancestorage to vmopv1util Doesn't need to be in old provider anymore --- .../volume/volume_controller.go | 8 +- .../volume/volume_controller_intg_test.go | 10 +- .../volume/volume_controller_unit_test.go | 4 +- .../vsphere/placement/zone_placement.go | 4 +- .../vsphere/virtualmachine/configspec.go | 3 +- pkg/providers/vsphere/vmprovider_vm_test.go | 6 +- pkg/providers/vsphere/vmprovider_vm_utils.go | 3 +- .../vsphere/vmprovider_vm_utils_test.go | 12 +- .../vmopv1/instancestorage.go} | 16 ++- pkg/util/vmopv1/instancestorage_test.go | 136 ++++++++++++++++++ .../validation/virtualmachine_validator.go | 5 +- 11 files changed, 171 insertions(+), 36 deletions(-) rename pkg/{providers/vsphere/instancestorage/instance_storage.go => util/vmopv1/instancestorage.go} (57%) create mode 100644 pkg/util/vmopv1/instancestorage_test.go diff --git a/controllers/virtualmachine/volume/volume_controller.go b/controllers/virtualmachine/volume/volume_controller.go index 5902fb58f..f24d81e9b 100644 --- a/controllers/virtualmachine/volume/volume_controller.go +++ b/controllers/virtualmachine/volume/volume_controller.go @@ -38,10 +38,10 @@ import ( "github.com/vmware-tanzu/vm-operator/pkg/patch" "github.com/vmware-tanzu/vm-operator/pkg/providers" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/constants" - "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/instancestorage" "github.com/vmware-tanzu/vm-operator/pkg/record" "github.com/vmware-tanzu/vm-operator/pkg/util" "github.com/vmware-tanzu/vm-operator/pkg/util/annotations" + vmopv1util "github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1" ) const ( @@ -271,7 +271,7 @@ func (r *Reconciler) reconcileResult(ctx *pkgctx.VolumeContext) ctrl.Result { if pkgcfg.FromContext(ctx).Features.InstanceStorage { // Requeue the request if all instance storage PVCs are not bound. _, pvcsBound := ctx.VM.Annotations[constants.InstanceStoragePVCsBoundAnnotationKey] - if !pvcsBound && instancestorage.IsPresent(ctx.VM) { + if !pvcsBound && vmopv1util.IsInstanceStoragePresent(ctx.VM) { return ctrl.Result{RequeueAfter: wait.Jitter( pkgcfg.FromContext(ctx).InstanceStorage.SeedRequeueDuration, pkgcfg.FromContext(ctx).InstanceStorage.JitterMaxFactor, @@ -344,7 +344,7 @@ func (r *Reconciler) reconcileInstanceStoragePVCs(ctx *pkgctx.VolumeContext) (bo // If the VM Spec doesn't have any instance storage volumes, there is nothing for us to do. // We do not support removing - or changing really - this type of volume. - isVolumes := instancestorage.FilterVolumes(ctx.VM) + isVolumes := vmopv1util.FilterInstanceStorageVolumes(ctx.VM) if len(isVolumes) == 0 { return true, nil } @@ -538,7 +538,7 @@ func (r *Reconciler) createInstanceStoragePVC( // We merely consider creating non-existing PVCs in reconcileInstanceStoragePVCs flow. // We specifically don't need of CreateOrUpdate / CreateOrPatch. if err := r.Create(ctx, pvc); err != nil { - if instancestorage.IsInsufficientQuota(err) { + if vmopv1util.IsInsufficientQuota(err) { r.recorder.EmitEvent(ctx.VM, "Create", err, true) } return err diff --git a/controllers/virtualmachine/volume/volume_controller_intg_test.go b/controllers/virtualmachine/volume/volume_controller_intg_test.go index 698f5bffe..9e431f322 100644 --- a/controllers/virtualmachine/volume/volume_controller_intg_test.go +++ b/controllers/virtualmachine/volume/volume_controller_intg_test.go @@ -25,8 +25,8 @@ import ( "github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels" "github.com/vmware-tanzu/vm-operator/pkg/patch" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/constants" - "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/instancestorage" "github.com/vmware-tanzu/vm-operator/pkg/util" + vmopv1util "github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1" "github.com/vmware-tanzu/vm-operator/test/builder" ) @@ -154,7 +154,7 @@ func intgTestsReconcile() { vm := getVirtualMachine(objKey) Expect(vm).ToNot(BeNil()) - volumes := instancestorage.FilterVolumes(vm) + volumes := vmopv1util.FilterInstanceStorageVolumes(vm) Expect(volumes).ToNot(BeEmpty()) Eventually(func() bool { @@ -185,7 +185,7 @@ func intgTestsReconcile() { vm := getVirtualMachine(objKey) Expect(vm).ToNot(BeNil()) - volumes := instancestorage.FilterVolumes(vm) + volumes := vmopv1util.FilterInstanceStorageVolumes(vm) Expect(volumes).ToNot(BeEmpty()) Eventually(func() bool { @@ -209,7 +209,7 @@ func intgTestsReconcile() { vm := getVirtualMachine(objKey) Expect(vm).ToNot(BeNil()) - volumes := instancestorage.FilterVolumes(vm) + volumes := vmopv1util.FilterInstanceStorageVolumes(vm) Expect(volumes).ToNot(BeEmpty()) for _, vol := range volumes { @@ -323,7 +323,7 @@ func intgTestsReconcile() { Specify("PVCs are created with the expected annotation", func() { Expect(ctx.Client.Get(ctx, vmKey, vm)).To(Succeed()) - volumes := instancestorage.FilterVolumes(vm) + volumes := vmopv1util.FilterInstanceStorageVolumes(vm) Expect(volumes).ToNot(BeEmpty()) Eventually(func(g Gomega) { diff --git a/controllers/virtualmachine/volume/volume_controller_unit_test.go b/controllers/virtualmachine/volume/volume_controller_unit_test.go index 5a684a218..6c3540af7 100644 --- a/controllers/virtualmachine/volume/volume_controller_unit_test.go +++ b/controllers/virtualmachine/volume/volume_controller_unit_test.go @@ -31,9 +31,9 @@ import ( pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context" providerfake "github.com/vmware-tanzu/vm-operator/pkg/providers/fake" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/constants" - "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/instancestorage" "github.com/vmware-tanzu/vm-operator/pkg/util" "github.com/vmware-tanzu/vm-operator/pkg/util/ptr" + vmopv1util "github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1" "github.com/vmware-tanzu/vm-operator/test/builder" ) @@ -1230,7 +1230,7 @@ func getInstanceStoragePVCs(ctx *pkgctx.VolumeContext, testCtx *builder.UnitTest var errs []error pvcList := make([]corev1.PersistentVolumeClaim, 0) - volumes := instancestorage.FilterVolumes(ctx.VM) + volumes := vmopv1util.FilterInstanceStorageVolumes(ctx.VM) for _, vol := range volumes { objKey := client.ObjectKey{ Namespace: ctx.VM.Namespace, diff --git a/pkg/providers/vsphere/placement/zone_placement.go b/pkg/providers/vsphere/placement/zone_placement.go index 9a9c461ab..14be89037 100644 --- a/pkg/providers/vsphere/placement/zone_placement.go +++ b/pkg/providers/vsphere/placement/zone_placement.go @@ -20,9 +20,9 @@ import ( pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config" pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/constants" - "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/instancestorage" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/vcenter" "github.com/vmware-tanzu/vm-operator/pkg/topology" + vmopv1util "github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1" ) type Constraints struct { @@ -57,7 +57,7 @@ func doesVMNeedPlacement(vmCtx pkgctx.VirtualMachineContext) (res Result, needZo } if pkgcfg.FromContext(vmCtx).Features.InstanceStorage { - if instancestorage.IsPresent(vmCtx.VM) { + if vmopv1util.IsInstanceStoragePresent(vmCtx.VM) { res.InstanceStoragePlacement = true if hostMoID := vmCtx.VM.Annotations[constants.InstanceStorageSelectedNodeMOIDAnnotationKey]; hostMoID != "" { diff --git a/pkg/providers/vsphere/virtualmachine/configspec.go b/pkg/providers/vsphere/virtualmachine/configspec.go index 56bb13196..59035a6ae 100644 --- a/pkg/providers/vsphere/virtualmachine/configspec.go +++ b/pkg/providers/vsphere/virtualmachine/configspec.go @@ -10,7 +10,6 @@ import ( pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config" pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/constants" - "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/instancestorage" "github.com/vmware-tanzu/vm-operator/pkg/util" "github.com/vmware-tanzu/vm-operator/pkg/util/ptr" vmopv1util "github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1" @@ -206,7 +205,7 @@ func CreateConfigSpecForPlacement( }) if pkgcfg.FromContext(vmCtx).Features.InstanceStorage { - isVolumes := instancestorage.FilterVolumes(vmCtx.VM) + isVolumes := vmopv1util.FilterInstanceStorageVolumes(vmCtx.VM) for idx, dev := range CreateInstanceStorageDiskDevices(isVolumes) { configSpec.DeviceChange = append(configSpec.DeviceChange, &vimtypes.VirtualDeviceConfigSpec{ diff --git a/pkg/providers/vsphere/vmprovider_vm_test.go b/pkg/providers/vsphere/vmprovider_vm_test.go index 899f59d3a..9f4aef2bd 100644 --- a/pkg/providers/vsphere/vmprovider_vm_test.go +++ b/pkg/providers/vsphere/vmprovider_vm_test.go @@ -38,12 +38,12 @@ import ( "github.com/vmware-tanzu/vm-operator/pkg/providers" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/constants" - "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/instancestorage" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/virtualmachine" "github.com/vmware-tanzu/vm-operator/pkg/topology" pkgutil "github.com/vmware-tanzu/vm-operator/pkg/util" kubeutil "github.com/vmware-tanzu/vm-operator/pkg/util/kube" "github.com/vmware-tanzu/vm-operator/pkg/util/ptr" + vmopv1util "github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1" "github.com/vmware-tanzu/vm-operator/pkg/vmconfig" "github.com/vmware-tanzu/vm-operator/pkg/vmconfig/crypto" "github.com/vmware-tanzu/vm-operator/test/builder" @@ -2049,7 +2049,7 @@ func vmTests() { isStorage vmopv1.InstanceStorage) { ExpectWithOffset(1, isStorage.Volumes).ToNot(BeEmpty()) - isVolumes := instancestorage.FilterVolumes(vm) + isVolumes := vmopv1util.FilterInstanceStorageVolumes(vm) ExpectWithOffset(1, isVolumes).To(HaveLen(len(isStorage.Volumes))) for _, isVol := range isStorage.Volumes { @@ -2094,7 +2094,7 @@ func vmTests() { Expect(conditions.IsTrue(vm, vmopv1.VirtualMachineConditionCreated)).To(BeFalse()) By("Instance storage volumes should be added to VM", func() { - Expect(instancestorage.IsPresent(vm)).To(BeTrue()) + Expect(vmopv1util.IsInstanceStoragePresent(vm)).To(BeTrue()) expectInstanceStorageVolumes(vm, vmClass.Spec.Hardware.InstanceStorage) }) diff --git a/pkg/providers/vsphere/vmprovider_vm_utils.go b/pkg/providers/vsphere/vmprovider_vm_utils.go index c443406c0..226f7a26c 100644 --- a/pkg/providers/vsphere/vmprovider_vm_utils.go +++ b/pkg/providers/vsphere/vmprovider_vm_utils.go @@ -21,7 +21,6 @@ import ( pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config" pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/constants" - "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/instancestorage" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/sysprep" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/vmlifecycle" "github.com/vmware-tanzu/vm-operator/pkg/util" @@ -492,7 +491,7 @@ func AddInstanceStorageVolumes( vmCtx pkgctx.VirtualMachineContext, is vmopv1.InstanceStorage) bool { - if instancestorage.IsPresent(vmCtx.VM) { + if vmopv1util.IsInstanceStoragePresent(vmCtx.VM) { // Instance storage disks are copied from the class to the VM only once, regardless // if the class changes. return true diff --git a/pkg/providers/vsphere/vmprovider_vm_utils_test.go b/pkg/providers/vsphere/vmprovider_vm_utils_test.go index f81fb4f6d..d593b5e4d 100644 --- a/pkg/providers/vsphere/vmprovider_vm_utils_test.go +++ b/pkg/providers/vsphere/vmprovider_vm_utils_test.go @@ -21,9 +21,9 @@ import ( "github.com/vmware-tanzu/vm-operator/pkg/conditions" pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config" pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context" - vsphere "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere" - "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/instancestorage" + "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere" "github.com/vmware-tanzu/vm-operator/pkg/util" + vmopv1util "github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1" "github.com/vmware-tanzu/vm-operator/test/builder" ) @@ -911,7 +911,7 @@ func vmUtilTests() { isStorage vmopv1.InstanceStorage) { ExpectWithOffset(1, isStorage.Volumes).ToNot(BeEmpty()) - isVolumes := instancestorage.FilterVolumes(vm) + isVolumes := vmopv1util.FilterInstanceStorageVolumes(vm) ExpectWithOffset(1, isVolumes).To(HaveLen(len(isStorage.Volumes))) for _, isVol := range isStorage.Volumes { @@ -939,7 +939,7 @@ func vmUtilTests() { It("VM Class does not contain instance storage volumes", func() { is := vsphere.AddInstanceStorageVolumes(vmCtx, vmClass.Spec.Hardware.InstanceStorage) Expect(is).To(BeFalse()) - Expect(instancestorage.FilterVolumes(vmCtx.VM)).To(BeEmpty()) + Expect(vmopv1util.FilterInstanceStorageVolumes(vmCtx.VM)).To(BeEmpty()) }) When("Instance Volume is added in VM Class", func() { @@ -957,13 +957,13 @@ func vmUtilTests() { is := vsphere.AddInstanceStorageVolumes(vmCtx, vmClass.Spec.Hardware.InstanceStorage) Expect(is).To(BeTrue()) - isVolumesBefore := instancestorage.FilterVolumes(vmCtx.VM) + isVolumesBefore := vmopv1util.FilterInstanceStorageVolumes(vmCtx.VM) expectInstanceStorageVolumes(vmCtx.VM, vmClass.Spec.Hardware.InstanceStorage) // Instance Storage is already configured, should not patch again is = vsphere.AddInstanceStorageVolumes(vmCtx, vmClass.Spec.Hardware.InstanceStorage) Expect(is).To(BeTrue()) - isVolumesAfter := instancestorage.FilterVolumes(vmCtx.VM) + isVolumesAfter := vmopv1util.FilterInstanceStorageVolumes(vmCtx.VM) Expect(isVolumesAfter).To(HaveLen(len(isVolumesBefore))) Expect(isVolumesAfter).To(Equal(isVolumesBefore)) }) diff --git a/pkg/providers/vsphere/instancestorage/instance_storage.go b/pkg/util/vmopv1/instancestorage.go similarity index 57% rename from pkg/providers/vsphere/instancestorage/instance_storage.go rename to pkg/util/vmopv1/instancestorage.go index b36c1ba18..705bdde4c 100644 --- a/pkg/providers/vsphere/instancestorage/instance_storage.go +++ b/pkg/util/vmopv1/instancestorage.go @@ -1,7 +1,7 @@ // Copyright (c) 2021 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package instancestorage +package vmopv1 import ( "strings" @@ -11,8 +11,8 @@ import ( vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3" ) -// IsPresent checks if VM Spec has instance volumes added to its Volumes list. -func IsPresent(vm *vmopv1.VirtualMachine) bool { +// IsInstanceStoragePresent checks if VM Spec has instance volumes added to its Volumes list. +func IsInstanceStoragePresent(vm *vmopv1.VirtualMachine) bool { for _, vol := range vm.Spec.Volumes { if pvc := vol.PersistentVolumeClaim; pvc != nil && pvc.InstanceVolumeClaim != nil { return true @@ -21,8 +21,8 @@ func IsPresent(vm *vmopv1.VirtualMachine) bool { return false } -// FilterVolumes returns instance storage volumes present in VM spec. -func FilterVolumes(vm *vmopv1.VirtualMachine) []vmopv1.VirtualMachineVolume { +// FilterInstanceStorageVolumes returns instance storage volumes present in VM spec. +func FilterInstanceStorageVolumes(vm *vmopv1.VirtualMachine) []vmopv1.VirtualMachineVolume { var volumes []vmopv1.VirtualMachineVolume for _, vol := range vm.Spec.Volumes { if pvc := vol.PersistentVolumeClaim; pvc != nil && pvc.InstanceVolumeClaim != nil { @@ -34,8 +34,10 @@ func FilterVolumes(vm *vmopv1.VirtualMachine) []vmopv1.VirtualMachineVolume { } func IsInsufficientQuota(err error) bool { - if apierrors.IsForbidden(err) && (strings.Contains(err.Error(), "insufficient quota") || strings.Contains(err.Error(), "exceeded quota")) { - return true + if apierrors.IsForbidden(err) { + e := err.Error() + return strings.Contains(e, "insufficient quota") || strings.Contains(e, "exceeded quota") } + return false } diff --git a/pkg/util/vmopv1/instancestorage_test.go b/pkg/util/vmopv1/instancestorage_test.go new file mode 100644 index 000000000..35fd893ab --- /dev/null +++ b/pkg/util/vmopv1/instancestorage_test.go @@ -0,0 +1,136 @@ +// Copyright (c) 2024 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package vmopv1_test + +import ( + "errors" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime/schema" + + vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3" + vmopv1util "github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1" +) + +var _ = Describe("IsInstanceStoragePresent", func() { + var vm *vmopv1.VirtualMachine + + BeforeEach(func() { + vm = &vmopv1.VirtualMachine{} + }) + + When("VM does not have instance storage", func() { + BeforeEach(func() { + vm.Spec.Volumes = append(vm.Spec.Volumes, vmopv1.VirtualMachineVolume{ + Name: "my-vol", + VirtualMachineVolumeSource: vmopv1.VirtualMachineVolumeSource{ + PersistentVolumeClaim: &vmopv1.PersistentVolumeClaimVolumeSource{ + PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: "my-pvc", + }, + InstanceVolumeClaim: nil, + }, + }, + }) + }) + + It("returns false", func() { + Expect(vmopv1util.IsInstanceStoragePresent(vm)).To(BeFalse()) + }) + }) + + When("VM has instance storage", func() { + BeforeEach(func() { + vm.Spec.Volumes = append(vm.Spec.Volumes, + vmopv1.VirtualMachineVolume{ + Name: "my-vol", + VirtualMachineVolumeSource: vmopv1.VirtualMachineVolumeSource{ + PersistentVolumeClaim: &vmopv1.PersistentVolumeClaimVolumeSource{ + PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: "my-pvc", + }, + }, + }, + }, + vmopv1.VirtualMachineVolume{ + Name: "my-is-vol", + VirtualMachineVolumeSource: vmopv1.VirtualMachineVolumeSource{ + PersistentVolumeClaim: &vmopv1.PersistentVolumeClaimVolumeSource{ + PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: "my-is-pvc", + }, + InstanceVolumeClaim: &vmopv1.InstanceVolumeClaimVolumeSource{ + StorageClass: "foo", + }, + }, + }, + }) + }) + + It("returns true", func() { + Expect(vmopv1util.IsInstanceStoragePresent(vm)).To(BeTrue()) + }) + }) +}) + +var _ = Describe("FilterInstanceStorageVolumes", func() { + var vm *vmopv1.VirtualMachine + + BeforeEach(func() { + vm = &vmopv1.VirtualMachine{} + }) + + When("VM has no volumes", func() { + It("returns empty list", func() { + Expect(vmopv1util.FilterInstanceStorageVolumes(vm)).To(BeEmpty()) + }) + }) + + When("VM has volumes", func() { + BeforeEach(func() { + vm.Spec.Volumes = append(vm.Spec.Volumes, + vmopv1.VirtualMachineVolume{ + Name: "my-vol", + VirtualMachineVolumeSource: vmopv1.VirtualMachineVolumeSource{ + PersistentVolumeClaim: &vmopv1.PersistentVolumeClaimVolumeSource{ + PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: "my-pvc", + }, + }, + }, + }, + vmopv1.VirtualMachineVolume{ + Name: "my-is-vol", + VirtualMachineVolumeSource: vmopv1.VirtualMachineVolumeSource{ + PersistentVolumeClaim: &vmopv1.PersistentVolumeClaimVolumeSource{ + PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: "my-is-pvc", + }, + InstanceVolumeClaim: &vmopv1.InstanceVolumeClaimVolumeSource{ + StorageClass: "foo", + }, + }, + }, + }) + }) + + It("returns instance storage volumes", func() { + volumes := vmopv1util.FilterInstanceStorageVolumes(vm) + Expect(volumes).To(HaveLen(1)) + Expect(volumes[0]).To(Equal(vm.Spec.Volumes[1])) + }) + }) +}) + +var _ = Describe("IsInsufficientQuota", func() { + + It("returns true", func() { + err := apierrors.NewForbidden(schema.GroupResource{}, "", errors.New("insufficient quota for creating PVC")) + Expect(vmopv1util.IsInsufficientQuota(err)).To(BeTrue()) + }) +}) diff --git a/webhooks/virtualmachine/validation/virtualmachine_validator.go b/webhooks/virtualmachine/validation/virtualmachine_validator.go index 9c7dabbf1..f416561c7 100644 --- a/webhooks/virtualmachine/validation/virtualmachine_validator.go +++ b/webhooks/virtualmachine/validation/virtualmachine_validator.go @@ -38,7 +38,6 @@ import ( "github.com/vmware-tanzu/vm-operator/pkg/constants" pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context" "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/config" - "github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/instancestorage" "github.com/vmware-tanzu/vm-operator/pkg/topology" "github.com/vmware-tanzu/vm-operator/pkg/util" cloudinitvalidate "github.com/vmware-tanzu/vm-operator/pkg/util/cloudinit/validate" @@ -904,10 +903,10 @@ func (v validator) validateInstanceStorageVolumes( var oldVMInstanceStorageVolumes []vmopv1.VirtualMachineVolume if oldVM != nil { - oldVMInstanceStorageVolumes = instancestorage.FilterVolumes(oldVM) + oldVMInstanceStorageVolumes = vmopv1util.FilterInstanceStorageVolumes(oldVM) } - if !equality.Semantic.DeepEqual(instancestorage.FilterVolumes(vm), oldVMInstanceStorageVolumes) { + if !equality.Semantic.DeepEqual(vmopv1util.FilterInstanceStorageVolumes(vm), oldVMInstanceStorageVolumes) { allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "volumes"), addingModifyingInstanceVolumesNotAllowed)) }