From c4a76706440496047b3df87f0deba2ace76f72d1 Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Wed, 29 Sep 2021 14:20:58 +0800 Subject: [PATCH] fix(webhooks): use correct network name format Signed-off-by: Frank Yang --- pkg/webhook/resources/network/validator.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/webhook/resources/network/validator.go b/pkg/webhook/resources/network/validator.go index ee0363b25f..381ec47ef6 100644 --- a/pkg/webhook/resources/network/validator.go +++ b/pkg/webhook/resources/network/validator.go @@ -121,11 +121,19 @@ func (v *networkAttachmentDefinitionValidator) getVLAN(namespace string, vid int func (v *networkAttachmentDefinitionValidator) Delete(request *types.Request, oldObj runtime.Object) error { netAttachDef := oldObj.(*v1.NetworkAttachmentDefinition) - networkName := netAttachDef.Name + + // multus network name can be or / + // ref: https://github.com/kubevirt/client-go/blob/148fa0d1c7e83b7a56606a7ca92394ba6768c9ac/api/v1/schema.go#L1436-L1439 + networkName := fmt.Sprintf("%s/%s", netAttachDef.Namespace, netAttachDef.Name) vms, err := v.vms.GetByIndex(indexeres.VMByNetworkIndex, networkName) if err != nil { return err } + if vmsTmp, err := v.vms.GetByIndex(indexeres.VMByNetworkIndex, netAttachDef.Name); err != nil { + return err + } else { + vms = append(vms, vmsTmp...) + } if len(vms) > 0 { vmNameList := make([]string, 0, len(vms))