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

MAC address cleanup #304

Merged
merged 2 commits into from
Dec 18, 2024
Merged

Conversation

alromeros
Copy link
Contributor

@alromeros alromeros commented Dec 11, 2024

What this PR does / why we need it:

When a virtual machine is restored to an alternate namespace, the virtual machine is restored with the same MAC address as the original one. This results in a MAC address conflict if the original virtual machine is still running on the original namespace.

Though we already have a work-in-progress PR, recent interest in this feature has forced us to open a new one to address this issue. From now on, users can optionally clean a VM or VMI MAC address by setting the "velero.kubevirt.io/clear-mac-address" label in the restore object.

Cherry-picked a couple of commits from #235 to keep the original contributor's work.

/cc @esteban-ee

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

Release note:

Support clearing MAC address by label

@kubevirt-bot
Copy link

@alromeros: GitHub didn't allow me to request PR reviews from the following users: esteban-ee.

Note that only kubevirt members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

What this PR does / why we need it:

When a virtual machine is restored to an alternate namespace, the virtual machine is restored with the same MAC address as the original virtual machine. This results in a MAC address conflict if the original virtual machine is still running on the original namespace.

Though we already have a work-in-progress PR, recent interest in this feature has forced us to open a new one to address this issue. From now on, users can optionally clean a VM or VMI MAC address by setting the "velero.kubevirt.io/clear-mac-address" label in the restore object.

Cherry-picked a couple of commits from #235 to keep the original contributor's work.

/cc @esteban-ee

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

Release note:

Support clearing MAC address by label

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.

@kubevirt-bot kubevirt-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/L labels Dec 11, 2024
@alromeros alromeros changed the title [WIP] MAC address cleanup MAC address cleanup Dec 11, 2024
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 11, 2024
@alromeros
Copy link
Contributor Author

/cc @ShellyKa13 @mhenriks

@mhenriks
Copy link
Member

/approve

@kubevirt-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mhenriks

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 Dec 13, 2024
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.

Some comments are relevant to the 2 commit which are not yours.. I get the desire to use community member commits but they dont have much value.. I believe you should either delete them or squash the first 3 commits and add him as as signed by also..

@@ -63,6 +63,10 @@ func (p *VMRestorePlugin) Execute(input *velero.RestoreItemActionExecuteInput) (
return nil, errors.WithStack(err)
}

for i := 0; i < len(vm.Spec.Template.Spec.Domain.Devices.Interfaces); i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

dont think you need this commit..

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 having "incomplete" commits such as these if they showcase the development history and specifically wanted to make an exception for these as they are from another contributor. That said, we've had this conversation in the past and I'm also ok with a cleaner approach, so I'll squash them as suggested.

@@ -63,8 +64,11 @@ func (p *VMRestorePlugin) Execute(input *velero.RestoreItemActionExecuteInput) (
return nil, errors.WithStack(err)
}

for i := 0; i < len(vm.Spec.Template.Spec.Domain.Devices.Interfaces); i++ {
vm.Spec.Template.Spec.Domain.Devices.Interfaces[i].MacAddress = ""
if util.IsMacAdressClearedByAnnotation(vm) {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo Adress -> address
Also I think the name is missleading..
consider something like: ShouldClearMacAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Related to my comment above

if util.IsMacAdressClearedByAnnotation(vm) {
p.log.Info("Clear virtual machine MAC addresses")
for i := 0; i < len(vm.Spec.Template.Spec.Domain.Devices.Interfaces); i++ {
vm.Spec.Template.Spec.Domain.Devices.Interfaces[i].MacAddress = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

I think its better also to put this in a function ClearMacAddress

vm kvcore.VirtualMachine
expected bool
}{
{"Clear mac addres should return false",
Copy link
Contributor

Choose a reason for hiding this comment

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

the name of the tests should also explain what is tested i.e here: with no annotation, in the next with annotation false etc..

{"Clear mac addres should return false",
"VirtualMachine",
kvcore.VirtualMachine{
{"Clear MAC address should return false",
Copy link
Contributor

Choose a reason for hiding this comment

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

you should add here "without label" and in the next test "with label"

vm.Spec.Template.Spec.Domain.Devices.Interfaces[0].MacAddress = originalMAC
return vm
}
retryOnceOnErr(updateVm(f.KvClient, f.Namespace.Name, vm.Name, update)).Should(BeNil())
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe you should use patch here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a preexisting function used in several other tests, prefer to leave it here and consider refactoring the function itself in a follow-up.

Expect(err).ToNot(HaveOccurred())
Expect(phase).To(Equal(velerov1api.BackupPhaseCompleted))

By("Stopping VM")
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you need to stop the vm before you delete 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.

Just a remnant from copy-pasting another test that does the same. I can remove it.

@alromeros alromeros force-pushed the mac-address-cleanup branch 2 times, most recently from 3ff4b30 to 2a82153 Compare December 16, 2024 11:06
@alromeros
Copy link
Contributor Author

/test pull-kvp-functional-test

@alromeros alromeros requested a review from ShellyKa13 December 16, 2024 14:41
Copy link
Member

@awels awels left a comment

Choose a reason for hiding this comment

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

putting hold on it so Shelly can take a look, but if not before you want it merged, you have the lgtm
/hold

@kubevirt-bot kubevirt-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Dec 17, 2024
This commit allows to optionally clear the MAC address in VM and VMIs during restore.

Currently, the way to go for modular backup/restore behavior in velero plugin is by using labels instead of annotations.

Labels are easier to add to the restore/backup objects during creation as the velero client has a flag to include them.

This commit also changes some const names to use PascalCase to match exported const naming standard.

Signed-off-by: Eduardo Esteban <[email protected]>

Signed-off-by: Alvaro Romero <[email protected]>
@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 17, 2024
@alromeros alromeros requested a review from awels December 17, 2024 16:02
@ShellyKa13
Copy link
Contributor

/unhold
/lgtm
Nice work! thanks!

@kubevirt-bot kubevirt-bot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Dec 18, 2024
@kubevirt-bot kubevirt-bot merged commit dfff8d2 into kubevirt:main Dec 18, 2024
5 checks passed
@alromeros
Copy link
Contributor Author

alromeros commented Dec 18, 2024

Will backport this once #310 is merged, thanks @ShellyKa13!

@alromeros
Copy link
Contributor Author

/cherrypick release-v0.7

1 similar comment
@alromeros
Copy link
Contributor Author

/cherrypick release-v0.7

@kubevirt-bot
Copy link

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

Applying: Clear MAC address by label
Using index info to reconstruct a base tree...
M	pkg/plugin/vm_restore_item_action.go
M	pkg/plugin/vmi_restore_item_action.go
M	pkg/util/util.go
M	pkg/util/util_test.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/util/util_test.go
CONFLICT (content): Merge conflict in pkg/util/util_test.go
Auto-merging pkg/util/util.go
Auto-merging pkg/plugin/vmi_restore_item_action.go
CONFLICT (content): Merge conflict in pkg/plugin/vmi_restore_item_action.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 Clear MAC address by label

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/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MAC address conflict when restoring a virtual machine to alternate namespace
5 participants