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.

pkg/webhook/vlanconfig/validator.go Show resolved Hide resolved
pkg/webhook/nad/validator.go Outdated Show resolved Hide resolved
@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]>
for _, vm := range vms {
if vm.Namespace != nad.Namespace {
continue
}
Copy link
Contributor

@rrajendran17 rrajendran17 Dec 17, 2024

Choose a reason for hiding this comment

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

is this check needed ?

if err := v.checkVmi(vc, nodes); err != nil {
return fmt.Errorf(deleteErr, vc.Name, err)
}

nads, err := v.nadCache.List(util.HarvesterSystemNamespaceName, labels.Set(map[string]string{
utils.KeyClusterNetworkLabel: vc.Spec.ClusterNetwork,
}).AsSelector())
Copy link
Contributor

Choose a reason for hiding this comment

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

The namespace must be "" or metav1.NamespaceAll as we need to fetch all nads from all namespaces.
HarvesterSystemNamespaceName will fetch nads only from harvester-system namespace

@rrajendran17
Copy link
Contributor

Thanks @mingshuoqiu for taking care of the comments.
Overall LGTM, except few minor comments.Can you please validate the code changes for nad deletion, vlan config deletion with vms stopped scenarios and add the steps to testplan also.Thanks.


for _, vm := range vmsTmp {
if vm.Namespace != nad.Namespace {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about this existing check and if its needed, we can still attach a nad from any namespace to a vm in any namespace.This operation is supported currently.And with this check we might miss vms that have attached a nad from another namespace and the nad could be deleted while the vm is still present.

Copy link
Member

@starbops starbops left a comment

Choose a reason for hiding this comment

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

I have a general question regarding the fix: Do we still need the VmiGetter? Under what circumstances do we rely on VMIs to check whether an action is allowed or not? Maybe the logic in the WhoUseNad for VMI and VM is redundant, and we can completely replace VMI with VM. Please advise. Thank you.

@mingshuoqiu
Copy link
Contributor Author

Need to re-implement the WhoUseNad since the indexeres.VMByNetworkIndex has been removed from harvester v1.4. Will replace the WhoUseNad by different logic.

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.

3 participants