Skip to content

Commit

Permalink
network: rename constant to primaryPodInterfaceName
Browse files Browse the repository at this point in the history
eth0 is just the name of the primary interface passed to pods via
containernetworking.

Signed-off-by: Dan Kenigsberg <[email protected]>
  • Loading branch information
dankenigsberg committed Jan 11, 2021
1 parent 52c0e91 commit 5df7749
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions pkg/virt-launcher/virtwrap/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"kubevirt.io/kubevirt/pkg/virt-launcher/virtwrap/api"
)

const podInterface = "eth0"
const primaryPodInterfaceName = "eth0"

var interfaceCacheFile = "/proc/%s/root/var/run/kubevirt-private/interface-cache-%s.json"
var qemuArgCacheFile = "/proc/%s/root/var/run/kubevirt-private/qemu-arg-%s.json"
Expand Down Expand Up @@ -100,7 +100,7 @@ func getPodInterfaceName(networks map[string]*v1.Network, cniNetworks map[string
// multus pod interfaces named netX
return fmt.Sprintf("net%d", cniNetworks[ifaceName])
} else {
return podInterface
return primaryPodInterfaceName
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-launcher/virtwrap/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var _ = Describe("Network", func() {
iface := v1.DefaultBridgeNetworkInterface()
defaultNet := v1.DefaultPodNetwork()

mockNetworkInterface.EXPECT().PlugPhase1(vm, iface, defaultNet, podInterface, pid)
mockNetworkInterface.EXPECT().PlugPhase1(vm, iface, defaultNet, primaryPodInterfaceName, pid)
err := SetupNetworkInterfacesPhase1(vm, pid)
Expect(err).To(BeNil())
})
Expand Down
66 changes: 33 additions & 33 deletions pkg/virt-launcher/virtwrap/network/podinterface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var _ = Describe("Pod Network", func() {

bridgeAddr, _ = netlink.ParseAddr(fmt.Sprintf(bridgeFakeIP, 0))
tapDeviceName = "tap0"
testNic = &VIF{Name: podInterface,
testNic = &VIF{Name: primaryPodInterfaceName,
IP: fakeAddr,
MAC: fakeMac,
Mtu: uint16(mtu),
Expand All @@ -139,7 +139,7 @@ var _ = Describe("Pod Network", func() {
masqueradeVmIpv6 = masqueradeIpv6VmAddr.IP.String()
masqueradeDummyName = fmt.Sprintf("%s-nic", api.DefaultBridgeName)
masqueradeDummy = &netlink.Dummy{LinkAttrs: netlink.LinkAttrs{Name: masqueradeDummyName, MTU: mtu}}
masqueradeTestNic = &VIF{Name: podInterface,
masqueradeTestNic = &VIF{Name: primaryPodInterfaceName,
IP: *masqueradeVmAddr,
IPv6: *masqueradeIpv6VmAddr,
MAC: fakeMac,
Expand Down Expand Up @@ -179,14 +179,14 @@ var _ = Describe("Pod Network", func() {
TestPodInterfaceIPBinding := func(vm *v1.VirtualMachineInstance, domain *api.Domain) {

//For Bridge tests
mockNetwork.EXPECT().LinkByName(podInterface).Return(dummy, nil).Times(2)
mockNetwork.EXPECT().LinkByName(primaryPodInterfaceName).Return(dummy, nil).Times(2)
mockNetwork.EXPECT().AddrList(dummy, netlink.FAMILY_V4).Return(addrList, nil)
mockNetwork.EXPECT().AddrList(dummy, netlink.FAMILY_ALL).Return(addrList, nil)
mockNetwork.EXPECT().RouteList(dummy, netlink.FAMILY_V4).Return(routeList, nil)
mockNetwork.EXPECT().GetMacDetails(podInterface).Return(fakeMac, nil)
mockNetwork.EXPECT().GetMacDetails(primaryPodInterfaceName).Return(fakeMac, nil)
mockNetwork.EXPECT().AddrDel(dummy, &fakeAddr).Return(nil)
mockNetwork.EXPECT().LinkSetDown(dummy).Return(nil)
mockNetwork.EXPECT().SetRandomMac(podInterface).Return(updateFakeMac, nil)
mockNetwork.EXPECT().SetRandomMac(primaryPodInterfaceName).Return(updateFakeMac, nil)
mockNetwork.EXPECT().LinkSetUp(dummy).Return(nil)
mockNetwork.EXPECT().LinkSetLearningOff(dummy).Return(nil)
mockNetwork.EXPECT().LinkAdd(bridgeTest).Return(nil)
Expand All @@ -201,7 +201,7 @@ var _ = Describe("Pod Network", func() {
mockNetwork.EXPECT().DisableTXOffloadChecksum(bridgeTest.Name).Return(nil)

// For masquerade tests
mockNetwork.EXPECT().LinkByName(podInterface).Return(dummy, nil)
mockNetwork.EXPECT().LinkByName(primaryPodInterfaceName).Return(dummy, nil)
mockNetwork.EXPECT().AddrList(dummy, netlink.FAMILY_ALL).Return(addrList, nil)
mockNetwork.EXPECT().ParseAddr(masqueradeGwStr).Return(masqueradeGwAddr, nil)
mockNetwork.EXPECT().ParseAddr(masqueradeIpv6GwStr).Return(masqueradeIpv6GwAddr, nil)
Expand Down Expand Up @@ -307,11 +307,11 @@ var _ = Describe("Pod Network", func() {

api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)

mockNetwork.EXPECT().LinkByName(podInterface).Return(dummy, nil)
mockNetwork.EXPECT().LinkByName(primaryPodInterfaceName).Return(dummy, nil)
mockNetwork.EXPECT().AddrList(dummy, netlink.FAMILY_ALL).Return(addrList, nil)
mockNetwork.EXPECT().LinkByName(podInterface).Return(dummy, nil)
mockNetwork.EXPECT().LinkByName(primaryPodInterfaceName).Return(dummy, nil)
mockNetwork.EXPECT().LinkSetDown(dummy).Return(nil)
mockNetwork.EXPECT().SetRandomMac(podInterface).Return(updateFakeMac, nil)
mockNetwork.EXPECT().SetRandomMac(primaryPodInterfaceName).Return(updateFakeMac, nil)
mockNetwork.EXPECT().AddrList(dummy, netlink.FAMILY_V4).Return(addrList, nil)
mockNetwork.EXPECT().LinkAdd(bridgeTest).Return(nil)
mockNetwork.EXPECT().LinkByName(api.DefaultBridgeName).Return(bridgeTest, nil)
Expand All @@ -320,7 +320,7 @@ var _ = Describe("Pod Network", func() {
mockNetwork.EXPECT().ParseAddr(fmt.Sprintf(bridgeFakeIP, 0)).Return(bridgeAddr, nil)
mockNetwork.EXPECT().AddrAdd(bridgeTest, bridgeAddr).Return(nil)
mockNetwork.EXPECT().RouteList(dummy, netlink.FAMILY_V4).Return(routeList, nil)
mockNetwork.EXPECT().GetMacDetails(podInterface).Return(fakeMac, nil)
mockNetwork.EXPECT().GetMacDetails(primaryPodInterfaceName).Return(fakeMac, nil)
mockNetwork.EXPECT().LinkSetMaster(dummy, bridgeTest).Return(nil)
mockNetwork.EXPECT().AddrDel(dummy, &fakeAddr).Return(errors.New("device is busy"))
mockNetwork.EXPECT().CreateTapDevice(tapDeviceName, queueNumber, pid, mtu).Return(nil)
Expand All @@ -342,10 +342,10 @@ var _ = Describe("Pod Network", func() {

api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)

mockNetwork.EXPECT().LinkByName(podInterface).Return(dummy, nil).Times(2)
mockNetwork.EXPECT().LinkByName(primaryPodInterfaceName).Return(dummy, nil).Times(2)
mockNetwork.EXPECT().AddrList(dummy, netlink.FAMILY_ALL).Return(addrList, nil)
mockNetwork.EXPECT().AddrList(dummy, netlink.FAMILY_V4).Return(addrList, nil)
mockNetwork.EXPECT().GetMacDetails(podInterface).Return(fakeMac, nil)
mockNetwork.EXPECT().GetMacDetails(primaryPodInterfaceName).Return(fakeMac, nil)
mockNetwork.EXPECT().IsIpv4Primary().Return(true, nil).Times(1)

err := SetupPodNetworkPhase1(vm, pid)
Expand Down Expand Up @@ -386,7 +386,7 @@ var _ = Describe("Pod Network", func() {
It("should populate MAC address", func() {
vmi := newVMIBridgeInterface("testnamespace", "testVmName")
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], podInterface)
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
bridge, ok := driver.(*BridgePodInterface)
Expect(ok).To(BeTrue())
Expand Down Expand Up @@ -423,7 +423,7 @@ var _ = Describe("Pod Network", func() {
for _, proto := range ipProtocols() {
mockNetwork.EXPECT().HasNatIptables(proto).Return(true).Times(2)
}
mockNetwork.EXPECT().IsIpv6Enabled(podInterface).Return(true, nil).Times(3)
mockNetwork.EXPECT().IsIpv6Enabled(primaryPodInterfaceName).Return(true, nil).Times(3)
mockNetwork.EXPECT().IsIpv4Primary().Return(true, nil).Times(1)

domain := NewDomainWithBridgeInterface()
Expand All @@ -434,7 +434,7 @@ var _ = Describe("Pod Network", func() {
})
It("should define a new VIF bind to a bridge and create a specific nat rule using iptables", func() {
// Forward a specific port
mockNetwork.EXPECT().IsIpv6Enabled(podInterface).Return(true, nil).Times(3)
mockNetwork.EXPECT().IsIpv6Enabled(primaryPodInterfaceName).Return(true, nil).Times(3)
mockNetwork.EXPECT().IsIpv4Primary().Return(true, nil).Times(1)

for _, proto := range ipProtocols() {
Expand Down Expand Up @@ -474,7 +474,7 @@ var _ = Describe("Pod Network", func() {
for _, proto := range ipProtocols() {
mockNetwork.EXPECT().HasNatIptables(proto).Return(true).Times(2)
}
mockNetwork.EXPECT().IsIpv6Enabled(podInterface).Return(true, nil).Times(3)
mockNetwork.EXPECT().IsIpv6Enabled(primaryPodInterfaceName).Return(true, nil).Times(3)
mockNetwork.EXPECT().IsIpv4Primary().Return(true, nil).Times(1)

domain := NewDomainWithBridgeInterface()
Expand All @@ -485,7 +485,7 @@ var _ = Describe("Pod Network", func() {
})
It("should define a new VIF bind to a bridge and create a specific nat rule using nftables", func() {
// Forward a specific port
mockNetwork.EXPECT().IsIpv6Enabled(podInterface).Return(true, nil).Times(3)
mockNetwork.EXPECT().IsIpv6Enabled(primaryPodInterfaceName).Return(true, nil).Times(3)
mockNetwork.EXPECT().IsIpv4Primary().Return(true, nil).Times(1)

for _, proto := range ipProtocols() {
Expand Down Expand Up @@ -529,7 +529,7 @@ var _ = Describe("Pod Network", func() {

api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)

driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, podInterface)
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
TestRunPlug(driver)
Expect(len(domain.Spec.Devices.Interfaces)).To(Equal(0))
Expand All @@ -544,7 +544,7 @@ var _ = Describe("Pod Network", func() {
api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"

driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, podInterface)
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
TestRunPlug(driver)
Expect(len(domain.Spec.Devices.Interfaces)).To(Equal(0))
Expand All @@ -570,7 +570,7 @@ var _ = Describe("Pod Network", func() {
Name: "default",
}})

driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, podInterface)
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
TestRunPlug(driver)
Expect(len(domain.Spec.Devices.Interfaces)).To(Equal(1))
Expand Down Expand Up @@ -606,7 +606,7 @@ var _ = Describe("Pod Network", func() {
vmi := newVMIMasqueradeInterface("testnamespace", "testVmName")
api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, podInterface)
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
masq, ok := driver.(*MasqueradePodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -623,7 +623,7 @@ var _ = Describe("Pod Network", func() {
vmi := newVMIMasqueradeInterface("testnamespace", "testVmName")
api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, podInterface)
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
masq, ok := driver.(*MasqueradePodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -644,7 +644,7 @@ var _ = Describe("Pod Network", func() {
vmi := newVMIBridgeInterface("testnamespace", "testVmName")
api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, podInterface)
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
bridge, ok := driver.(*BridgePodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -659,7 +659,7 @@ var _ = Describe("Pod Network", func() {
vmi := newVMIBridgeInterface("testnamespace", "testVmName")
api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, podInterface)
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
bridge, ok := driver.(*BridgePodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -675,7 +675,7 @@ var _ = Describe("Pod Network", func() {
vmi := newVMIBridgeInterface("testnamespace", "testVmName")
api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, podInterface)
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
bridge, ok := driver.(*BridgePodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -694,7 +694,7 @@ var _ = Describe("Pod Network", func() {
vmi := newVMISlirpInterface("testnamespace", "testVmName")
api.NewDefaulter(runtime.GOARCH).SetObjectDefaults_Domain(domain)

driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, podInterface)
driver, err := getPhase2Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], domain, primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
slirp, ok := driver.(*SlirpPodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -709,7 +709,7 @@ var _ = Describe("Pod Network", func() {
It("should fail when nothing to load", func() {
vmi := newVMIBridgeInterface("testnamespace", "testVmName")
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], podInterface)
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
bridge, ok := driver.(*BridgePodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -721,7 +721,7 @@ var _ = Describe("Pod Network", func() {
It("should succeed when cache file present", func() {
vmi := newVMIBridgeInterface("testnamespace", "testVmName")
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], podInterface)
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
bridge, ok := driver.(*BridgePodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -739,7 +739,7 @@ var _ = Describe("Pod Network", func() {
It("should succeed", func() {
vmi := newVMISlirpInterface("testnamespace", "testVmName")

driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], podInterface)
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
slirp, ok := driver.(*SlirpPodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -763,7 +763,7 @@ var _ = Describe("Pod Network", func() {
It("should fail when nothing to load", func() {
vmi := newVMIMasqueradeInterface("testnamespace", "testVmName")
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], podInterface)
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
masq, ok := driver.(*MasqueradePodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -775,7 +775,7 @@ var _ = Describe("Pod Network", func() {
It("should succeed when cache file present", func() {
vmi := newVMIMasqueradeInterface("testnamespace", "testVmName")
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de-ad-00-00-be-af"
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], podInterface)
driver, err := getPhase1Binding(vmi, &vmi.Spec.Domain.Devices.Interfaces[0], &vmi.Spec.Networks[0], primaryPodInterfaceName)
Expect(err).ToNot(HaveOccurred())
masq, ok := driver.(*MasqueradePodInterface)
Expect(ok).To(BeTrue())
Expand All @@ -800,11 +800,11 @@ var _ = Describe("Pod Network", func() {
Expect(err).ToNot(HaveOccurred())

iface := &v1.Interface{Name: "default", InterfaceBindingMethod: v1.InterfaceBindingMethod{Masquerade: &v1.InterfaceMasquerade{}}}
mockNetwork.EXPECT().LinkByName(podInterface).Return(dummy, nil)
mockNetwork.EXPECT().LinkByName(primaryPodInterfaceName).Return(dummy, nil)
mockNetwork.EXPECT().AddrList(dummy, netlink.FAMILY_ALL).Return(addrList, nil)
mockNetwork.EXPECT().IsIpv4Primary().Return(true, nil).Times(1)

err = setPodInterfaceCache(iface, podInterface, uid)
err = setPodInterfaceCache(iface, primaryPodInterfaceName, uid)
Expect(err).ToNot(HaveOccurred())

data, err := ioutil.ReadFile(fmt.Sprintf(util.VMIInterfacepath, uid, iface.Name))
Expand Down

0 comments on commit 5df7749

Please sign in to comment.