Skip to content

Commit 95d4d26

Browse files
committed
fix: Use set to collect port names
Signed-off-by: Jules Skrill <julesskrill@gmail.com>
1 parent 3321015 commit 95d4d26

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/controller/kubevirt.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {
142142
}
143143

144144
// collect all port names related to the VMI (pod network/multus annotations/attached networks)
145-
portNames := []string{}
145+
portNamesSet := strset.New()
146146
// only consider ports which kube-ovn created (it may be that non kube-ovn NAD attachements are being used)
147147
lsps, err := c.OVNNbClient.ListNormalLogicalSwitchPorts(c.config.EnableExternalVpc, nil)
148148
if err != nil {
@@ -165,7 +165,7 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {
165165
if !defaultMultus {
166166
portName := ovs.PodNameToPortName(vmiMigration.Spec.VMIName, vmiMigration.Namespace, util.OvnProvider)
167167
if allPortNames.Has(portName) {
168-
portNames = append(portNames, portName)
168+
portNamesSet.Add(portName)
169169
}
170170
}
171171

@@ -179,7 +179,7 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {
179179
provider := fmt.Sprintf("%s.%s.%s", multiNet.Name, multiNet.Namespace, util.OvnProvider)
180180
portName := ovs.PodNameToPortName(vmi.Name, vmi.Namespace, provider)
181181
if allPortNames.Has(portName) {
182-
portNames = append(portNames, portName)
182+
portNamesSet.Add(portName)
183183
}
184184
}
185185
}
@@ -194,10 +194,12 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {
194194
provider := fmt.Sprintf("%s.%s.%s", items[1], items[0], util.OvnProvider)
195195
portName := ovs.PodNameToPortName(vmi.Name, vmi.Namespace, provider)
196196
if allPortNames.Has(portName) {
197-
portNames = append(portNames, portName)
197+
portNamesSet.Add(portName)
198198
}
199199
}
200200
}
201+
202+
portNames := portNamesSet.List()
201203
klog.Infof("collected port names of vmi %s, port names are %v", vmi.Name, strings.Join(portNames, ", "))
202204

203205
switch vmiMigration.Status.Phase {

0 commit comments

Comments
 (0)