Skip to content

Fix Helm chart environment variable merging for groupFiltering.allowedGroups#209

Merged
aponcedeleonch merged 2 commits intomainfrom
fix-allowed-groups
Dec 22, 2025
Merged

Fix Helm chart environment variable merging for groupFiltering.allowedGroups#209
aponcedeleonch merged 2 commits intomainfrom
fix-allowed-groups

Conversation

@aponcedeleonch
Copy link
Member

@aponcedeleonch aponcedeleonch commented Dec 22, 2025

Closes: #199

  • Fixed groupFiltering.allowedGroups not being applied to podTemplateSpec by implementing automatic env var merging
  • Created new template helper that merges ALLOWED_GROUPS, database URLs, and custom env vars into podTemplateSpec
  • Updated documentation to clarify that mcpserver.env is merged with podTemplateSpec defaults
  • Changed SQLite path from /tmp to /data for consistency with emptyDir volume mount
  • Bumped chart version to 0.1.1 and appVersion to 0.2.0

🤖 Generated with Claude Code

…dGroups

- Fixed groupFiltering.allowedGroups not being applied to podTemplateSpec by implementing automatic env var merging
- Created new template helper that merges ALLOWED_GROUPS, database URLs, and custom env vars into podTemplateSpec
- Updated documentation to clarify that mcpserver.env is merged with podTemplateSpec defaults
- Changed SQLite path from /tmp to /data for consistency with emptyDir volume mount
- Bumped chart version to 0.1.1 and appVersion to 0.2.0

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@claude
Copy link

claude bot commented Dec 22, 2025

PR Review

✅ Strengths

Problem Solved: Correctly fixes the groupFiltering.allowedGroups not being applied due to env var merging issue.

Clean Implementation: The new mcp-optimizer.podTemplateSpec helper (lines 102-124 in _helpers.tpl) elegantly solves env var merging using:

  • deepCopy to avoid mutating source values
  • Logical append order: base → auto-generated (DB URLs, ALLOWED_GROUPS) → custom
  • Clear separation of concerns

Documentation: Comprehensive README updates explain the env var merging behavior well.

🔍 Issues & Recommendations

1. Potential Duplicate Environment Variables (Critical)

The helper doesn't check for duplicates before appending. If podTemplateSpec.spec.containers[0].env already contains ASYNC_DB_URL, DB_URL, or ALLOWED_GROUPS, they'll appear twice in the final spec.

Fix: Add deduplication logic (last value wins):

{{- $finalEnv := list }}
{{- $envMap := dict }}
{{- range concat $container.env $additionalEnvs .Values.mcpserver.env }}
  {{- $_ := set $envMap .name . }}
{{- end }}
{{- range $key, $val := $envMap }}
  {{- $finalEnv = append $finalEnv $val }}
{{- end }}

2. Silent Failure if podTemplateSpec is Missing

Line 35 in mcpserver.yaml: {{- if .Values.mcpserver.podTemplateSpec }} means no podTemplateSpec is rendered if undefined. Since the chart now depends on it for env vars, this creates inconsistency.

Fix: Either remove the conditional (always require podTemplateSpec) or fail explicitly if missing.

3. SQLite Path Inconsistency

values.yaml line 135 changed path from /tmp to /data, but SQLITE_TMPDIR still points to /tmp (line 64). While functionally okay due to volume mounts, it's confusing.

Recommendation: Either rename SQLITE_TMPDIR to SQLITE_DATADIR or document why tmpdir ≠ db path.

4. Documentation Clarity

README states custom env vars from mcpserver.env are "appended" but doesn't explain precedence. Users may not realize earlier values can be shadowed if duplicates aren't handled.

📊 Summary

Must Fix: Issue #1 (duplicate env vars)
Should Fix: Issue #2 (conditional podTemplateSpec)
Consider: Issues #3-4 (naming/docs)

Overall solid fix, but needs duplicate handling to be production-ready.

Copy link
Collaborator

@tgrunnagle tgrunnagle left a comment

Choose a reason for hiding this comment

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

Nice!

@aponcedeleonch
Copy link
Member Author

@claude please check if your comments have been addressed

@claude
Copy link

claude bot commented Dec 22, 2025

Claude finished @aponcedeleonch's task —— View job


Review Comments Status

Todo List


✅ All Issues Addressed

All four issues from my previous review have been successfully addressed:

Issue #1: Duplicate Environment Variables (Critical)FIXED

  • Implemented deduplication logic in _helpers.tpl:120-129
  • Uses a map to ensure each env var name appears only once
  • Last value wins as recommended

Issue #2: Silent Failure for Missing podTemplateSpecFIXED

  • Removed the conditional in mcpserver.yaml:35
  • podTemplateSpec is now always rendered, ensuring consistency

Issue #3: SQLite Path InconsistencyFIXED

  • Changed SQLITE_TMPDIR from /tmp to /data in values.yaml:64
  • Now consistent with the SQLite database path /data/mcp_optimizer.db

Issue #4: Documentation ClarityFIXED

  • Added clear "Environment Variable Precedence" section in README.md:134-140
  • Explains the three-tier precedence system (base → auto-generated → custom)
  • Documents that last value wins for duplicates

Summary

The PR is now production-ready. All critical and recommended issues have been properly addressed with clean implementations and comprehensive documentation.


Job Run: https://github.com/StacklokLabs/mcp-optimizer/actions/runs/${{ github.run_id }}
Branch: fix-allowed-groups

@aponcedeleonch aponcedeleonch merged commit b01092d into main Dec 22, 2025
6 checks passed
@aponcedeleonch aponcedeleonch deleted the fix-allowed-groups branch December 22, 2025 15:39
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.

Helm chart: groupFiltering.allowedGroups not working due to default podTemplateSpec

2 participants