-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
/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()) |
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.
Did you get this code from kubevirt? Shouldn't there be /
between namespace and name? Otherwise hash(foo, bar) = hash(f, oobar)
?
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.
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.
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.
See what they do here: kubevirt/kubevirt#13150
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.
ACK
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.
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
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.
Interesting, but we can't do much until it merges. Are we still ok with this implementation?
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 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
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 not against generating a random one but currently I'm hashing name/namespace/UID
, isn't that enough to secure unique IDs per VM?
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.
No because VMs with same name/namespace is deleted+recreated it will have the same id
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.
gotcha
pkg/plugin/vm_restore_item_action.go
Outdated
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.
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 :)
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.
That one is different because it's not used in both VM and VMI restore files so there's no redundant code.
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.
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 :)
7679c31
to
4211ea4
Compare
/cc @dasionov |
4211ea4
to
5232e76
Compare
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. |
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.
seems like the comment is outdated?
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.
Right, good catch
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.
/approve
[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 |
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]>
…uuid" label Signed-off-by: Alvaro Romero <[email protected]>
5232e76
to
087b8a6
Compare
/lgtm |
/cherrypick release-v0.7 |
@alromeros: #317 failed to apply on top of branch "release-v0.7":
In response to this:
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. |
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: