Skip to content
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

Remove existing Cloud-Init drive before creation #139

Merged
merged 1 commit into from
Jan 20, 2023
Merged

Remove existing Cloud-Init drive before creation #139

merged 1 commit into from
Jan 20, 2023

Conversation

sebastian-de
Copy link
Contributor

If a template is created from a VM with a Cloud-Init drive, the existing drive is neither deleted nor updated in stepFinalizeTemplateConfig and Proxmox throws TASK ERROR: zfs error: cannot create 'rpool/data/vm-106-cloudinit': dataset already exists and the build fails.

This PR adds stepRemoveCloudInitDrive, which will remove the Cloud-Init drive before finalizing the template.

To produce a clean template, also remove Cloud-Init configuration parameters set during build.
If cloud_init is set to true, the resulting drive will be empty.

Tested on PVE 7.3

Closes #112

@sebastian-de sebastian-de requested a review from a team as a code owner January 17, 2023 18:39
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sebastian-de,

Just left a few comments on the code and tests, I'm puzzled by the test more than the code.
Once you addressed the comments I left, I'll do another pass and if we're good, we'll merge that.

Thanks!

return multistep.ActionHalt
}
// The cloud-init drive is usually attached to ide0, but check the other controllers as well
ideControllers := []string{"ide0", "ide1", "ide2", "ide3"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super knowledgeable when it comes to Proxmox, but is this list finite? Is there any chance the cloud-init drive might not be one of those?
Judging how you're getting the controllers, would it be relevant to iterate on the vmParams to gather all the existing controllers (ide or other possible values) and remove the attribute in those that define it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it's not possible to link to the config entries directly, so I'm quoting https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/config here:

ide[n] string [...] Use volume as IDE hard disk or CD-ROM (n is 0 to 3).

Proxmox always defaults to IDE for Cloud-Init drives, but yes, in theory you can attach it to other controllers as well. I added them to the code.

if !c.expectCallSetConfig {
t.Error("Did not expect SetVmConfig to be called")
}
for key, val := range c.expectedVMConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this test, what is it working with? Looking at the code the payload should essentially contain only a delete key/val, therefore the other values are nil by default, since no value exists for each key in the expectedVMConfig, unless I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh dear, sorry for the headaches...
I rewrote the tests, don't know what I was thinking, when I wrote them initially.

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sebastian-de,

Thanks for the reroll, the test makes more sense to me with the rewrite, I'm approving this PR.

I left a couple more nits to address, once you've had a chance to address them, we can merge.

Thanks again for the contribution!

builder/proxmox/common/step_remove_cloud_init_drive.go Outdated Show resolved Hide resolved
builder/proxmox/common/step_remove_cloud_init_drive.go Outdated Show resolved Hide resolved
If the existing drive is not deleted it won't get updated in
stepFinalizeTemplateConfig and Proxmox gives an error:
"TASK ERROR: zfs error: cannot create 'rpool/data/vm-106-cloudinit': dataset already exists"

To produce a clean template, also remove Cloud-Init configuration
parameters set during build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proxmox-clone will always fill the cloud-init drive with the ssh communicator config
2 participants