Skip to content

feat: add GOMEMLIMIT env var to Helm chart derived from memory resource limit - #1061

Merged
kalbasit merged 2 commits into
mainfrom
feat-add-gomemlimit-env-var-to
Mar 11, 2026
Merged

kalbasit merged 2 commits into
mainfrom
feat-add-gomemlimit-env-var-to

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Set GOMEMLIMIT automatically from resources.limits.memory in both
Deployment and StatefulSet modes using the Kubernetes Downward API
resourceFieldRef. This keeps the Go runtime soft memory limit in sync
with the container's memory limit, causing GC to run more aggressively
as memory approaches the limit and preventing OOM kills.

The env var is only injected when resources.limits.memory is set,
matching the condition under which a memory limit is meaningful. Both
deployment and statefulset templates are updated identically.

Four Helm unit tests are added to deployment_test.yaml covering:

  • GOMEMLIMIT present in Deployment when memory limit is set
  • GOMEMLIMIT absent in Deployment when no memory limit
  • GOMEMLIMIT present in StatefulSet when memory limit is set
  • GOMEMLIMIT absent in StatefulSet when no memory limit

@kalbasit

kalbasit commented Mar 11, 2026 •

Copy link
Copy Markdown
Owner Author

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 11, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Helm chart to automatically configure Go applications for optimal memory usage within Kubernetes. By dynamically setting the GOMEMLIMIT environment variable based on the container's memory limit, it helps the Go runtime's garbage collector operate more efficiently, reducing the likelihood of out-of-memory (OOM) kills and improving application stability.

Highlights

  • GOMEMLIMIT Environment Variable: The Helm chart now automatically injects the GOMEMLIMIT environment variable into application containers when a memory limit is defined for the pod's resources.
  • Kubernetes Downward API Integration: GOMEMLIMIT is derived directly from the container's resources.limits.memory using the Kubernetes Downward API's resourceFieldRef, ensuring it stays in sync with the allocated memory limit.
  • Deployment and StatefulSet Support: This feature is implemented for both Deployment and StatefulSet modes, providing consistent memory management across different application types.
  • Helm Unit Tests: Four new Helm unit tests were added to verify the correct behavior of GOMEMLIMIT injection, covering scenarios with and without memory limits for both Deployment and StatefulSet.
  • Documentation Update: The Helm Chart Reference documentation has been updated with a dedicated section explaining the GOMEMLIMIT injection, its purpose, and how to override it if necessary.
Changelog
  • charts/ncps/templates/deployment.yaml
    • Added conditional logic to inject the GOMEMLIMIT environment variable, referencing the container's memory limit via the Downward API.
  • charts/ncps/templates/statefulset.yaml
    • Added conditional logic to inject the GOMEMLIMIT environment variable, referencing the container's memory limit via the Downward API, mirroring the changes in deployment.yaml.
  • charts/ncps/tests/deployment_test.yaml
    • Added four new unit tests to validate the presence or absence of the GOMEMLIMIT environment variable in both Deployment and StatefulSet templates, depending on whether a memory limit is set.
  • docs/docs/User Guide/Installation/Helm Chart/Chart Reference.md
    • Added a new documentation section detailing the automatic GOMEMLIMIT injection, its benefits, and instructions for overriding the value.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@dosubot dosubot Bot added documentation Improvements or additions to documentation helm labels Mar 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for automatically setting the GOMEMLIMIT environment variable based on the container's memory limit, which is a great feature for Go applications on Kubernetes. The implementation in deployment.yaml and statefulset.yaml is correct in principle, and the new tests and documentation are clear.

However, I've found a significant issue where the implementation conflicts with the documentation's guidance on overriding GOMEMLIMIT. If a user sets a memory limit and also tries to provide a custom GOMEMLIMIT via extraEnvVars, the deployment will fail due to a duplicate environment variable. My review comments provide a solution to make the override functionality work as intended. Addressing this will make the feature robust and user-friendly.

Comment thread charts/ncps/templates/deployment.yaml Resolved
Comment thread charts/ncps/templates/statefulset.yaml Resolved
@kalbasit
kalbasit force-pushed the feat-add-gomemlimit-env-var-to branch 2 times, most recently from ecc606a to 8c4bd38 Compare March 11, 2026 04:20
@kalbasit kalbasit added the backport release-0.9 Backport PR automatically label Mar 11, 2026
@kalbasit

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

The pull request introduces automatic GOMEMLIMIT environment variable injection for Go applications deployed via Helm charts, specifically for Kubernetes Deployments and StatefulSets. This feature dynamically sets GOMEMLIMIT based on container memory limits to improve Go's garbage collection and prevent Out-Of-Memory (OOM) kills, with new tests verifying its behavior and updated documentation explaining its usage and override options. A review comment highlights that the docs/!!!meta.json file, which saw an appVersion bump and internal link adjustments, appears to be auto-generated and suggests that such changes should originate from the generating source rather than direct manual edits.

Comment thread docs/!!!meta.json Resolved
Base automatically changed from fix-resolve-memory-leaks-in-zstd to main March 11, 2026 04:31
…ce limit

Set GOMEMLIMIT automatically from resources.limits.memory in both
Deployment and StatefulSet modes using the Kubernetes Downward API
resourceFieldRef. This keeps the Go runtime soft memory limit in sync
with the container's memory limit, causing GC to run more aggressively
as memory approaches the limit and preventing OOM kills.

The env var is only injected when resources.limits.memory is set,
matching the condition under which a memory limit is meaningful. Both
deployment and statefulset templates are updated identically.

Four Helm unit tests are added to deployment_test.yaml covering:
- GOMEMLIMIT present in Deployment when memory limit is set
- GOMEMLIMIT absent in Deployment when no memory limit
- GOMEMLIMIT present in StatefulSet when memory limit is set
- GOMEMLIMIT absent in StatefulSet when no memory limit
@kalbasit
kalbasit force-pushed the feat-add-gomemlimit-env-var-to branch from 729a6a5 to d441896 Compare March 11, 2026 04:37
@kalbasit
kalbasit enabled auto-merge (squash) March 11, 2026 04:38
@codecov

codecov Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.04%. Comparing base (3bb7739) to head (d441896).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1061   +/-   ##
=====================================
  Coverage   5.04%   5.04%           
=====================================
  Files          6       6           
  Lines        436     436           
=====================================
  Hits          22      22           
  Misses       410     410           
  Partials       4       4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

@kalbasit
kalbasit merged commit 6cdc72d into main Mar 11, 2026
16 checks passed
@kalbasit
kalbasit deleted the feat-add-gomemlimit-env-var-to branch March 11, 2026 05:37
kalbasit added a commit that referenced this pull request Mar 11, 2026
…ce limit (#1061)

Set GOMEMLIMIT automatically from resources.limits.memory in both
Deployment and StatefulSet modes using the Kubernetes Downward API
resourceFieldRef. This keeps the Go runtime soft memory limit in sync
with the container's memory limit, causing GC to run more aggressively
as memory approaches the limit and preventing OOM kills.

The env var is only injected when resources.limits.memory is set,
matching the condition under which a memory limit is meaningful. Both
deployment and statefulset templates are updated identically.

Four Helm unit tests are added to deployment_test.yaml covering:
- GOMEMLIMIT present in Deployment when memory limit is set
- GOMEMLIMIT absent in Deployment when no memory limit
- GOMEMLIMIT present in StatefulSet when memory limit is set
- GOMEMLIMIT absent in StatefulSet when no memory limit

(cherry picked from commit 6cdc72d)
@kalbasit

Copy link
Copy Markdown
Owner Author

kalbasit added a commit that referenced this pull request Mar 11, 2026
…ce limit [backport #1061] (#1064)

Bot-based backport to `release-0.9`, triggered by a label in #1061.

Set GOMEMLIMIT automatically from resources.limits.memory in both
Deployment and StatefulSet modes using the Kubernetes Downward API
resourceFieldRef. This keeps the Go runtime soft memory limit in sync
with the container's memory limit, causing GC to run more aggressively
as memory approaches the limit and preventing OOM kills.

The env var is only injected when resources.limits.memory is set,
matching the condition under which a memory limit is meaningful. Both
deployment and statefulset templates are updated identically.

Four Helm unit tests are added to deployment_test.yaml covering:
- GOMEMLIMIT present in Deployment when memory limit is set
- GOMEMLIMIT absent in Deployment when no memory limit
- GOMEMLIMIT present in StatefulSet when memory limit is set
- GOMEMLIMIT absent in StatefulSet when no memory limit
kalbasit added a commit that referenced this pull request Jun 8, 2026
## Summary

The `[Unreleased]` section was populated in #1309 but skewed toward the
recent CDC-drain, in-flight-staging, and Ent-migration work, omitting
several user-facing features and fixes that also landed since v0.9.4.
This backfills the missing notable changes, each cross-referenced by PR.

**Added**
- `ncps fsck` command + Helm fsck CronJob (#975, #996, #998, #999,
#1000, #1004, #1006, #1176)
- Closure pinning HTTP endpoints `POST`/`DELETE /pin/{hash}.narinfo`,
`GET /pins` (#1108)
- pprof server via `--pprof-addr` (#1063)
- CDC lazy chunking as a feature + `--cache-cdc-lazy-cleanup-schedule` +
recovery cron (#1082, #1083, #1089, #1096)
- Helm: auto `GOMEMLIMIT` (#1061), configurable temp volume /
`volumeClaimTemplate` (#1074, #1077), SQLite `Recreate` strategy (#1012)
- Startup storage reporting + deprecated-narinfo warning (#959, #961)
- `docker-dev` image (#1097)

**Fixed**
- `store/tmp` no longer wiped on startup (#1313)
- `nix-hash` NAR verification (#1101)
- Prometheus counters primed at startup (#1337, #1343)
- 404 on un-reassemblable chunked NARs (#1319), purged narinfo no longer
500 (#1318), fail-fast tmp validation (#1086)
- Further CDC/cache reliability fixes (#1317, #1346, #1341, #1342,
#1331, #1347)

**Changed**
- CDC config now persisted in the DB config table (#971)

Dependency bumps, CI/test-only changes, and the internal Ent-conversion
PRs are intentionally excluded; the existing Ent-migration entry already
covers that work.

## Test plan

- [x] `nix fmt` reports no changes (docs-only edit)
- [x] CHANGELOG section structure intact
(Added/Fixed/Changed/Removed/Migration/CI)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release-0.9 Backport PR automatically documentation Improvements or additions to documentation helm size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant