Skip to content

Commit

Permalink
network: rename cniNetworks map
Browse files Browse the repository at this point in the history
This map contains the multus index number per network name. Let us give
it a name that reminds of what is in the map.

Signed-off-by: Dan Kenigsberg <[email protected]>
  • Loading branch information
dankenigsberg committed Mar 5, 2021
1 parent 9e02f74 commit 08aa282
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pkg/virt-launcher/virtwrap/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,38 @@ type podNIC interface {
PlugPhase2(vmi *v1.VirtualMachineInstance, iface *v1.Interface, network *v1.Network, domain *api.Domain, podInterfaceName string) error
}

func getNetworksAndCniNetworks(vmi *v1.VirtualMachineInstance) (map[string]*v1.Network, map[string]int) {
func getNetworksAndMultusIndices(vmi *v1.VirtualMachineInstance) (map[string]*v1.Network, map[string]int) {
networks := map[string]*v1.Network{}
cniNetworks := map[string]int{}
multusIndices := map[string]int{}
for _, network := range vmi.Spec.Networks {
networks[network.Name] = network.DeepCopy()
if networks[network.Name].Multus != nil && !networks[network.Name].Multus.Default {
// multus pod interfaces start from 1
cniNetworks[network.Name] = len(cniNetworks) + 1
multusIndices[network.Name] = len(multusIndices) + 1
}
}
return networks, cniNetworks
return networks, multusIndices
}

func getPodInterfaceName(networks map[string]*v1.Network, cniNetworks map[string]int, ifaceName string) string {
func getPodInterfaceName(networks map[string]*v1.Network, multusIndices map[string]int, ifaceName string) string {
if networks[ifaceName].Multus != nil && !networks[ifaceName].Multus.Default {
// multus pod interfaces named netX
return fmt.Sprintf("net%d", cniNetworks[ifaceName])
return fmt.Sprintf("net%d", multusIndices[ifaceName])
} else {
return primaryPodInterfaceName
}
}

func SetupPodNetworkPhase1(vmi *v1.VirtualMachineInstance, pid int, cacheFactory cache.InterfaceCacheFactory) error {
networks, cniNetworks := getNetworksAndCniNetworks(vmi)
networks, multusIndices := getNetworksAndMultusIndices(vmi)
for i, iface := range vmi.Spec.Domain.Devices.Interfaces {
network, ok := networks[iface.Name]
if !ok {
return fmt.Errorf("failed to find a network %s", iface.Name)
}
podnic := podNICFactory(cacheFactory)
podInterfaceName := getPodInterfaceName(networks, cniNetworks, iface.Name)
err = podNIC.PlugPhase1(podnic, vmi, &vmi.Spec.Domain.Devices.Interfaces[i], network, podInterfaceName, pid)
podInterfaceName := getPodInterfaceName(networks, multusIndices, iface.Name)
err := podNIC.PlugPhase1(podnic, vmi, &vmi.Spec.Domain.Devices.Interfaces[i], network, podInterfaceName, pid)
if err != nil {
return err
}
Expand All @@ -98,15 +98,15 @@ func SetupPodNetworkPhase1(vmi *v1.VirtualMachineInstance, pid int, cacheFactory
}

func SetupPodNetworkPhase2(vmi *v1.VirtualMachineInstance, domain *api.Domain, cacheFactory cache.InterfaceCacheFactory) error {
networks, cniNetworks := getNetworksAndCniNetworks(vmi)
networks, multusIndices := getNetworksAndMultusIndices(vmi)
for i, iface := range vmi.Spec.Domain.Devices.Interfaces {
network, ok := networks[iface.Name]
if !ok {
return fmt.Errorf("failed to find a network %s", iface.Name)
}
podnic := podNICFactory(cacheFactory)
podInterfaceName := getPodInterfaceName(networks, cniNetworks, iface.Name)
err = podNIC.PlugPhase2(podnic, vmi, &vmi.Spec.Domain.Devices.Interfaces[i], network, domain, podInterfaceName)
podInterfaceName := getPodInterfaceName(networks, multusIndices, iface.Name)
err := podNIC.PlugPhase2(podnic, vmi, &vmi.Spec.Domain.Devices.Interfaces[i], network, domain, podInterfaceName)
if err != nil {
return err
}
Expand Down

0 comments on commit 08aa282

Please sign in to comment.