Merge pull request #11806 from giuseppe/play-kube-fix-cpu-limits

kube: fix conversion from milliCPU to period/quota
This commit is contained in:
OpenShift Merge Robot 2021-09-30 13:34:52 -04:00 committed by GitHub
commit 16b9b51ae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -160,7 +160,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
return nil, errors.Wrap(err, "Failed to set CPU quota")
}
if milliCPU > 0 {
period, quota := util.CoresToPeriodAndQuota(float64(milliCPU) / 1000)
period, quota := util.CoresToPeriodAndQuota(float64(milliCPU))
s.ResourceLimits.CPU = &spec.LinuxCPU{
Quota: &quota,
Period: &period,

View File

@ -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() {
invalidImageName := "./myimage"