Skip to content

Commit

Permalink
chore(qrm): nic allocation reactor use allocation identifier instead
Browse files Browse the repository at this point in the history
  • Loading branch information
luomingmeng committed Feb 5, 2025
1 parent 683ae8b commit 793197b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
12 changes: 8 additions & 4 deletions pkg/agent/qrm-plugins/network/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import (
type AllocationInfo struct {
commonstate.AllocationMeta `json:",inline"`

Egress uint32 `json:"egress"`
Ingress uint32 `json:"ingress"`
IfName string `json:"if_name"` // we do not support cross-nic bandwidth
NumaNodes machine.CPUSet `json:"numa_node"` // associated numa nodes of the socket connecting to the selected NIC
Egress uint32 `json:"egress"`
Ingress uint32 `json:"ingress"`
Identifier string `json:"identifier"`
IfNSName string `json:"if_ns_name"`
IfName string `json:"if_name"` // we do not support cross-nic bandwidth
NumaNodes machine.CPUSet `json:"numa_node"` // associated numa nodes of the socket connecting to the selected NIC
}

type (
Expand Down Expand Up @@ -89,6 +91,8 @@ func (ai *AllocationInfo) Clone() *AllocationInfo {
AllocationMeta: *ai.AllocationMeta.Clone(),
Egress: ai.Egress,
Ingress: ai.Ingress,
Identifier: ai.Identifier,
IfNSName: ai.IfNSName,
IfName: ai.IfName,
NumaNodes: ai.NumaNodes.Clone(),
}
Expand Down
18 changes: 13 additions & 5 deletions pkg/agent/qrm-plugins/network/staticpolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ func (p *StaticPolicy) GetTopologyAwareResources(_ context.Context,
}

nic := p.getNICByName(allocationInfo.IfName)
identifier := allocationInfo.Identifier
if identifier == "" {
// backup to use ifName and nic.NSName as identifier
identifier = getResourceIdentifier(nic.NSName, nic.Iface)
}

topologyAwareQuantityList := []*pluginapi.TopologyAwareQuantity{
{
ResourceValue: float64(allocationInfo.Egress),
Expand All @@ -389,7 +395,7 @@ func (p *StaticPolicy) GetTopologyAwareResources(_ context.Context,
Type: string(apinode.TopologyTypeNIC),
TopologyLevel: pluginapi.TopologyLevel_SOCKET,
Annotations: map[string]string{
apiconsts.ResourceAnnotationKeyResourceIdentifier: getResourceIdentifier(nic.NSName, allocationInfo.IfName),
apiconsts.ResourceAnnotationKeyResourceIdentifier: allocationInfo.Identifier,
apiconsts.ResourceAnnotationKeyNICNetNSName: nic.NSName,
},
},
Expand Down Expand Up @@ -656,10 +662,12 @@ func (p *StaticPolicy) Allocate(ctx context.Context,
newAllocation := &state.AllocationInfo{
AllocationMeta: commonstate.GenerateGenericContainerAllocationMeta(req,
commonstate.EmptyOwnerPoolName, qosLevel),
Egress: uint32(reqInt),
Ingress: uint32(reqInt),
IfName: selectedNIC.Iface,
NumaNodes: siblingNUMAs,
Egress: uint32(reqInt),
Ingress: uint32(reqInt),
Identifier: getResourceIdentifier(selectedNIC.NSName, selectedNIC.Iface),
IfNSName: selectedNIC.NSName,
IfName: selectedNIC.Iface,
NumaNodes: siblingNUMAs,
}

resourceAllocationAnnotations, err := p.getResourceAllocationAnnotations(podAnnotations, newAllocation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (p nicPodAllocationWrapper) UpdateAllocation(pod *v1.Pod) error {
annotations = make(map[string]string)
}

annotations[apiconsts.PodAnnotationNICSelectionResultKey] = p.AllocationInfo.IfName
annotations[apiconsts.PodAnnotationNICSelectionResultKey] = p.AllocationInfo.Identifier
pod.SetAnnotations(annotations)

return nil
Expand Down

0 comments on commit 793197b

Please sign in to comment.