apiVersion: templates.gatekeeper.sh/v1 kind: ConstraintTemplate metadata: name: k8scontainerrequests annotations: metadata.gatekeeper.sh/title: "Container Requests" metadata.gatekeeper.sh/version: 1.0.1 description: >- Requires containers to have memory and CPU requests set and constrains requests to be within the specified maximum values. https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ spec: crd: spec: names: kind: K8sContainerRequests validation: # Schema for the `parameters` field openAPIV3Schema: type: object properties: exemptImages: description: >- Any container that uses an image that matches an entry in this list will be excluded from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`. It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name) in order to avoid unexpectedly exempting images from an untrusted repository. type: array items: type: string cpu: description: "The maximum allowed cpu request on a Pod, exclusive." type: string memory: description: "The maximum allowed memory request on a Pod, exclusive." type: string targets: - target: admission.k8s.gatekeeper.sh rego: | {{ file.Read "src/general/containerrequests/src.rego" | strings.Indent 8 | strings.TrimSuffix "\n" }} libs: - | {{ file.Read "src/general/containerrequests/lib_exempt_container.rego" | strings.Indent 10 | strings.TrimSuffix "\n" }}