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

Use VMCache instead of VMICache to judge if the NAD is in use #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mingshuoqiu
Copy link
Contributor

The VMI status will be none if the VM is turned off from the GUI. The VMI information can't not be relied to make sure if particular NAD is attched to any VM or not. Use VMCache instead to prevent from deleting the NAD if the VM is turned off.

Problem:
Fail to delete an Off VM if its network was deleted. The VM network can be deleted if the attached VM is off. It will be a problem if user try to turn the VM back to on.

Solution:
Do not allow VM network removing if the VM still exists, even it is OFF.

Related Issue:
harvester/harvester#6961

Test plan:

  1. Create a VM network
  2. Create a VM and attached to the created VM network
  3. Turn the VM from Running to Off.
  4. Remove the VM network. Should not be allowed.

@rrajendran17
Copy link
Contributor

@mingshuoqiu can you also add steps in Testplan for verifying deletion of vlan config as well with stopped vm.

@@ -218,20 +217,13 @@ func (v *Validator) checkVmi(vc *networkv1.VlanConfig, nodes mapset.Set[string])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

since NAD deletion is validating for the presence of stopped vms, vlan config deletion could just validate the presence of NADs attached to the cluster network.Checking the presence of vms again could be redundant in vlanconfig deletion

@@ -135,7 +138,7 @@ func (v *Validator) checkVmi(nad *cniv1.NetworkAttachmentDefinition) error {
if len(vmis) > 0 {
vmiNameList := make([]string, 0, len(vmis))
for _, vmi := range vmis {
vmiNameList = append(vmiNameList, vmi.Namespace+"/"+vmi.Name)
vmiNameList = append(vmiNameList, vmi)
}
return fmt.Errorf("it's still used by VM(s) %s which must be stopped at first", strings.Join(vmiNameList, ", "))
Copy link
Contributor

Choose a reason for hiding this comment

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

Error msg should be different for update and delete case.
"It is still used by vms, vms must be stopped first" - for update NAD
"nad cannot be deleted as it is still attached to vms" - for delete NAD

@mingshuoqiu mingshuoqiu force-pushed the issue_6961 branch 2 times, most recently from bdf0dbd to bec79e5 Compare December 9, 2024 06:12
The VMI status will be none if the VM is turned off from the GUI.
The VMI information can't not be relied to make sure if particular
NAD is attched to any VM or not. Use VMCache instead to prevent
from deleting the NAD if the VM is turned off.

Signed-off-by: Chris Chiu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants