mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +08:00
Merge pull request #25645 from jankaluza/24418
Add support for --pids-limit in podman kube play.
This commit is contained in:
@ -55,6 +55,8 @@ by `podman kube play` to create them.
|
||||
|
||||
Note: To customize the name of the infra container created during `podman kube play`, use the **io.podman.annotations.infra.name** annotation in the pod definition. This annotation is automatically set when generating a kube yaml from a pod that was created with the `--infra-name` flag set.
|
||||
|
||||
Note: Use the **io.podman.annotations.pids-limit/$ctrname** annotation to configure the pod's pids limit.
|
||||
|
||||
`Kubernetes PersistentVolumeClaims`
|
||||
|
||||
A Kubernetes PersistentVolumeClaim represents a Podman named volume. Only the PersistentVolumeClaim name is required by Podman to create a volume. Kubernetes annotations can be used to make use of the available options for Podman volumes.
|
||||
|
@ -169,6 +169,9 @@ const (
|
||||
// KubeImageAutomountAnnotation
|
||||
KubeImageAutomountAnnotation = "io.podman.annotations.kube.image.volumes.mount"
|
||||
|
||||
// PIDsLimitAnnotation is used to limit the number of PIDs
|
||||
PIDsLimitAnnotation = "io.podman.annotations.pids-limit"
|
||||
|
||||
// TotalAnnotationSizeLimitB is the max length of annotations allowed by Kubernetes.
|
||||
TotalAnnotationSizeLimitB int = 256 * (1 << 10) // 256 kB
|
||||
)
|
||||
|
@ -375,6 +375,20 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
|
||||
s.Annotations[define.InspectAnnotationApparmor] = apparmor
|
||||
}
|
||||
|
||||
if pidslimit, ok := annotations[define.PIDsLimitAnnotation+"/"+opts.Container.Name]; ok {
|
||||
s.Annotations[define.PIDsLimitAnnotation] = pidslimit
|
||||
pidslimitAsInt, err := strconv.ParseInt(pidslimit, 10, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.ResourceLimits == nil {
|
||||
s.ResourceLimits = &spec.LinuxResources{}
|
||||
}
|
||||
s.ResourceLimits.Pids = &spec.LinuxPids{
|
||||
Limit: pidslimitAsInt,
|
||||
}
|
||||
}
|
||||
|
||||
if label, ok := opts.Annotations[define.InspectAnnotationLabel+"/"+opts.Container.Name]; ok {
|
||||
if label == "nested" {
|
||||
s.ContainerSecurityConfig.LabelNested = &localTrue
|
||||
|
@ -527,6 +527,10 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
|
||||
s.Annotations[define.UserNsAnnotation] = c.UserNS
|
||||
}
|
||||
|
||||
if c.PIDsLimit != nil {
|
||||
s.Annotations[define.PIDsLimitAnnotation] = strconv.FormatInt(*c.PIDsLimit, 10)
|
||||
}
|
||||
|
||||
if len(c.StorageOpts) > 0 {
|
||||
opts := make(map[string]string, len(c.StorageOpts))
|
||||
for _, opt := range c.StorageOpts {
|
||||
|
@ -6180,4 +6180,18 @@ spec:
|
||||
Expect(execArr[len(execArr)-1]).To(Not(ContainSubstring(arr[len(arr)-1])))
|
||||
})
|
||||
|
||||
It("test pids-limit annotation", func() {
|
||||
ctrAnnotation := "io.podman.annotations.pids-limit/" + defaultCtrName
|
||||
pod := getPod(withAnnotation(ctrAnnotation, "10"), withPodInitCtr(getCtr(withImage(CITEST_IMAGE), withCmd([]string{"printenv", "container"}), withInitCtr(), withName("init-test"))), withCtr(getCtr(withImage(CITEST_IMAGE), withCmd([]string{"top"}))))
|
||||
err := generateKubeYaml("pod", pod, kubeYaml)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
kube := podmanTest.Podman([]string{"kube", "play", kubeYaml})
|
||||
kube.WaitWithDefaultTimeout()
|
||||
Expect(kube).Should(ExitCleanly())
|
||||
|
||||
exec := podmanTest.PodmanExitCleanly("exec", "testPod-"+defaultCtrName, "cat", "/sys/fs/cgroup/pids.max")
|
||||
Expect(exec.OutputToString()).To(Equal("10"))
|
||||
})
|
||||
|
||||
})
|
||||
|
Reference in New Issue
Block a user