Skip to content

Commit

Permalink
fix(qrm-plugins): populate sidecar container annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-lgy committed Feb 25, 2025
1 parent 8168777 commit 1451f23
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
8 changes: 8 additions & 0 deletions pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,14 @@ func (p *DynamicPolicy) applySidecarAllocationInfoFromMainContainer(sidecarAlloc
changed = true
}

// Copy missing annotations from main container
for key, value := range mainAllocationInfo.Annotations {
if _, ok := sidecarAllocationInfo.Annotations[key]; !ok {
sidecarAllocationInfo.Annotations[key] = value
changed = true
}
}

request := p.getContainerRequestedCores(sidecarAllocationInfo)
if sidecarAllocationInfo.RequestQuantity != request {
sidecarAllocationInfo.RequestQuantity = request
Expand Down
42 changes: 27 additions & 15 deletions pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_advisor_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,30 +249,42 @@ func (p *DynamicPolicy) createGetAdviceRequest() (*advisorapi.GetAdviceRequest,
},
}

// Only fill in the container type for non-pool entries.
if entryName != commonstate.FakedContainerName {
if !containerEntries.IsPoolEntry() {
// Only fill in the container type for non-pool entries.
containerType, found := pluginapi.ContainerType_value[allocationInfo.ContainerType]
if !found {
return nil, fmt.Errorf("container type %q for container %s/%s not found", allocationInfo.ContainerType, uid, entryName)
}

info.Metadata.ContainerType = pluginapi.ContainerType(containerType)
}

ownerPoolName := allocationInfo.GetOwnerPoolName()
if ownerPoolName == commonstate.EmptyOwnerPoolName {
general.Warningf("pod: %s/%s container: %s get empty owner pool name",
allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName)
if allocationInfo.CheckSideCar() {
ownerPoolName = containerEntries.GetMainContainerPoolName()
ownerPoolName := allocationInfo.GetOwnerPoolName()
if ownerPoolName == commonstate.EmptyOwnerPoolName {
general.Warningf("pod: %s/%s container: %s get empty owner pool name",
allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName)
if allocationInfo.CheckSideCar() {
ownerPoolName = containerEntries.GetMainContainerPoolName()

general.Warningf("set pod: %s/%s sidecar container: %s owner pool name: %s same to its main container",
allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName,
ownerPoolName)
general.Warningf("set pod: %s/%s sidecar container: %s owner pool name: %s same to its main container",
allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName,
ownerPoolName)
}
}
}
info.AllocationInfo.OwnerPoolName = ownerPoolName

info.AllocationInfo.OwnerPoolName = ownerPoolName
// Copy annotations missing in sidecar container from main container.
// This should have been done during sidecar allocation, but we do it again here
// to ensure backward compatibility with checkpoint written by older versions of the plugin.
if allocationInfo.CheckSideCar() {
mainContainerInfo := containerEntries.GetMainContainerEntry()
if mainContainerInfo != nil {
for key, value := range mainContainerInfo.Annotations {
if _, ok := info.Metadata.Annotations[key]; !ok {
info.Metadata.Annotations[key] = value
}
}
}
}
}

// not set topology-aware assignments for shared_cores,
// since their topology-aware assignments are same to the pools they are in.
Expand Down

0 comments on commit 1451f23

Please sign in to comment.