Skip to content

Commit

Permalink
Merge pull request kubevirt#13708 from orelmisan/report-link-state
Browse files Browse the repository at this point in the history
virt-handler, netstat: Report interfaces' link state
  • Loading branch information
kubevirt-bot authored Jan 23, 2025
2 parents ab298fb + 4d88730 commit 7d17efc
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 19 deletions.
4 changes: 4 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -16898,6 +16898,10 @@
"default": ""
}
},
"linkState": {
"description": "LinkState Reports the current operational link state`. values: up, down.",
"type": "string"
},
"mac": {
"description": "Hardware address of a Virtual Machine interface",
"type": "string"
Expand Down
11 changes: 11 additions & 0 deletions pkg/network/setup/netstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func ifacesStatusFromDomainInterfaces(domainSpecIfaces []api.Interface) []v1.Vir
MAC: domainSpecIface.MAC.MAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: domainInterfaceQueues(domainSpecIface.Driver),
LinkState: linkStateFromDomain(domainSpecIface.LinkState),
})
}
return vmiStatusIfaces
Expand All @@ -291,6 +292,16 @@ func domainInterfaceQueues(driver *api.InterfaceDriver) int32 {
return DefaultInterfaceQueueCount
}

func linkStateFromDomain(linkState *api.LinkState) string {
const linkStateUp = "up"

if linkState == nil {
return linkStateUp
}

return linkState.State
}

func sriovIfacesStatusFromDomainHostDevices(hostDevices []api.HostDevice, vmiIfacesSpecByName map[string]v1.Interface) []v1.VirtualMachineInstanceNetworkInterface {
var vmiStatusIfaces []v1.VirtualMachineInstanceNetworkInterface

Expand Down
63 changes: 63 additions & 0 deletions pkg/network/setup/netstat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
var _ = Describe("netstat", func() {
var setup testSetup

const linkStateUp = "up"

BeforeEach(func() {
setup = newTestSetup()
})
Expand Down Expand Up @@ -116,13 +118,15 @@ var _ = Describe("netstat", func() {
IPs: []string{primaryPodIPv4, primaryPodIPv6},
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: secondaryNetworkName,
IP: secondaryPodIPv4,
IPs: []string{secondaryPodIPv4, secondaryPodIPv6},
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}), "the pod IP/s should be reported in the status")

Expand Down Expand Up @@ -153,6 +157,7 @@ var _ = Describe("netstat", func() {
IPs: []string{primaryPodIPv4, primaryPodIPv6},
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: int32(queueCount),
LinkState: linkStateUp,
},
}), "queue count and the pod IP/s should be reported in the status")

Expand Down Expand Up @@ -195,13 +200,15 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: netvmispec.InfoSourceDomainAndGA,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: secondaryNetworkName,
InterfaceName: secondaryIfaceName,
MAC: secondaryMAC,
InfoSource: netvmispec.InfoSourceDomainAndGA,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}), "the pod & guest-agent IP/s should be reported in the status")

Expand Down Expand Up @@ -233,6 +240,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: netvmispec.InfoSourceDomainAndGA,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}), "the guest-agent IP/s should be reported in the status")

Expand Down Expand Up @@ -284,6 +292,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: infoSourceDomainGAMultus,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: secondaryNetworkName,
Expand All @@ -293,6 +302,7 @@ var _ = Describe("netstat", func() {
MAC: secondaryMAC,
InfoSource: infoSourceDomainGAMultus,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}), "the pod IP/s should be reported in the status")

Expand Down Expand Up @@ -332,6 +342,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: netvmispec.InfoSourceDomainAndGA,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}), "the pod IP/s should be reported in the status")

Expand Down Expand Up @@ -372,6 +383,7 @@ var _ = Describe("netstat", func() {
MAC: newDomainMAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}), "the pod IP/s should be reported in the status")
})
Expand Down Expand Up @@ -441,6 +453,7 @@ var _ = Describe("netstat", func() {
MAC: origMAC,
InfoSource: netvmispec.InfoSourceDomainAndGA,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}), "the pod IP/s should be reported in the status")
})
Expand Down Expand Up @@ -502,6 +515,7 @@ var _ = Describe("netstat", func() {
IPs: []string{primaryPodIPv4},
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: networkName,
Expand Down Expand Up @@ -597,6 +611,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: secondaryNetworkName,
Expand All @@ -605,6 +620,7 @@ var _ = Describe("netstat", func() {
MAC: secondaryMAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: "",
Expand Down Expand Up @@ -649,6 +665,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: netvmispec.InfoSourceDomainAndGA,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: secondaryNetworkName,
Expand All @@ -658,6 +675,7 @@ var _ = Describe("netstat", func() {
MAC: secondaryMAC,
InfoSource: netvmispec.InfoSourceDomainAndGA,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: "",
Expand All @@ -682,6 +700,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: secondaryNetworkName,
Expand All @@ -690,6 +709,7 @@ var _ = Describe("netstat", func() {
MAC: secondaryMAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}))
})
Expand Down Expand Up @@ -726,6 +746,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}))
})
Expand Down Expand Up @@ -757,6 +778,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: netvmispec.InfoSourceDomainAndGA,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}))
})
Expand Down Expand Up @@ -821,6 +843,7 @@ var _ = Describe("netstat", func() {
MAC: MAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: secNetworkName1,
Expand All @@ -829,6 +852,7 @@ var _ = Describe("netstat", func() {
MAC: MAC1,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: secNetworkName2,
Expand All @@ -837,6 +861,7 @@ var _ = Describe("netstat", func() {
MAC: MAC2,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}))
},
Expand Down Expand Up @@ -890,6 +915,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: infoSourceDomainGAMultus,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
{
Name: secondaryNetworkName,
Expand Down Expand Up @@ -941,6 +967,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: infoSourceDomainGAMultus,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}), "only primary should exist in status since secondary iface not exist in spec")
})
Expand Down Expand Up @@ -987,6 +1014,7 @@ var _ = Describe("netstat", func() {
MAC: primaryMAC,
InfoSource: infoSourceDomainGA,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}))
})
Expand Down Expand Up @@ -1023,6 +1051,39 @@ var _ = Describe("netstat", func() {
}))
})

Context("Link state", func() {
const (
linkStateUp = "up"
linkStateDown = "down"
)
DescribeTable("should report correct link state", func(linkState string) {
const (
networkName = "primary"
MAC = "1C:CE:C0:01:BE:E7"
)

domainIface := newDomainSpecIface(networkName, MAC)
domainIface.LinkState = &api.LinkState{State: linkState}

setup.Domain.Spec.Devices.Interfaces = append(setup.Domain.Spec.Devices.Interfaces, domainIface)

Expect(setup.NetStat.UpdateStatus(setup.Vmi, setup.Domain)).To(Succeed())

Expect(setup.Vmi.Status.Interfaces).To(Equal([]v1.VirtualMachineInstanceNetworkInterface{
{
Name: networkName,
MAC: MAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkState,
},
}))
},
Entry("When link state is explicitly set to up", linkStateUp),
Entry("When link state is explicitly set to down", linkStateDown),
)
})

Context("misc scenario", func() {
const (
networkName = "primary"
Expand All @@ -1040,6 +1101,7 @@ var _ = Describe("netstat", func() {
MAC: MAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}))
})
Expand All @@ -1066,6 +1128,7 @@ var _ = Describe("netstat", func() {
MAC: MAC,
InfoSource: netvmispec.InfoSourceDomain,
QueueCount: netsetup.DefaultInterfaceQueueCount,
LinkState: linkStateUp,
},
}))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13314,6 +13314,10 @@ var CRDsValidation map[string]string = map[string]string{
items:
type: string
type: array
linkState:
description: 'LinkState Reports the current operational link state''.
values: up, down.'
type: string
mac:
description: Hardware address of a Virtual Machine interface
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,8 @@
"podInterfaceName": "podInterfaceNameValue",
"interfaceName": "interfaceNameValue",
"infoSource": "infoSourceValue",
"queueCount": -10
"queueCount": -10,
"linkState": "linkStateValue"
}
],
"guestOSInfo": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ status:
ipAddress: ipAddressValue
ipAddresses:
- ipAddressesValue
linkState: linkStateValue
mac: macValue
name: nameValue
podInterfaceName: podInterfaceNameValue
Expand Down
2 changes: 2 additions & 0 deletions staging/src/kubevirt.io/api/core/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ type VirtualMachineInstanceNetworkInterface struct {
InfoSource string `json:"infoSource,omitempty"`
// Specifies how many queues are allocated by MultiQueue
QueueCount int32 `json:"queueCount,omitempty"`
// LinkState Reports the current operational link state`. values: up, down.
LinkState string `json:"linkState,omitempty"`
}

type VirtualMachineInstanceGuestOSInfo struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions staging/src/kubevirt.io/client-go/api/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d17efc

Please sign in to comment.