Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/network/deviceinfo/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@

package deviceinfo

const SRIOVAliasPrefix = "sriov-"
const (
SRIOVAliasPrefix = "sriov-"
DraSRIOVAliasPrefix = "dra-sriov-"
)
4 changes: 4 additions & 0 deletions pkg/virt-config/feature-gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ func (config *ClusterConfig) HostDevicesWithDRAEnabled() bool {
return config.isFeatureGateEnabled(featuregate.HostDevicesWithDRAGate)
}

func (config *ClusterConfig) NetworkDevicesWithDRAEnabled() bool {
return config.isFeatureGateEnabled(featuregate.NetworkDevicesWithDRAGate)
}

func (config *ClusterConfig) ConfigurableHypervisorEnabled() bool {
return config.isFeatureGateEnabled(featuregate.ConfigurableHypervisor)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/virt-config/featuregate/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ const (
// HostDevicesWithDRAGate allows users to create VMIs with DRA provisioned Host devices
HostDevicesWithDRAGate = "HostDevicesWithDRA"

// Owner: @alaypatel07
// Alpha: v1.6.0
//
// NetworkDevicesWithDRAGate allows users to create VMIs with DRA provisioned SR-IOV network devices
NetworkDevicesWithDRAGate = "NetworkDevicesWithDRA"

DecentralizedLiveMigration = "DecentralizedLiveMigration"

// Owner: sig-storage / @alromeros
Expand Down Expand Up @@ -198,6 +204,7 @@ func init() {
RegisterFeatureGate(FeatureGate{Name: VirtIOFSStorageVolumeGate, State: Alpha})
RegisterFeatureGate(FeatureGate{Name: GPUsWithDRAGate, State: Alpha})
RegisterFeatureGate(FeatureGate{Name: HostDevicesWithDRAGate, State: Alpha})
RegisterFeatureGate(FeatureGate{Name: NetworkDevicesWithDRAGate, State: Alpha})
RegisterFeatureGate(FeatureGate{Name: DecentralizedLiveMigration, State: Alpha})
RegisterFeatureGate(FeatureGate{Name: DeclarativeHotplugVolumesGate, State: Alpha})
RegisterFeatureGate(FeatureGate{Name: SecureExecution, State: Beta})
Expand Down
59 changes: 59 additions & 0 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,62 @@ func generateQemuTimeoutWithJitter(qemuTimeoutBaseSeconds int) string {
return fmt.Sprintf("%ds", timeout)
}

// renderNetworkResourceClaims adds network DRA resource claims to pod spec
func renderNetworkResourceClaims(vmi *v1.VirtualMachineInstance, pod *k8sv1.Pod, clusterConfig *virtconfig.ClusterConfig) {
if !clusterConfig.NetworkDevicesWithDRAEnabled() {
return
}

if len(vmi.Spec.Networks) == 0 {
return
}

// Collect unique claim names referenced by networks
networkClaimNames := make(map[string]bool)
for _, network := range vmi.Spec.Networks {
if network.ResourceClaim != nil {
if network.ResourceClaim.ClaimName != nil {
networkClaimNames[*network.ResourceClaim.ClaimName] = true
}
}
}

if len(networkClaimNames) == 0 {
return
}

// Note: pod.Spec.ResourceClaims is already populated from vmi.Spec.ResourceClaims at pod creation time (line 735)
// We only need to add container-level references here

// Add resource claims to container resources
if pod.Spec.Containers == nil || len(pod.Spec.Containers) == 0 {
return
}

// Find compute container
for i := range pod.Spec.Containers {
if pod.Spec.Containers[i].Name == "compute" {
if pod.Spec.Containers[i].Resources.Claims == nil {
pod.Spec.Containers[i].Resources.Claims = []k8sv1.ResourceClaim{}
}

// Add claim references to container
for _, network := range vmi.Spec.Networks {
if network.ResourceClaim != nil && network.ResourceClaim.ClaimName != nil && network.ResourceClaim.RequestName != nil {
pod.Spec.Containers[i].Resources.Claims = append(
pod.Spec.Containers[i].Resources.Claims,
k8sv1.ResourceClaim{
Name: *network.ResourceClaim.ClaimName,
Request: *network.ResourceClaim.RequestName,
},
)
}
}
break
}
}
}

func computePodSecurityContext(vmi *v1.VirtualMachineInstance, seccomp *k8sv1.SeccompProfile) *k8sv1.PodSecurityContext {
psc := &k8sv1.PodSecurityContext{}

Expand Down Expand Up @@ -696,6 +752,9 @@ func (t *TemplateService) renderLaunchManifest(vmi *v1.VirtualMachineInstance, i

pod.Spec.Volumes = append(pod.Spec.Volumes, sidecarVolumes...)

// Add network resource claims to pod
renderNetworkResourceClaims(vmi, &pod, t.clusterConfig)

return &pod, nil
}

Expand Down
84 changes: 84 additions & 0 deletions pkg/virt-controller/watch/dra/dra.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,23 @@ func (c *DRAStatusController) updateStatus(logger *log.FilteredLogger, vmi *v1.V
}
}

// Sync network devices (they use hostDeviceStatuses array)
if c.clusterConfig.NetworkDevicesWithDRAEnabled() {
networkDeviceInfo, err := c.getNetworkDevicesFromVMISpec(vmi)
if err != nil {
return err
}

if len(networkDeviceInfo) > 0 {
networkDeviceStatuses, err := c.getNetworkDeviceStatuses(networkDeviceInfo, pod)
if err != nil {
return err
}
// Append network statuses to hostDeviceStatuses
hostDeviceStatuses = append(hostDeviceStatuses, networkDeviceStatuses...)
}
}

newDeviceStatus := &v1.DeviceStatus{}
if gpuStatuses != nil {
newDeviceStatus.GPUStatuses = gpuStatuses
Expand Down Expand Up @@ -709,3 +726,70 @@ func (c *DRAStatusController) getHostDeviceStatus(hostDeviceInfo DeviceInfo, pod

return hostDeviceStatus, nil
}

func (c *DRAStatusController) getNetworkDevicesFromVMISpec(vmi *v1.VirtualMachineInstance) ([]DeviceInfo, error) {
var networkDevices []DeviceInfo
for _, network := range vmi.Spec.Networks {
if network.ResourceClaim == nil {
continue
}
if network.ResourceClaim.ClaimName == nil || network.ResourceClaim.RequestName == nil {
continue
}
networkDevices = append(networkDevices, DeviceInfo{
VMISpecClaimName: *network.ResourceClaim.ClaimName,
VMISpecRequestName: *network.ResourceClaim.RequestName,
DeviceStatusInfo: &v1.DeviceStatusInfo{
Name: network.Name,
DeviceResourceClaimStatus: nil,
},
})
}
return networkDevices, nil
}

func (c *DRAStatusController) getNetworkDeviceStatuses(networkDeviceInfos []DeviceInfo, pod *k8sv1.Pod) ([]v1.DeviceStatusInfo, error) {
statuses := make([]v1.DeviceStatusInfo, 0, len(networkDeviceInfos))
for _, info := range networkDeviceInfos {
st, err := c.getNetworkDeviceStatus(info, pod)
if err != nil {
return nil, err
}
statuses = append(statuses, st)
}
return statuses, nil
}

func (c *DRAStatusController) getNetworkDeviceStatus(networkDeviceInfo DeviceInfo, pod *k8sv1.Pod) (v1.DeviceStatusInfo, error) {
networkDeviceStatus := v1.DeviceStatusInfo{
Name: networkDeviceInfo.Name,
DeviceResourceClaimStatus: &v1.DeviceResourceClaimStatus{
ResourceClaimName: getResourceClaimNameForDevice(networkDeviceInfo.VMISpecClaimName, pod),
},
}

if networkDeviceStatus.DeviceResourceClaimStatus.ResourceClaimName == nil {
return networkDeviceStatus, nil
}

device, err := c.getAllocatedDevice(pod.Namespace, *networkDeviceStatus.DeviceResourceClaimStatus.ResourceClaimName, networkDeviceInfo.VMISpecRequestName)
if err != nil {
return networkDeviceStatus, err
}
if device == nil {
return networkDeviceStatus, nil
}

networkDeviceStatus.DeviceResourceClaimStatus.Name = &device.Device
pciAddress, _, err := c.getDeviceAttributes(pod.Spec.NodeName, device.Device, device.Driver)
if err != nil {
return networkDeviceStatus, err
}
attrs := v1.DeviceAttribute{}
if pciAddress != "" {
attrs.PCIAddress = &pciAddress
}
networkDeviceStatus.DeviceResourceClaimStatus.Attributes = &attrs

return networkDeviceStatus, nil
}
Loading