Skip to content

Commit

Permalink
network: refactor newpodNIC
Browse files Browse the repository at this point in the history
The factory function newPodNIC exists only to accomodate our tests.
However, it also did something unrelated: verify that a network is
implementable by KubeVirt.

Extracting the verififcation part would allow us to simplify newPodNIC
in a followup commit.

Signed-off-by: Dan Kenigsberg <[email protected]>
  • Loading branch information
dankenigsberg committed Mar 5, 2021
1 parent 89dbfb1 commit be4c288
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/virt-launcher/virtwrap/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func getNetworksAndCniNetworks(vmi *v1.VirtualMachineInstance) (map[string]*v1.N
return networks, cniNetworks
}

func networkIsImplementable(network *v1.Network) error {
if network.Pod == nil && network.Multus == nil {
return fmt.Errorf("Network not implemented")
}
return nil
}

func getPodInterfaceName(networks map[string]*v1.Network, cniNetworks map[string]int, ifaceName string) string {
if networks[ifaceName].Multus != nil && !networks[ifaceName].Multus.Default {
// multus pod interfaces named netX
Expand All @@ -87,6 +94,10 @@ func SetupPodNetworkPhase1(vmi *v1.VirtualMachineInstance, pid int, cacheFactory
if !ok {
return fmt.Errorf("failed to find a network %s", iface.Name)
}
err := networkIsImplementable(network)
if err != nil {
return err
}
podnic, err := podNICFactory(network, cacheFactory)
if err != nil {
return err
Expand All @@ -107,6 +118,10 @@ func SetupPodNetworkPhase2(vmi *v1.VirtualMachineInstance, domain *api.Domain, c
if !ok {
return fmt.Errorf("failed to find a network %s", iface.Name)
}
err := networkIsImplementable(network)
if err != nil {
return err
}
podnic, err := podNICFactory(network, cacheFactory)
if err != nil {
return err
Expand All @@ -121,8 +136,5 @@ func SetupPodNetworkPhase2(vmi *v1.VirtualMachineInstance, domain *api.Domain, c
}

func newpodNIC(network *v1.Network, cacheFactory cache.InterfaceCacheFactory) (podNIC, error) {
if network.Pod != nil || network.Multus != nil {
return &podNICImpl{cacheFactory: cacheFactory}, nil
}
return nil, fmt.Errorf("Network not implemented")
return &podNICImpl{cacheFactory: cacheFactory}, nil
}

0 comments on commit be4c288

Please sign in to comment.