From 9c6c981928c3e020ff6eef9454c7ee86aa8c83d1 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 30 Sep 2021 15:22:47 +0200 Subject: [PATCH] kube: fix conversion from milliCPU to period/quota Closes: https://github.com/containers/podman/issues/11803 Signed-off-by: Giuseppe Scrivano --- pkg/specgen/generate/kube/kube.go | 2 +- test/e2e/play_kube_test.go | 33 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go index c01d7a1f01..2dd0f56479 100644 --- a/pkg/specgen/generate/kube/kube.go +++ b/pkg/specgen/generate/kube/kube.go @@ -157,7 +157,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: "a, Period: &period, diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 0d5b9d52c2..83ce751e6d 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -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"