Fix: panic and crash when size
parameter of a disk
is not parseable into a Quantity
#111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The
harvester_virtualmachine
and its subresources are parsed and converted into akubevirtv1.VirtualMachine
object using aVMBuilder
factory. ThisVMBuilder
assumes that parameters given to it have some semblance of sanity. This means amongst other things that thesize
parameter of a volume must be a parseable into aresource.Quantity
usingresource.MustParse
, e.g."10Gi"
.The
size
parameter isn't always required, but when it is required, if a user omits it the Terraform provider will just fill it with a default value.Since the
size
parameter of adisk
subresource of aharvester_virtualmachine
is user input, it must be sanitized before being passed on to theVMBuilder
. In case it isn't parseable, a sensible error must be emitted and further processing of the virtual machine resource must be stopped.To do this, the parsing function of the
disk
subresource ofharvester_virtualmachine
resources is re-ordered such that the different cases where thesize
parameter matters and where it is ignored are more clearly defined.When it matters, the
size
parameter is checked before being passed on to theVMBuilder
.This also allows a default value to be used when the
size
parameter isn't given, but is required.Related Issues: