Skip to content

feat(shield): set GOMAXPROCS/GOMEMLIMIT for Go workloads on Windows - #2660

Closed
francesco-furlan wants to merge 1 commit into
mainfrom
feat/shield-go-runtime-windows
Closed

feat(shield): set GOMAXPROCS/GOMEMLIMIT for Go workloads on Windows#2660
francesco-furlan wants to merge 1 commit into
mainfrom
feat/shield-go-runtime-windows

Conversation

@francesco-furlan

Copy link
Copy Markdown
Contributor

What

Sets GOMAXPROCS/GOMEMLIMIT explicitly for Shield's Go workloads on Windows, derived from each container's own resource limits via the downward API (resourceFieldRef).

Why

Modern Go reads cgroup CPU/memory limits automatically on Linux. Windows containers have no cgroups, so the runtime falls back to whole-node CPU count and no memory ceiling — causing scheduler contention and OOM risk under tight limits. We pin the runtime to whatever the chart renders, only where Go can't auto-detect (Windows).

Changes

  • templates/common/_go_runtime.tpl (new) — common.go_runtime.envs helper. Emits each env var only when its matching limit is set (limits.cpuGOMAXPROCS, limits.memoryGOMEMLIMIT with divisor: "1").
  • templates/host/daemonset-windows.yaml — always tuned (always Windows).
  • templates/cluster/deployment.yaml — tuned only when pinned to Windows nodes.
  • templates/cluster/_helpers.tpl — new cluster.scheduled_on_windows detector (checks effective nodeSelector for kubernetes.io/os: windows).
  • Env vars emitted before the user-env include, so users can still override.
  • Linux host-shield DaemonSet left unchanged (Go auto-detects there).
  • Chart.yaml bumped 1.43.21.44.0.
  • Tests added to the Windows DaemonSet and cluster Deployment suites.

Notes

  • Windows scheduling is detected via nodeSelector only — affinity-only pinning of cluster-shield won't trigger the env vars (matches how the chart's own Windows DaemonSet signals OS; documented in the helper comment).

Verification

  • helm template: Windows DaemonSet always tuned; cluster-shield tuned only when Windows-pinned; both gated on limits; Linux host DaemonSet untouched.
  • helm unittest: 37 suites / 560 tests pass.

🤖 Generated with Claude Code

Windows containers have no cgroups, so the Go runtime cannot auto-detect
the container's CPU/memory limits and falls back to whole-node CPU count
with no memory ceiling. Set GOMAXPROCS/GOMEMLIMIT explicitly via the
downward API (resourceFieldRef) so they track whatever the chart renders.

- New common.go_runtime.envs helper emits each var only when its limit is set
- host-shield-windows DaemonSet: always tuned (always Windows)
- cluster-shield Deployment: tuned only when pinned to Windows nodes,
  detected via the effective nodeSelector (kubernetes.io/os: windows)
- Emitted before the user-env include so users can still override
- Linux host-shield left unchanged (Go auto-detects cgroup limits there)
@francesco-furlan
francesco-furlan requested a review from a team as a code owner June 19, 2026 10:38
@francesco-furlan
francesco-furlan marked this pull request as draft June 25, 2026 10:22
@mavimo
mavimo deleted the feat/shield-go-runtime-windows branch July 30, 2026 08:48
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.

1 participant