Skip to content

Commit ad04ac2

Browse files
authored
remove DeepEqual from backfilled volume validation (vmware-tanzu#1418)
Remove duplicate validation since validateVolume already validates immutable fields for all volumes.
1 parent e1652f0 commit ad04ac2

File tree

2 files changed

+4
-55
lines changed

2 files changed

+4
-55
lines changed

webhooks/virtualmachine/validation/virtualmachine_validator.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,8 @@ func (v validator) validateInstanceStorageVolumes(
16401640
return allErrs
16411641
}
16421642

1643-
// validateBackfilledVolumesNotRemoved checks if any volumes backfilled from classic
1644-
// disks have been removed from the spec when the AllDisksArePVCs feature is disabled.
1643+
// validateBackfilledVolumesNotRemoved checks if any volumes backfilled from
1644+
// classic disks have been removed or modified.
16451645
func (v validator) validateBackfilledVolumesNotRemoved(
16461646
_ *pkgctx.WebhookRequestContext,
16471647
vm, oldVM *vmopv1.VirtualMachine,
@@ -1670,18 +1670,12 @@ func (v validator) validateBackfilledVolumesNotRemoved(
16701670
continue
16711671
}
16721672

1673-
newVol, exists := newVolumesMap[oldVol.Name]
1673+
// No need to validate immutable fields since they are validated in validateVolume.
1674+
_, exists := newVolumesMap[oldVol.Name]
16741675
if !exists {
16751676
allErrs = append(allErrs, field.Forbidden(
16761677
volumesPath,
16771678
fmt.Sprintf("%s: %s", oldVol.Name, removingBackfilledVolumeNotAllowed)))
1678-
continue
1679-
}
1680-
1681-
if !equality.Semantic.DeepEqual(*newVol, oldVol) {
1682-
allErrs = append(allErrs, field.Forbidden(
1683-
volumesPath,
1684-
fmt.Sprintf("%s: %s", oldVol.Name, modifyingBackfilledVolumeNotAllowed)))
16851679
}
16861680
}
16871681

webhooks/virtualmachine/validation/virtualmachine_validator_unit_test.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7707,28 +7707,6 @@ func unitTestsValidateUpdate() { //nolint:gocyclo
77077707
validate: doValidateWithMsg("spec.volumes: Forbidden: backfilled-vol: removing volume backfilled from classic disk is not allowed"),
77087708
},
77097709
),
7710-
Entry("should deny modifying a backfilled volume",
7711-
testParams{
7712-
setup: func(ctx *unitValidatingWebhookContext) {
7713-
// Create a backfilled volume in old VM
7714-
backfilledVol := vmopv1.VirtualMachineVolume{
7715-
Name: "backfilled-vol",
7716-
ControllerType: vmopv1.VirtualControllerTypeSCSI,
7717-
ControllerBusNumber: ptr.To(int32(0)),
7718-
UnitNumber: ptr.To(int32(1)),
7719-
// No PersistentVolumeClaim
7720-
}
7721-
ctx.oldVM.Spec.Volumes = append(ctx.oldVM.Spec.Volumes, backfilledVol)
7722-
7723-
// Modify it in new VM (change unit number)
7724-
modifiedVol := backfilledVol.DeepCopy()
7725-
modifiedVol.UnitNumber = ptr.To(int32(2))
7726-
ctx.vm.Spec.Volumes = append(ctx.vm.Spec.Volumes, *modifiedVol)
7727-
},
7728-
expectAllowed: false,
7729-
validate: doValidateWithMsg("spec.volumes: Forbidden: backfilled-vol: modifying backfilled volume is not allowed"),
7730-
},
7731-
),
77327710
Entry("should allow when backfilled volume is unchanged",
77337711
testParams{
77347712
setup: func(ctx *unitValidatingWebhookContext) {
@@ -7792,29 +7770,6 @@ func unitTestsValidateUpdate() { //nolint:gocyclo
77927770
expectAllowed: true,
77937771
},
77947772
),
7795-
Entry("should deny modifying ApplicationType of backfilled volume",
7796-
testParams{
7797-
setup: func(ctx *unitValidatingWebhookContext) {
7798-
// Create a backfilled volume in old VM
7799-
backfilledVol := vmopv1.VirtualMachineVolume{
7800-
Name: "backfilled-vol",
7801-
ControllerType: vmopv1.VirtualControllerTypeSCSI,
7802-
ControllerBusNumber: ptr.To(int32(0)),
7803-
UnitNumber: ptr.To(int32(1)),
7804-
ApplicationType: vmopv1.VolumeApplicationTypeOracleRAC,
7805-
// No PersistentVolumeClaim
7806-
}
7807-
ctx.oldVM.Spec.Volumes = append(ctx.oldVM.Spec.Volumes, backfilledVol)
7808-
7809-
// Change ApplicationType (but keep placement fields same)
7810-
modifiedVol := backfilledVol.DeepCopy()
7811-
modifiedVol.ApplicationType = vmopv1.VolumeApplicationTypeMicrosoftWSFC
7812-
ctx.vm.Spec.Volumes = append(ctx.vm.Spec.Volumes, *modifiedVol)
7813-
},
7814-
expectAllowed: false,
7815-
validate: doValidateWithMsg("spec.volumes: Forbidden: backfilled-vol: modifying backfilled volume is not allowed"),
7816-
},
7817-
),
78187773
)
78197774
})
78207775

0 commit comments

Comments
 (0)