Skip to content

[nats] Fixes for NATS App Helm chart, fix template issues with config.merge - #1583

Merged
Timofei Larkin (lllamnyp) merged 2 commits into
cozystack:mainfrom
insignia96:fix/nats-chart-config-merge-bugs
Nov 4, 2025
Merged

Timofei Larkin (lllamnyp) merged 2 commits into
cozystack:mainfrom
insignia96:fix/nats-chart-config-merge-bugs

Conversation

@insignia96

@insignia96 Isaiah Olson (insignia96) commented Nov 4, 2025 •

Copy link
Copy Markdown
Contributor

[nats] Fixes for NATS App Helm chart, fix template issues with config.merge value

What this PR does

This PR fixes two critical bugs in the NATS application chart (packages/apps/nats) that prevented successful deployment when using user authentication with custom configuration:

Bug #1: YAML Parse Error with Empty config.merge

  • When users were defined but config.merge was empty ({}), the Helm template would fail with YAML parse errors
  • Fixed by adding safe existence checks before accessing .Values.config.merge and preventing rendering of empty merge blocks

Bug #2: Incorrect Config Nesting

  • When both users and config.merge were defined, custom NATS config values (e.g., max_payload, max_connections) were incorrectly nested as children of the accounts object instead of being placed at the root NATS configuration level
  • This caused NATS pods to crash with "Expected map entries for accounts" errors
  • Fixed by correcting the indentation from nindent 12 to nindent 10 in the template

The related issue is #1354

Changes Made

File: packages/apps/nats/templates/nats.yaml

  1. Line 55: Added safe existence checks for .Values.config.merge
  2. Line 66: Added length validation to prevent rendering empty merge objects
  3. Line 67: Fixed indentation to ensure config values merge at root level

Impact

  • Enables NATS deployments with user authentication and custom configuration
  • Fixes Stalwart mail server clustering scenarios that require NATS with authentication
  • Resolves HelmRelease failures in multi-tenant environments

Testing

Can be tested with:

apiVersion: apps.cozystack.io/v1alpha1
kind: NATS
metadata:
  name: test-nats
spec:
  replicas: 2
  users:
    testuser: {}
  config:
    merge:
      max_payload: 2097152
      max_connections: 500

Expected result: HelmRelease succeeds, NATS pods start successfully, and configuration is valid.


Release note

[nats] Fix NATS application chart template bugs that prevented deployments with user authentication and custom configuration.

Summary by CodeRabbit

  • Bug Fixes

    • Broader detection for including merge configuration so embedded merge blocks appear more reliably.
    • Credentials/accounts sections now render whenever any password is present, fixing cases where credentials were omitted.
    • Resolver and merged config rendering made more consistent, reducing unexpected omissions in exported manifests.
  • Chores

    • Simplified internal config handling to reduce nesting and improve stability.

@dosubot dosubot Bot added the size/XS This PR changes 0-9 lines, ignoring generated files label Nov 4, 2025
@coderabbitai

coderabbitai Bot commented Nov 4, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Updates a single Helm template to simplify and broaden conditionals that control rendering of merged config, resolver, and credentials blocks in the NATS manifest; shifts to with-template rendering and reduces indentation levels.

Changes

Cohort / File(s) Change Summary
NATS Template Configuration
packages/apps/nats/templates/nats.yaml
Broadened guards for rendering the config.merge block to check for .Values.config.merge or presence of passwords, switched to with-style rendering for config.merge and config.resolver, simplified inner conditionals for credentials, and reduced nindent from 12 to 10 for embedded YAML.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Helm as Helm engine
  participant Values as .Values
  participant Template as nats.yaml template
  participant Manifest as Rendered manifest

  Helm->>Template: Render nats.yaml with .Values
  Template->>Values: check if .Values.config.merge exists OR passwords present
  alt merge condition true
    Template->>Manifest: render merged config (with .Values.config.merge)
  else merge condition false
    Template-->>Manifest: skip merged config
  end

  Template->>Values: check for resolver block
  alt resolver exists
    Template->>Manifest: render resolver (with .Values.config.resolver)
  else
    Template-->>Manifest: skip resolver
  end

  Template->>Values: check for any password entries
  alt passwords present
    Template->>Manifest: render accounts/credentials sections using passwords
  else
    Template-->>Manifest: skip accounts/credentials rendering
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to YAML indentation changes (nindent 12 → 10) affecting embedded blocks.
  • Verify the broadened conditional (.Values.config.merge vs previous checks) doesn't unintentionally render empty/invalid config.
  • Confirm password-presence branch retains prior behavior for accounts/credentials rendering.

Suggested reviewers

  • kvaps
  • nbykov0

Poem

🐰 In the meadow of templates I hop and I peep,
Guarding merges and resolvers so YAML stays neat.
With gentler checks and indents made tight,
I stitch configs together by soft moonlight. ✨

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main fixes described: NATS Helm chart template issues with config.merge conditional gating and indentation adjustments.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1ebc9c and 172774b.

📒 Files selected for processing (1)
  • packages/apps/nats/templates/nats.yaml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (3)
packages/apps/nats/templates/nats.yaml (3)

55-69: Conditional restructuring looks solid — properly handles all edge cases.

The dual-layer conditioning at lines 55 and 57 correctly addresses the PR bugs:

  • Line 55 renders the merge: block if either passwords or custom config exist
  • Line 57 ensures accounts: only renders when passwords are defined
  • The with block at line 66–68 prevents empty merge blocks (fixes the YAML parse error when config.merge is empty)

This approach aligns with the past reviewer's suggestion to use with blocks instead of explicit existence checks, which is idiomatic Helm.


66-68: Indentation fix correctly nests merged config at the right hierarchy level.

The change from nindent 12 to nindent 10 ensures that user-provided config from .Values.config.merge becomes a sibling of the accounts: block (both children of merge:), rather than a grandchild of accounts:. This fixes the nesting bug and prevents the "Expected map entries for accounts" error mentioned in the PR.

The same pattern is correctly applied to the resolver: block at lines 70–72.

Also applies to: 70-72


55-73: Confirm compatibility with PR #1571 (as raised by kvaps).

The PR reviewer kvaps flagged a potential conflict with a recent separate NATS fix in PR #1571. Given that both PRs touch the NATS Helm template, please verify there are no overlapping changes or revert/re-apply ordering issues.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello Isaiah Olson (@insignia96), 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 addresses two critical bugs within the NATS application Helm chart that previously hindered successful deployments, particularly when user authentication was combined with custom configurations. The changes ensure that NATS deployments can now properly utilize both user authentication and custom settings without encountering YAML parsing errors or incorrect configuration nesting, thereby enabling more robust and flexible NATS deployments.

Highlights

  • YAML Parse Error Fix: Resolved a YAML parse error that occurred when config.merge was empty but users were defined, by adding safe existence checks for .Values.config.merge.
  • Incorrect Config Nesting Fix: Corrected an issue where custom NATS config values were incorrectly nested under the accounts object, causing NATS pods to crash. This was fixed by adjusting the indentation level.
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 (@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 (@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. ↩

@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 effectively addresses two critical bugs in the NATS Helm chart that prevented deployments with user authentication and custom configurations. The fixes correctly add existence checks for .Values.config.merge to prevent YAML parsing errors and adjust the indentation to ensure custom configurations are merged at the correct level. The changes are well-implemented. I've added one suggestion to refactor a repeated condition into a variable to improve code clarity and maintainability.

@dosubot dosubot Bot added the kind/bug Categorizes issue or PR as related to a bug label Nov 4, 2025
@kvaps Andrei Kvapil (kvaps) added the kind/backport Categorizes issue or PR as requiring a backport to the current release line label Nov 4, 2025
@kvaps

Copy link
Copy Markdown
Member

Hey Isaiah Olson (@insignia96) many thanks for your contribution!
Recently there were anotother fix for NATS.

Could you please confirm that it won't conflict with this change?
#1571

Comment thread packages/apps/nats/templates/nats.yaml Outdated
Comment on lines +66 to +67
{{- if and .Values.config (hasKey .Values.config "merge") (gt (len .Values.config.merge) 0) }}
{{ toYaml .Values.config.merge | nindent 10 }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
{{- if and .Values.config (hasKey .Values.config "merge") (gt (len .Values.config.merge) 0) }}
{{ toYaml .Values.config.merge | nindent 10 }}
{{- with .Values.config.merge }}
{{- toYaml . | nindent 10 }}

There isn't a need to check if .Values.config.merge is set (it's at least an empty dict), but the with block will not render if it is empty, fixing the issue. Good catch with the indent, however.

Comment thread packages/apps/nats/templates/nats.yaml Outdated
fullnameOverride: {{ .Release.Name }}
config:
{{- if or (gt (len $passwords) 0) (gt (len .Values.config.merge) 0) }}
{{- if or (gt (len $passwords) 0) (and .Values.config (hasKey .Values.config "merge") (gt (len .Values.config.merge) 0)) }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
{{- if or (gt (len $passwords) 0) (and .Values.config (hasKey .Values.config "merge") (gt (len .Values.config.merge) 0)) }}
{{- if or $passwords .Values.config.merge }}

Same as my previous comment, no need to check the parent keys, they are defined by default. Also empty dicts are falsey values, so this check could be more concise.

Comment thread packages/apps/nats/templates/nats.yaml Outdated
Comment on lines 57 to 65
@@ -63,8 +63,8 @@ spec:
password: "{{ $password }}"
{{- end }}
{{- end }}

@lllamnyp Timofei Larkin (lllamnyp) Nov 4, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is outside the diff range, but in the same gist as all the other suggestions, you could apply a refactor like this:

Suggested change
{{- with $passwords }}
accounts:
A:
users:
{{- range $username, $password := . }}
- user: "{{ $username }}"
password: "{{ $password }}"
{{- end }}
{{- end }}

This patch makes the fixes from `b1ebc9cc` by @insignia96 terser by
making use of Helm's `with` blocks.

Signed-off-by: Timofei Larkin <[email protected]>
@dosubot dosubot Bot added size/S This PR changes 10-29 lines, ignoring generated files and removed size/XS This PR changes 0-9 lines, ignoring generated files labels Nov 4, 2025
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Nov 4, 2025
@lllamnyp
Timofei Larkin (lllamnyp) merged commit 634649f into cozystack:main Nov 4, 2025
21 checks passed
@github-actions

github-actions Bot commented Nov 4, 2025

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/backport Categorizes issue or PR as requiring a backport to the current release line kind/bug Categorizes issue or PR as related to a bug lgtm This PR has been approved by a maintainer size/S This PR changes 10-29 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants