@@ -13,12 +13,7 @@ import (
1313 "k8s.io/klog/v2"
1414 kubevirtv1 "kubevirt.io/api/core/v1"
1515
16- nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
17- nadutils "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/utils"
18- "github.com/scylladb/go-set/strset"
19-
2016 "github.com/kubeovn/kube-ovn/pkg/informer"
21- "github.com/kubeovn/kube-ovn/pkg/ovs"
2217 "github.com/kubeovn/kube-ovn/pkg/util"
2318)
2419
@@ -141,65 +136,17 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {
141136 klog .Infof ("current vmiMigration %s status %s, vmi MigrationState is nil" , key , vmiMigration .Status .Phase )
142137 }
143138
144- // collect all port names related to the VMI (pod network/multus annotations/attached networks)
145- portNamesSet := strset .New ()
146- // only consider ports which kube-ovn created (it may be that non kube-ovn NAD attachements are being used)
147- lsps , err := c .OVNNbClient .ListNormalLogicalSwitchPorts (c .config .EnableExternalVpc , nil )
139+ lsps , err := c .OVNNbClient .ListNormalLogicalSwitchPorts (c .config .EnableExternalVpc , map [string ]string {"pod" : fmt .Sprintf ("%s/%s" , vmi .Namespace , vmi .Name )})
148140 if err != nil {
149- klog .Errorf ("failed to list logical switch port , %v" , err )
141+ klog .Errorf ("failed to list logical switch ports for vmi %s/%s , %v" , vmi . Namespace , vmi . Name , err )
150142 return err
151143 }
152144
153- allPortNames := strset . NewWithSize ( len (lsps ))
145+ portNames := make ([] string , 0 , len (lsps ))
154146 for _ , lsp := range lsps {
155- allPortNames .Add (lsp .Name )
156- }
157-
158- defaultMultus := false
159- for _ , network := range vmi .Spec .Networks {
160- if network .Multus != nil && network .Multus .Default {
161- defaultMultus = true
162- break
163- }
164- }
165- if ! defaultMultus {
166- portName := ovs .PodNameToPortName (vmiMigration .Spec .VMIName , vmiMigration .Namespace , util .OvnProvider )
167- if allPortNames .Has (portName ) {
168- portNamesSet .Add (portName )
169- }
170- }
171-
172- nadAnnotation := vmi .Annotations [nadv1 .NetworkAttachmentAnnot ]
173- if nadAnnotation != "" {
174- attachNets , err := nadutils .ParseNetworkAnnotation (nadAnnotation , vmi .Namespace )
175- if err != nil {
176- klog .Errorf ("failed to get attachment subnet of vmi %s, %v" , vmi .Name , err )
177- } else {
178- for _ , multiNet := range attachNets {
179- provider := fmt .Sprintf ("%s.%s.%s" , multiNet .Name , multiNet .Namespace , util .OvnProvider )
180- portName := ovs .PodNameToPortName (vmi .Name , vmi .Namespace , provider )
181- if allPortNames .Has (portName ) {
182- portNamesSet .Add (portName )
183- }
184- }
185- }
186- }
187-
188- for _ , network := range vmi .Spec .Networks {
189- if network .Multus != nil && network .Multus .NetworkName != "" {
190- items := strings .Split (network .Multus .NetworkName , "/" )
191- if len (items ) != 2 {
192- items = []string {vmi .Namespace , items [0 ]}
193- }
194- provider := fmt .Sprintf ("%s.%s.%s" , items [1 ], items [0 ], util .OvnProvider )
195- portName := ovs .PodNameToPortName (vmi .Name , vmi .Namespace , provider )
196- if allPortNames .Has (portName ) {
197- portNamesSet .Add (portName )
198- }
199- }
147+ portNames = append (portNames , lsp .Name )
200148 }
201149
202- portNames := portNamesSet .List ()
203150 klog .Infof ("collected port names of vmi %s, port names are %v" , vmi .Name , strings .Join (portNames , ", " ))
204151
205152 switch vmiMigration .Status .Phase {
0 commit comments