-
Notifications
You must be signed in to change notification settings - Fork 70
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
[Issue 74] Create var for Cloud-Init Disk Type #256
Conversation
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 @xrayj11,
Thanks for the PR, and sorry I took a long time to review it.
This looks good to me overall, I have left a couple comments/suggestions, feel free to address them, and I can do another review when you've had time to respond.
Thanks again!
scsiController := fmt.Sprintf("scsi%d", i) | ||
diskControllers = append(diskControllers, scsiController) | ||
} | ||
default: |
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 would suggest defaulting to ide only if it's empty or explicitly ide
, otherwise this allows for anything and I can see this being a surprise potentially.
default: | |
"", "ide": |
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.
EDIT: nevermind I notice we're in Run
here, I'd suggest then having that check/error in the Prepare
function then, so we can set ide
if unset for example, and we can error if the option has an unsupported value.
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 have added a default, check, and error in the Prepare
function. Does this look good?
I tested it with a CloudInitDiskType
value that was not supported (not scsi
,sata
, or ide
) and it stopped packer with the error message I added. I also confirmed that blanks still default to ide
.
e03831f
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 would still suggest expliciting ide
for this case, just in case something else manages to go through the Prepare
, so that it doesn't go into ide
mode when reaching this step.
Adding a default
with an error is probably for the best for later developments, as this will error in case we update Prepare
but forget to do the same here.
default: | |
"ide": | |
// Unspecified disk type defaults to "ide" | |
diskControllers = []string{"ide0", "ide1", "ide2", "ide3"} | |
default: | |
state.Put("error", fmt.Errorf("unsupported disk type %q", c.CloudInitDiskType)) | |
return multistep.ActionHalt |
builder/proxmox/common/config.go
Outdated
@@ -183,6 +183,9 @@ type Config struct { | |||
// Name of the Proxmox storage pool | |||
// to store the Cloud-Init CDROM on. If not given, the storage pool of the boot device will be used. | |||
CloudInitStoragePool string `mapstructure:"cloud_init_storage_pool"` | |||
// The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide` | |||
// If not given, defaults to `ide`. |
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.
Nit to make it more concise.
// If not given, defaults to `ide`. | |
// Defaults to `ide`. |
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 @xrayj11,
Thanks for the update, I left a few more comments on the code for simplification and hardening purposes, please feel free to take a look and address them when you can.
I'll do another review when you've had time to do this.
Thanks!
builder/proxmox/common/config.go
Outdated
@@ -652,6 +652,16 @@ func (c *Config) Prepare(upper interface{}, raws ...interface{}) ([]string, []st | |||
log.Printf("SCSI controller not set, using default 'lsi'") | |||
c.SCSIController = "lsi" | |||
} | |||
if c.CloudInit == true { |
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 c.CloudInit == true { | |
if c.CloudInit { |
builder/proxmox/common/config.go
Outdated
@@ -652,6 +652,16 @@ func (c *Config) Prepare(upper interface{}, raws ...interface{}) ([]string, []st | |||
log.Printf("SCSI controller not set, using default 'lsi'") | |||
c.SCSIController = "lsi" | |||
} | |||
if c.CloudInit == true { | |||
if c.CloudInitDiskType == "" { |
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 believe the whole if c.CloudInit
block can be simplified with a switch
?
switch c.CloudInitDiskType {
case "ide", "scsi", "sata":
case "":
c.CloudInitDiskType = "ide"
default:
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("invalid value for `cloud_init_disk_type` %q: only one of 'ide', 'scsi', and 'sata' is valid", c.CloudInitDiskType))
}
scsiController := fmt.Sprintf("scsi%d", i) | ||
diskControllers = append(diskControllers, scsiController) | ||
} | ||
default: |
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 would still suggest expliciting ide
for this case, just in case something else manages to go through the Prepare
, so that it doesn't go into ide
mode when reaching this step.
Adding a default
with an error is probably for the best for later developments, as this will error in case we update Prepare
but forget to do the same here.
default: | |
"ide": | |
// Unspecified disk type defaults to "ide" | |
diskControllers = []string{"ide0", "ide1", "ide2", "ide3"} | |
default: | |
state.Put("error", fmt.Errorf("unsupported disk type %q", c.CloudInitDiskType)) | |
return multistep.ActionHalt |
@@ -197,6 +197,9 @@ in the image's Cloud-Init settings for provisioning. | |||
- `cloud_init_storage_pool` (string) - Name of the Proxmox storage pool | |||
to store the Cloud-Init CDROM on. If not given, the storage pool of the boot device will be used. | |||
|
|||
- `cloud_init_disk_type` (string) - The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide` | |||
If not given, defaults to `ide`. |
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 believe this should update itself based on the comment from config.go
, have you run make generate
to update that?
Hi @xrayj11, The rework looks good to me, however it seems there are failures during test, also the file should be linted/goimported so the CI is happy, may I ask you to fix those before we can merge? |
Hey @lbajolet-hashicorp, I've been trying to figure out the issue with the failed |
Ah I see @xrayj11, in this case I would suggest either of the two alternatives:
I'll let you pick which approach seems more appropriate to you, feel free to ping me when you've settled on either! |
…n Prepare. config.go formatting
I looked into trying to call |
Looks good to me @xrayj11, thanks for the reroll! Will merge if/when tests go green |
This change will allow users to specify a
cloud_init_disk_type
, which determines which type (ide, sata, scsi) of drive is created for Cloud-Init. If no value is given or the variable is not provided, the Cloud-Init drive will be created on the first available ide drive, which was how it operated before.This change should not break any existing configurations that use Cloud-Init, and only provides additional customization to specify a different drive type than the default
ide
These changes passed the
make test
, as well as packer validation after installing the newly packaged plugin and declaring thecloud_init_disk_type
var in my hcl file.I have tested this change with the proxmox-iso builder on each disk type (ide, sata, scsi) as well as not providing the var to ensure it will not break existing configurations. Each option resulted in the expected outcome, where the Cloud-Init drive was created with the type specified by the var.
Closes #74 - By giving the option of SCSI for Cloud-Init