Skip to content

Commit

Permalink
virt-controller, template: export init container resource generation …
Browse files Browse the repository at this point in the history
…to a func

Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Jul 19, 2022
1 parent b20703f commit 235955e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
35 changes: 35 additions & 0 deletions pkg/virt-controller/services/renderresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,38 @@ func sidecarResources(vmi *v1.VirtualMachineInstance) k8sv1.ResourceRequirements
}
return resources
}

func initContainerResourceRequirementsForVMI(vmi *v1.VirtualMachineInstance) k8sv1.ResourceRequirements {
if vmi.IsCPUDedicated() || vmi.WantsToHaveQOSGuaranteed() {
return k8sv1.ResourceRequirements{
Limits: initContainerDedicatedCPURequiredResources(),
Requests: initContainerDedicatedCPURequiredResources(),
}
} else {
return k8sv1.ResourceRequirements{
Limits: initContainerMinimalLimits(),
Requests: initContainerMinimalRequests(),
}
}
}

func initContainerDedicatedCPURequiredResources() k8sv1.ResourceList {
return k8sv1.ResourceList{
k8sv1.ResourceCPU: resource.MustParse("10m"),
k8sv1.ResourceMemory: resource.MustParse("40M"),
}
}

func initContainerMinimalLimits() k8sv1.ResourceList {
return k8sv1.ResourceList{
k8sv1.ResourceCPU: resource.MustParse("100m"),
k8sv1.ResourceMemory: resource.MustParse("40M"),
}
}

func initContainerMinimalRequests() k8sv1.ResourceList {
return k8sv1.ResourceList{
k8sv1.ResourceCPU: resource.MustParse("10m"),
k8sv1.ResourceMemory: resource.MustParse("1M"),
}
}
18 changes: 1 addition & 17 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,22 +603,6 @@ func (t *templateService) renderLaunchManifest(vmi *v1.VirtualMachineInstance, i
var initContainers []k8sv1.Container

if HaveContainerDiskVolume(vmi.Spec.Volumes) || util.HasKernelBootContainerImage(vmi) {
initContainerResources := k8sv1.ResourceRequirements{}
if vmi.IsCPUDedicated() || vmi.WantsToHaveQOSGuaranteed() {
initContainerResources.Limits = make(k8sv1.ResourceList)
initContainerResources.Limits[k8sv1.ResourceCPU] = resource.MustParse("10m")
initContainerResources.Limits[k8sv1.ResourceMemory] = resource.MustParse("40M")
initContainerResources.Requests = make(k8sv1.ResourceList)
initContainerResources.Requests[k8sv1.ResourceCPU] = resource.MustParse("10m")
initContainerResources.Requests[k8sv1.ResourceMemory] = resource.MustParse("40M")
} else {
initContainerResources.Limits = make(k8sv1.ResourceList)
initContainerResources.Limits[k8sv1.ResourceCPU] = resource.MustParse("100m")
initContainerResources.Limits[k8sv1.ResourceMemory] = resource.MustParse("40M")
initContainerResources.Requests = make(k8sv1.ResourceList)
initContainerResources.Requests[k8sv1.ResourceCPU] = resource.MustParse("10m")
initContainerResources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1M")
}
initContainerCommand := []string{"/usr/bin/cp",
"/usr/bin/container-disk",
"/init/usr/bin/container-disk",
Expand All @@ -628,7 +612,7 @@ func (t *templateService) renderLaunchManifest(vmi *v1.VirtualMachineInstance, i
initContainers,
t.newInitContainerRenderer(vmi,
initContainerVolumeMount(),
initContainerResources,
initContainerResourceRequirementsForVMI(vmi),
userId).Render(initContainerCommand))

// this causes containerDisks to be pre-pulled before virt-launcher starts.
Expand Down

0 comments on commit 235955e

Please sign in to comment.