forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instancetypes: Clear VM guest memory when ignoring inference failures
With this change the guest memory of VMs is cleared when inference of an instancetype was successful and the IgnoreInferFromVolumeFailure policy was set in the instancetype matcher. This allows to enable inference of instancetypes in virtctl by default without breaking the previous behavior by allowing virtctl to provide a fallback amount of memory to be used when inference fails. Signed-off-by: Felix Matouschek <[email protected]>
- Loading branch information
Showing
3 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1347,6 +1347,11 @@ var _ = Describe("[crit:medium][vendor:[email protected]][level:component][sig-c | |
) | ||
|
||
It("should ignore failure when trying to infer defaults from DataVolumeSpec with unsupported DataVolumeSource when policy is set", func() { | ||
guestMemory := resource.MustParse("512Mi") | ||
vm.Spec.Template.Spec.Domain.Memory = &virtv1.Memory{ | ||
Guest: &guestMemory, | ||
} | ||
|
||
// Inference from blank image source is not supported | ||
dv := libdv.NewDataVolume( | ||
libdv.WithNamespace(namespace), | ||
|
@@ -1368,7 +1373,40 @@ var _ = Describe("[crit:medium][vendor:[email protected]][level:component][sig-c | |
By("Validating the VirtualMachine") | ||
Expect(vm.Spec.Instancetype).To(BeNil()) | ||
Expect(vm.Spec.Preference).To(BeNil()) | ||
Expect(vm.Spec.Template.Spec.Domain.Memory).ToNot(BeNil()) | ||
Expect(vm.Spec.Template.Spec.Domain.Memory.Guest).ToNot(BeNil()) | ||
Expect(*vm.Spec.Template.Spec.Domain.Memory.Guest).To(Equal(guestMemory)) | ||
}) | ||
|
||
DescribeTable("should reject VM creation when inference was successful but memory and RejectInferFromVolumeFailure were set", func(explicit bool) { | ||
guestMemory := resource.MustParse("512Mi") | ||
vm.Spec.Template.Spec.Domain.Memory = &virtv1.Memory{ | ||
Guest: &guestMemory, | ||
} | ||
|
||
vm.Spec.Template.Spec.Volumes = []v1.Volume{{ | ||
Name: inferFromVolumeName, | ||
VolumeSource: v1.VolumeSource{ | ||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ | ||
PersistentVolumeClaimVolumeSource: k8sv1.PersistentVolumeClaimVolumeSource{ | ||
ClaimName: sourceDV.Name, | ||
}, | ||
}, | ||
}, | ||
}} | ||
|
||
if explicit { | ||
failurePolicy := v1.RejectInferFromVolumeFailure | ||
vm.Spec.Instancetype.InferFromVolumeFailurePolicy = &failurePolicy | ||
} | ||
|
||
By("Creating the VirtualMachine") | ||
vm, err = virtClient.VirtualMachine(namespace).Create(context.Background(), vm) | ||
Expect(err).To(MatchError("admission webhook \"virtualmachine-validator.kubevirt.io\" denied the request: VM field spec.template.spec.domain.memory conflicts with selected instance type")) | ||
}, | ||
Entry("with explicitly setting RejectInferFromVolumeFailure", true), | ||
Entry("with implicitly setting RejectInferFromVolumeFailure (default)", false), | ||
) | ||
}) | ||
|
||
Context("instance type with dedicatedCPUPlacement enabled", func() { | ||
|