mirror of
https://github.com/containers/podman.git
synced 2025-06-26 12:56:45 +08:00
Merge pull request #11806 from giuseppe/play-kube-fix-cpu-limits
kube: fix conversion from milliCPU to period/quota
This commit is contained in:
@ -160,7 +160,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
|
|||||||
return nil, errors.Wrap(err, "Failed to set CPU quota")
|
return nil, errors.Wrap(err, "Failed to set CPU quota")
|
||||||
}
|
}
|
||||||
if milliCPU > 0 {
|
if milliCPU > 0 {
|
||||||
period, quota := util.CoresToPeriodAndQuota(float64(milliCPU) / 1000)
|
period, quota := util.CoresToPeriodAndQuota(float64(milliCPU))
|
||||||
s.ResourceLimits.CPU = &spec.LinuxCPU{
|
s.ResourceLimits.CPU = &spec.LinuxCPU{
|
||||||
Quota: "a,
|
Quota: "a,
|
||||||
Period: &period,
|
Period: &period,
|
||||||
|
@ -2320,6 +2320,39 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`})
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman play kube allows setting resource limits with --cpus 1", func() {
|
||||||
|
SkipIfContainerized("Resource limits require a running systemd")
|
||||||
|
SkipIfRootless("CPU limits require root")
|
||||||
|
podmanTest.CgroupManager = "systemd"
|
||||||
|
|
||||||
|
var (
|
||||||
|
expectedCpuLimit string = "1"
|
||||||
|
)
|
||||||
|
|
||||||
|
deployment := getDeployment(
|
||||||
|
withPod(getPod(withCtr(getCtr(
|
||||||
|
withCpuLimit(expectedCpuLimit),
|
||||||
|
)))))
|
||||||
|
err := generateKubeYaml("deployment", deployment, kubeYaml)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
|
||||||
|
kube.WaitWithDefaultTimeout()
|
||||||
|
Expect(kube).Should(Exit(0))
|
||||||
|
|
||||||
|
for _, pod := range getPodNamesInDeployment(deployment) {
|
||||||
|
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(&pod), "--format", `{{ .HostConfig.CpuPeriod }}:{{ .HostConfig.CpuQuota }}`})
|
||||||
|
|
||||||
|
inspect.WaitWithDefaultTimeout()
|
||||||
|
Expect(inspect).Should(Exit(0))
|
||||||
|
|
||||||
|
parts := strings.Split(strings.Trim(inspect.OutputToString(), "\n"), ":")
|
||||||
|
Expect(parts).To(HaveLen(2))
|
||||||
|
|
||||||
|
Expect(parts[0]).To(Equal(parts[1]))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
It("podman play kube reports invalid image name", func() {
|
It("podman play kube reports invalid image name", func() {
|
||||||
invalidImageName := "./myimage"
|
invalidImageName := "./myimage"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user