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

[helm] Set GOMAXPROCS and GOMEMLIMIT environment variables #1528

Merged
merged 2 commits into from
May 23, 2024

Conversation

jnoordsij
Copy link
Contributor

Description of the change

Set GOMAXPROCS and GOMEMLIMIT environment variables based on container resources.

Inspired by traefik/traefik-helm-chart#1029.

Benefits

This should reduce potential CPU throttling and OOMKills on containers.

Possible drawbacks

This creates an empty env key for those not setting resource values. This is only a little ugly, but should not be harmful. Alternatively, we could add some conditional wrapper around the whole env block to only make it appear if a value is set, but that will be more complicated if additional env would be added in the future.

Applicable issues

N/A

Additional information

The resourceFieldRef is a very specific Kubernetes directive that is created specifically for passing resource-related values, which rounds up the CPU value to the nearest whole number (e.g. 250m to 1) and passes the memory as a numeric value; so 64Mi would result in the environment variable being set to 67108864. This by design makes it completely compatible with Go's API.

An example is documented within Kubernetes documentation itself: https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-container-fields-as-values-for-environment-variables.

…r resources

Signed-off-by: Jesper Noordsij <jesper.noordsij@gmail.com>
Signed-off-by: Jesper Noordsij <jesper.noordsij@gmail.com>
Copy link
Collaborator

@alemorcuq alemorcuq left a comment

Choose a reason for hiding this comment

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

Great, thank you!

@alemorcuq alemorcuq merged commit 317940c into bitnami-labs:main May 23, 2024
16 checks passed
@jnoordsij jnoordsij deleted the set-gomemlimit-gomaxprocs branch May 23, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants