Skip to content

Commit

Permalink
network: simplify signature of podNICFactory
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Kenigsberg <[email protected]>
  • Loading branch information
dankenigsberg committed Mar 5, 2021
1 parent be4c288 commit 995acd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
14 changes: 4 additions & 10 deletions pkg/virt-launcher/virtwrap/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ func SetupPodNetworkPhase1(vmi *v1.VirtualMachineInstance, pid int, cacheFactory
if err != nil {
return err
}
podnic, err := podNICFactory(network, cacheFactory)
if err != nil {
return err
}
podnic := podNICFactory(cacheFactory)
podInterfaceName := getPodInterfaceName(networks, cniNetworks, iface.Name)
err = podNIC.PlugPhase1(podnic, vmi, &vmi.Spec.Domain.Devices.Interfaces[i], network, podInterfaceName, pid)
if err != nil {
Expand All @@ -122,10 +119,7 @@ func SetupPodNetworkPhase2(vmi *v1.VirtualMachineInstance, domain *api.Domain, c
if err != nil {
return err
}
podnic, err := podNICFactory(network, cacheFactory)
if err != nil {
return err
}
podnic := podNICFactory(cacheFactory)
podInterfaceName := getPodInterfaceName(networks, cniNetworks, iface.Name)
err = podNIC.PlugPhase2(podnic, vmi, &vmi.Spec.Domain.Devices.Interfaces[i], network, domain, podInterfaceName)
if err != nil {
Expand All @@ -135,6 +129,6 @@ func SetupPodNetworkPhase2(vmi *v1.VirtualMachineInstance, domain *api.Domain, c
return nil
}

func newpodNIC(network *v1.Network, cacheFactory cache.InterfaceCacheFactory) (podNIC, error) {
return &podNICImpl{cacheFactory: cacheFactory}, nil
func newpodNIC(cacheFactory cache.InterfaceCacheFactory) podNIC {
return &podNICImpl{cacheFactory: cacheFactory}
}
12 changes: 6 additions & 6 deletions pkg/virt-launcher/virtwrap/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ var _ = Describe("Network", func() {

Context("interface configuration", func() {
It("should configure bridged pod networking by default", func() {
podNICFactory = func(network *v1.Network, cacheFactory cache.InterfaceCacheFactory) (podNIC, error) {
return mockpodNIC, nil
podNICFactory = func(cacheFactory cache.InterfaceCacheFactory) podNIC {
return mockpodNIC
}
vm := newVMIBridgeInterface("testnamespace", "testVmName")
iface := v1.DefaultBridgeNetworkInterface()
Expand All @@ -68,8 +68,8 @@ var _ = Describe("Network", func() {
Expect(err).To(BeNil())
})
It("should configure networking with multus", func() {
podNICFactory = func(network *v1.Network, cacheFactory cache.InterfaceCacheFactory) (podNIC, error) {
return mockpodNIC, nil
podNICFactory = func(cacheFactory cache.InterfaceCacheFactory) podNIC {
return mockpodNIC
}
const multusInterfaceName = "net1"
vm := newVMIBridgeInterface("testnamespace", "testVmName")
Expand All @@ -87,8 +87,8 @@ var _ = Describe("Network", func() {
Expect(err).To(BeNil())
})
It("should configure networking with multus and a default multus network", func() {
podNICFactory = func(network *v1.Network, cacheFactory cache.InterfaceCacheFactory) (podNIC, error) {
return mockpodNIC, nil
podNICFactory = func(cacheFactory cache.InterfaceCacheFactory) podNIC {
return mockpodNIC
}

vm := newVMIBridgeInterface("testnamespace", "testVmName")
Expand Down

0 comments on commit 995acd5

Please sign in to comment.