Skip to content

Commit

Permalink
virt-controller, template: export sidecar resource generation to a func
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Jul 19, 2022
1 parent ea1fcb4 commit b20703f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 12 additions & 0 deletions pkg/virt-controller/services/renderresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,15 @@ func validatePermittedHostDevices(spec *v1.VirtualMachineInstanceSpec, config *v

return nil
}

func sidecarResources(vmi *v1.VirtualMachineInstance) k8sv1.ResourceRequirements {
resources := k8sv1.ResourceRequirements{}
// add default cpu and memory limits to enable cpu pinning if requested
// TODO(vladikr): make the hookSidecar express resources
if vmi.IsCPUDedicated() || vmi.WantsToHaveQOSGuaranteed() {
resources.Limits = make(k8sv1.ResourceList)
resources.Limits[k8sv1.ResourceCPU] = resource.MustParse("200m")
resources.Limits[k8sv1.ResourceMemory] = resource.MustParse("64M")
}
return resources
}
11 changes: 1 addition & 10 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,19 +585,10 @@ func (t *templateService) renderLaunchManifest(vmi *v1.VirtualMachineInstance, i
podLabels[v1.VirtualMachineNameLabel] = hostName

for i, requestedHookSidecar := range requestedHookSidecarList {
resources := k8sv1.ResourceRequirements{}
// add default cpu and memory limits to enable cpu pinning if requested
// TODO(vladikr): make the hookSidecar express resources
if vmi.IsCPUDedicated() || vmi.WantsToHaveQOSGuaranteed() {
resources.Limits = make(k8sv1.ResourceList)
resources.Limits[k8sv1.ResourceCPU] = resource.MustParse("200m")
resources.Limits[k8sv1.ResourceMemory] = resource.MustParse("64M")
}

containers = append(
containers,
newSidecarContainerRenderer(
sidecarContainerName(i), vmi, resources, requestedHookSidecar, userId).Render(requestedHookSidecar.Command))
sidecarContainerName(i), vmi, sidecarResources(vmi), requestedHookSidecar, userId).Render(requestedHookSidecar.Command))
}

podAnnotations, err := generatePodAnnotations(vmi)
Expand Down

0 comments on commit b20703f

Please sign in to comment.