Skip to content

Commit

Permalink
net, netconf: Process filtered networks
Browse files Browse the repository at this point in the history
When the network setup is called in the virt-handler reconcile loop, the
networks have been already filtered per the origin of the call (e.g.
migration, initial setup or a hotplug).

Preserve the networks filtered when creating the `netpod` object so
other networks will not be processed.
(e.g. hotplug networks which their pod interface is not ready, should
not be processed)

Signed-off-by: Edward Haas <[email protected]>
  • Loading branch information
EdDev committed Oct 29, 2023
1 parent cd656e4 commit 32ab077
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/network/setup/netconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"kubevirt.io/kubevirt/pkg/network/netns"
"kubevirt.io/kubevirt/pkg/network/setup/netpod"
"kubevirt.io/kubevirt/pkg/network/setup/netpod/masquerade"
"kubevirt.io/kubevirt/pkg/network/vmispec"
)

type cacheCreator interface {
Expand Down Expand Up @@ -102,8 +103,8 @@ func (c *NetConf) Setup(vmi *v1.VirtualMachineInstance, networks []v1.Network, l
}
queuesCapacity := int(converter.NetworkQueuesCapacity(vmi))
netpod := netpod.NewNetPod(
vmi.Spec.Networks,
vmi.Spec.Domain.Devices.Interfaces,
networks,
vmispec.FilterInterfacesByNetworks(vmi.Spec.Domain.Devices.Interfaces, networks),
string(vmi.UID),
launcherPid,
ownerID,
Expand Down
11 changes: 11 additions & 0 deletions pkg/network/vmispec/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,14 @@ func IndexInterfaceStatusByName(interfaces []v1.VirtualMachineInstanceNetworkInt
}
return indexedInterfaceStatus
}

func FilterInterfacesByNetworks(interfaces []v1.Interface, networks []v1.Network) []v1.Interface {
var ifaces []v1.Interface
ifacesByName := IndexInterfaceSpecByName(interfaces)
for _, net := range networks {
if iface, exists := ifacesByName[net.Name]; exists {
ifaces = append(ifaces, iface)
}
}
return ifaces
}

0 comments on commit 32ab077

Please sign in to comment.