Skip to content

Commit

Permalink
kube: fix conversion from milliCPU to period/quota
Browse files Browse the repository at this point in the history
Closes: containers#11803

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Sep 30, 2021
1 parent 39d27cc commit 9c6c981
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/specgen/generate/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &quota,
Period: &period,
Expand Down
33 changes: 33 additions & 0 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 9c6c981

Please sign in to comment.