Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S6864: Add examples for LimitRange #4002

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions rules/S6864/kubernetes/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ node failure.

=== Code examples

To avoid potential issues specify a memory limit for each container.
To avoid potential issues either specify a memory limit for each container or create a resource of kind `LimitRange` that sets a default memory limit for all containers in a namespace.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To avoid potential issues either specify a memory limit for each container or create a resource of kind `LimitRange` that sets a default memory limit for all containers in a namespace.
To avoid potential issues either specify a memory limit for each container or create a resource of kind `LimitRange` that sets a default memory limit for all containers/pods in a namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limits are specified for each container in the pod specification, so I chose this wording

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased a bit to mention pod specifications


==== Noncompliant code example

Expand All @@ -55,6 +55,18 @@ spec:
image: nginx
----

[source,yaml,diff-id=2,diff-type=noncompliant]
----
apiVersion: v1
kind: Pod
metadata:
name: example
spec:
containers:
- name: web # Noncompliant
image: nginx
----

==== Compliant solution

[source,yaml,diff-id=1,diff-type=compliant]
Expand All @@ -72,11 +84,35 @@ spec:
memory: 100Mi
----

[source,yaml,diff-id=2,diff-type=compliant]
----
apiVersion: v1
kind: LimitRange
metadata:
name: mem-limit-range
namespace: default-mem-example
spec:
limits:
- type: Container
default:
memory: 100Mi
---
apiVersion: v1
kind: Pod
metadata:
name: example
namespace: default-mem-example
spec:
containers:
- name: web
image: nginx
----

=== How does this work?

A limit can be set through the property `resources.limits.memory` of a
container. Alternatively, a default limit for a namespace can be set with
`LimitRange`.
`LimitRange` through `spec.limits[].default.memory`.

== Resources

Expand Down