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

Generate new firmware UUID during restore #317

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

alromeros
Copy link
Contributor

What this PR does / why we need it:

This Pull Request implements a new label, "velero.kubevirt.io/generate-new-firmware-uuid" that when used in the restore object, the velero plugin will generate new firmware UUIDS for all restored VMs.

Which issue(s) this PR fixes:
Fixes # #199 (comment)

Special notes for your reviewer:

Release note:

Add label to optionally generate new firmware UUID during restore

@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/M labels Jan 7, 2025
@alromeros
Copy link
Contributor Author

/test pull-kvp-unit-test

pkg/util/util.go Outdated
// GenerateNewFirmwareUUID generates a new firmware UUID for the restored VM, ensuring it will be different than the one
// Kubevirt generates for the original VM by using a different magicUUID and hashing name+namespace.
func GenerateNewFirmwareUUID(vmiSpec *kvv1.VirtualMachineInstanceSpec, name, namespace string) {
vmiSpec.Domain.Firmware.UUID = types.UID(uuid.NewSHA1(firmwareUUIDns, []byte(name+namespace)).String())
Copy link
Member

@mhenriks mhenriks Jan 7, 2025

Choose a reason for hiding this comment

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

Did you get this code from kubevirt? Shouldn't there be / between namespace and name? Otherwise hash(foo, bar) = hash(f, oobar)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, used this PR as reference kubevirt/kubevirt#12885. This can be improved with your suggestion, will add the / and fix the test later today.

Copy link
Member

Choose a reason for hiding this comment

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

See what they do here: kubevirt/kubevirt#13150

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ACK

Copy link
Member

Choose a reason for hiding this comment

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

Should've looked at this sooner: kubevirt/community#347

namespace/name was abandoned for object uid. Unfortunately we cannot use that here so may as well just generate new random uids

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, but we can't do much until it merges. Are we still ok with this implementation?

Copy link
Member

Choose a reason for hiding this comment

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

I think random uuid is better, one of the goals of the proposal is to never have two VMs with the same firmware ID and the current scheme does not give us that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not against generating a random one but currently I'm hashing name/namespace/UID, isn't that enough to secure unique IDs per VM?

Copy link
Member

@mhenriks mhenriks Jan 9, 2025

Choose a reason for hiding this comment

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

No because VMs with same name/namespace is deleted+recreated it will have the same id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotcha

Copy link
Contributor

@ShellyKa13 ShellyKa13 Jan 8, 2025

Choose a reason for hiding this comment

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

its not strictly related to this PR.. but there is a pattern of

if [should do something since there is the label on the restore] {
       do something accordingly
}

and for Run strategy it is different, and it bugs me a bit lol
do you mind changing

	if runStrategy, ok := util.GetRestoreRunStrategy(input.Restore); ok {
		p.log.Infof("Setting virtual machine run strategy to %s", runStrategy)
		vm.Spec.RunStrategy = ptr.To(runStrategy)
		vm.Spec.Running = nil
	}

to something like:

if util.ShouldUpdateVmRunStrategy(input.Restore) {
		p.log.Infof("Setting virtual machine run strategy to %s", runStrategy)
                util.UpdateVMRunStrategy(input.Restore, &vm.Spec)
}

and do the actual update in a function in util? as done for MacAddress and now FirmwareUUID
Ill appreciate 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.

That one is different because it's not used in both VM and VMI restore files so there's no redundant code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But yeah I agree that it might look more organized if I add the function. I'm planning to also support annotations for all these operations soon, so I can handle it in a follow-up if you don't mind :)

@alromeros alromeros force-pushed the new-firmware-uuid branch 6 times, most recently from 7679c31 to 4211ea4 Compare January 8, 2025 21:12
@dasionov
Copy link

dasionov commented Jan 9, 2025

/cc @dasionov

pkg/util/util.go Outdated
}

// GenerateNewFirmwareUUID generates a new firmware UUID for the restored VM, ensuring it will be different than the one
// Kubevirt generates for the original VM by using a different magicUUID and hashing name+namespace.
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like the comment is outdated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, good catch

Copy link
Contributor

@ShellyKa13 ShellyKa13 left a comment

Choose a reason for hiding this comment

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

/approve

@kubevirt-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ShellyKa13

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 15, 2025
This commit implements a new label, "velero.kubevirt.io/generate-new-firmware-uuid", that when used in the restore object, the velero plugin will generate new firmware UUIDS for restored VMs.

Signed-off-by: Alvaro Romero <[email protected]>
@mhenriks
Copy link
Member

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 17, 2025
@kubevirt-bot kubevirt-bot merged commit a07ca1a into kubevirt:main Jan 17, 2025
5 checks passed
@alromeros
Copy link
Contributor Author

/cherrypick release-v0.7

@kubevirt-bot
Copy link

@alromeros: #317 failed to apply on top of branch "release-v0.7":

Applying: Add label to generate new firmware UUIDS for restored VMs
Using index info to reconstruct a base tree...
M	pkg/plugin/vm_restore_item_action.go
M	pkg/plugin/vm_restore_item_action_test.go
M	pkg/plugin/vmi_restore_item_action.go
M	pkg/util/util.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/util/util.go
Auto-merging pkg/plugin/vmi_restore_item_action.go
Auto-merging pkg/plugin/vm_restore_item_action_test.go
CONFLICT (content): Merge conflict in pkg/plugin/vm_restore_item_action_test.go
Auto-merging pkg/plugin/vm_restore_item_action.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 Add label to generate new firmware UUIDS for restored VMs

In response to this:

/cherrypick release-v0.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants