-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add source_image
to disk_attachment
#196
base: main
Are you sure you want to change the base?
Conversation
9123cfa
to
ef30f03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @adsr,
Thanks for the feature! The code looks good to me, I left a couple of questions, but overall this looks good to me.
Just to be sure, have you tested the feature? We should probably add some acceptance test for this, I can take care of it since we'll run them on our accounts, could I ask you to share some template I can take inspiration from in order to write this?
Out of curiosity, this looks like this is essentially for pre-populating extra drives with images, may I ask you what you're using this feature for?
I'll come back later to approve it and possibly write the acceptance test.
@@ -196,7 +204,7 @@ func (bd *BlockDevice) prepareDiskCreate() []error { | |||
errs = append(errs, fmt.Errorf("Scratch volumes cannot have a name specified.")) | |||
} | |||
|
|||
if bd.VolumeSize == 0 { | |||
if bd.VolumeSize == 0 && bd.SourceImage == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, any chance we can validate the volume's size is large enough to accomodate the image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't traced how or where this happens but VolumeSize
appears to be ignored when specifiying a SourceImage
.
EDIT: It only appeared that way because it was making a 3rd disk (see #196 (comment)). The API actually throws an error if the disk is too small:
==> googlecompute.chef: failed to create disk: googleapi: Error 400: Invalid value for field 'resource.sizeGb': '1'. Requested disk size cannot be smaller than the image size (20 GB), invalid
It seems fine to me to rely on the API. Would you prefer to raise an error ahead of time? I imagine we'd fetch metadata of the source image to figure out its size in order to compare.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on the API is sound indeed. We should probably warn in the docs so that users are aware they have to set the size and that they need to ensure the disk is larger than the base image.
Is the error clearly presented to the user? Or is the excerpt you shared from appears in the verbose logs only?
If it's the latter, we should probably figure out a way to return it clearly, otherwise it looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong then, but if we specify a source image, we have to specify the disk size as well, correct? If so this check is not valid anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we specify a source image, we have to specify the disk size as well, correct?
It's still optional I believe. Disk size defaults to the image size if you don't specify it (i.e., 0) which I think is desirable the majority of the time. Here are Google's docs for DiskSizeGb
:
Specifies the size of the disk in base-2 GB. The size must be at least 10 GB. If you specify a sourceImage, which is required for boot disks, the default size is the size of the sourceImage. If you do not specify a sourceImage, the default disk size is 500 GB.
Is the error clearly presented to the user?
I think this was without debug logs. I will double check and get back to you to confirm.
ef30f03
to
bcb6727
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for the review.
Just to be sure, have you tested the feature?
Out of curiosity, this looks like this is essentially for pre-populating extra drives with images, may I ask you what you're using this feature for?
Yes, we've tested the feature. We intend to use this in conjunction with #190 to modify a bootable OS image without actually booting it. Booting an image and modifying it in place causes side effects which we need to avoid. So we mount the image as an extra disk (this PR), mount and modify it at runtime, and tell Packer to re-image the extra disk (#190).
could I ask you to share some template I can take inspiration from in order to write this?
I'll get back to you on that.
@@ -196,7 +204,7 @@ func (bd *BlockDevice) prepareDiskCreate() []error { | |||
errs = append(errs, fmt.Errorf("Scratch volumes cannot have a name specified.")) | |||
} | |||
|
|||
if bd.VolumeSize == 0 { | |||
if bd.VolumeSize == 0 && bd.SourceImage == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't traced how or where this happens but VolumeSize
appears to be ignored when specifiying a SourceImage
.
EDIT: It only appeared that way because it was making a 3rd disk (see #196 (comment)). The API actually throws an error if the disk is too small:
==> googlecompute.chef: failed to create disk: googleapi: Error 400: Invalid value for field 'resource.sizeGb': '1'. Requested disk size cannot be smaller than the image size (20 GB), invalid
It seems fine to me to rely on the API. Would you prefer to raise an error ahead of time? I imagine we'd fetch metadata of the source image to figure out its size in order to compare.
Here's a barebones template that illustrates what we're going for. source "googlecompute" "image_extra_disk" {
project_id = var.gcp_project_id
zone = var.gcp_zone
source_image_family = var.source_image_family
image_name = var.image_name
disk_attachment {
disk_name = "extra-disk"
device_name = "extra_disk"
source_image = var.extra_disk_source_image_family
volume_type = "pd-standard"
}
image_source_disk = "extra-disk"
} |
EDIT: Force-pushed to 689fc55. Now creating just 2 just disks as expected. |
f1ea966
to
689fc55
Compare
689fc55
to
e375e8c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @adsr,
Thanks for the rerolls, I left a couple nits, but overall this looks good to me!
I pushed a refactor for the common code recently which conflicts with your PR, let me know if you need a hand to rebase that, but other than that, we're good for a merge soon.
DeviceName: "packer-test", | ||
InitializeParams: &compute.AttachedDiskInitializeParams{ | ||
DiskName: "packer-test-disk", | ||
SourceImage: "projects/p/global/images/family/f", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised we need to define the SourceImage
for both the BlockDevice
and the AttachedDisk
objects, is this required?
SourceImage: bd.SourceImage, | ||
} | ||
} else { | ||
disk.Source = bd.SourceVolume |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the SourceVolume
and the SourceImage
are mutually exclusive, I believe this can remain part of the definition for the AttachedDisk
?
Hi @adsr thanks for your help in pushing this enhancement forward. It looks like there were just a few suggestions left to address with a rebase to resolve conflicts. Are you still interested in pushing this PR forward? |
We would like to use this feature in our project. Is there smth we can help with? In case we are stuck with this PR, we can open an alternative PR with this feature. Please, let me know if there is smth we can help with ��� |
Add ability to specify a
source_image
in adisk_attachment
.Relevant excerpt from GCP godocs: