Skip to content

Conversation

fank
Copy link
Collaborator

@fank fank commented May 21, 2025

This pull request introduces support for deploying n8n as a StatefulSet in Kubernetes, enabling better handling of persistent volumes for multi-replica setups. It includes updates to the Helm chart, configuration files, and documentation to guide users on when and how to use StatefulSets instead of Deployments.

StatefulSet Support

  • Documentation Updates:

    • Added a new section in README.md explaining the differences between StatefulSets and Deployments, their use cases, and configuration requirements. Includes a warning about incompatibility with persistence.existingClaim when using StatefulSets.
    • Added an example configuration file (examples/values_stateful.yaml) for deploying n8n as a StatefulSet with individual persistent volumes per replica.
    • Updated examples/README.md to reference the new example configuration.
  • Helm Chart Enhancements:

    • Introduced a new main.useStatefulSet flag in values.yaml to toggle between StatefulSet and Deployment.
    • Added a validation check in _helpers.tpl to ensure persistence.existingClaim is not used with StatefulSets.
    • Updated deployment.yaml to skip Deployment creation when main.useStatefulSet is true. [1] [2]
    • Created a new statefulset.yaml template for StatefulSet deployments, including support for volumeClaimTemplates and other StatefulSet-specific configurations.
  • Persistence Configuration:

    • Modified _helpers.tpl to ensure dynamic PVC provisioning is only used for Deployments when main.useStatefulSet is false.

Summary by CodeRabbit

  • New Features

    • Added support for deploying the application as a Kubernetes StatefulSet, allowing each replica to have its own persistent volume for improved data integrity in multi-replica setups.
    • Introduced a new configuration option to toggle between Deployment and StatefulSet modes.
    • Provided an example configuration file for StatefulSet deployments.
    • Added a headless service for StatefulSet pod management alongside the regular service for external access.
    • Implemented validation to prevent incompatible persistence configurations when using StatefulSet.
  • Documentation

    • Extended documentation to explain the differences between Deployment and StatefulSet, including configuration guidance and best practices for persistent storage and high availability.
    • Updated example configurations and references in documentation for easier adoption of StatefulSet deployments.

Copy link
Contributor

coderabbitai bot commented May 21, 2025

Warning

Rate limit exceeded

@fank has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 52 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0357972 and e30824e.

📒 Files selected for processing (11)
  • README.md (2 hunks)
  • charts/n8n/Chart.yaml (2 hunks)
  • charts/n8n/templates/_helpers.tpl (2 hunks)
  • charts/n8n/templates/deployment.yaml (2 hunks)
  • charts/n8n/templates/pvc.yaml (1 hunks)
  • charts/n8n/templates/service-headless.yaml (1 hunks)
  • charts/n8n/templates/service.yaml (2 hunks)
  • charts/n8n/templates/statefulset.yaml (1 hunks)
  • charts/n8n/values.yaml (1 hunks)
  • examples/README.md (1 hunks)
  • examples/values_stateful.yaml (1 hunks)

Walkthrough

The changes introduce support for deploying the n8n application as a Kubernetes StatefulSet, allowing each replica to have its own persistent volume. This includes new configuration options, updated documentation, Helm template logic for StatefulSet creation and validation, conditional rendering of resources, and an example configuration for stateful deployments with Redis.

Changes

File(s) Change Summary
Documentation and Configuration
README.md, charts/n8n/values.yaml
Added detailed "Deployment Types" section explaining StatefulSet vs Deployment, introduced main.useStatefulSet boolean configuration option with default false.
Helm Template Helpers and Validation
charts/n8n/templates/_helpers.tpl
Added n8n.validateStatefulSet function to enforce correct StatefulSet persistence settings; updated PVC creation logic to exclude PVC when using StatefulSet with dynamic persistence.
Deployment Resource Template
charts/n8n/templates/deployment.yaml
Wrapped entire Deployment manifest in conditional to render only if main.useStatefulSet is false, disabling Deployment creation when StatefulSet is enabled.
StatefulSet Resource Template
charts/n8n/templates/statefulset.yaml
New Helm template defining a StatefulSet resource, conditionally rendered if main.useStatefulSet is true, supporting per-replica persistent volumes, pod and volume configurations, and lifecycle management.
PersistentVolumeClaim Template
charts/n8n/templates/pvc.yaml
Modified PVC creation condition to prevent PVC creation when main.useStatefulSet is true, as StatefulSets manage PVCs via volumeClaimTemplates.
Service Templates
charts/n8n/templates/service-headless.yaml, charts/n8n/templates/service.yaml
Added new headless Service manifest for StatefulSet pod management, conditional on StatefulSet usage; modified service name to append "-svc" suffix when StatefulSet enabled; fixed default service type value.
Examples and Sample Configurations
examples/README.md, examples/values_stateful.yaml
Added new example values file for StatefulSet deployment with multiple replicas, persistent volumes, Redis configuration, and related documentation entry.
CI Workflow
.github/workflows/lint-test.yaml
Removed "linter-artifacthub" job; downgraded versions of checkout, Helm setup, and chart-testing actions in lint-test workflow.
Chart Metadata
charts/n8n/Chart.yaml
Updated chart version from 1.0.11 to 1.0.12; replaced changelog entry to describe StatefulSet deployment support.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Helm
    participant Kubernetes

    User->>Helm: Install/Upgrade chart with values.yaml
    Helm->>Helm: Check main.useStatefulSet value
    alt useStatefulSet = true
        Helm->>Helm: Validate persistence settings for StatefulSet
        Helm->>Kubernetes: Render and apply StatefulSet manifest
        Helm->>Kubernetes: Render and apply volumeClaimTemplates
        Helm->>Kubernetes: Render and apply headless Service
    else useStatefulSet = false
        Helm->>Kubernetes: Render and apply Deployment manifest
        Helm->>Kubernetes: Render and apply PVC if needed
        Helm->>Kubernetes: Render and apply regular Service
    end
    Kubernetes->>User: Deploys n8n pods with appropriate persistent storage
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Suggested reviewers

  • Vad1mo
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (7)
examples/values_stateful.yaml (4)

1-1: Add space after comment marker to improve readability
YAML conventions recommend a space after the #. Change line 1 from:

#stateful deployment for multiple replicas with persistent state per replica

to:

# stateful deployment for multiple replicas with persistent state per replica
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 1-1: wrong new line character: expected \n

(new-lines)


7-7: Remove trailing whitespace
Line 7 contains trailing spaces. Please remove them to satisfy YAML lint rules and avoid unnecessary diff noise.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 7-7: trailing spaces

(trailing-spaces)


18-18: Remove trailing whitespace
Line 18 contains trailing spaces. Removing them keeps the file clean and lint-compliant.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 18-18: trailing spaces

(trailing-spaces)


32-38: Add accessModes for Valkey persistence
For consistency with main.persistence, consider specifying:

valkey:
  primary:
    persistence:
      enabled: true
      size: 2Gi
      accessModes:
        - ReadWriteOnce

This makes storage requirements explicit.

README.md (2)

50-50: Add missing comma for clarity
Insert a comma after “persistent volume” in line 50 so it reads:

“…all pods share the same persistent volume, which can lead to data corruption…”

🧰 Tools
🪛 LanguageTool

[uncategorized] ~50-~50: A comma might be missing here.
Context: ...ent, all pods share the same persistent volume which can lead to data corruption as mu...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)


63-66: Clarify required persistence.type setting
The warning mentions persistence.enabled and persistence.storageClass, but for StatefulSets you must also set:

persistence:
  type: dynamic

Please update the note to include persistence.type for completeness.

charts/n8n/templates/statefulset.yaml (1)

71-75: Refine env empty-list logic
The current | ternary nil "[]" may emit env: null when extraEnv is non-empty, leading to invalid YAML. Consider refactoring to:

env:
  {{- if .Values.main.extraEnv }}
  {{- range $key, $value := .Values.main.extraEnv }}
  - name: {{ $key }}
    {{ toYaml $value | nindent 4 }}
  {{- end }}
  {{- else }}
  []
  {{- end }}

This ensures env is always a proper array.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 565fbf7 and bc97564.

📒 Files selected for processing (7)
  • README.md (2 hunks)
  • charts/n8n/templates/_helpers.tpl (2 hunks)
  • charts/n8n/templates/deployment.yaml (2 hunks)
  • charts/n8n/templates/statefulset.yaml (1 hunks)
  • charts/n8n/values.yaml (1 hunks)
  • examples/README.md (1 hunks)
  • examples/values_stateful.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
charts/n8n/templates/deployment.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

examples/values_stateful.yaml

[error] 1-1: wrong new line character: expected \n

(new-lines)


[error] 7-7: trailing spaces

(trailing-spaces)


[error] 18-18: trailing spaces

(trailing-spaces)


[error] 24-24: trailing spaces

(trailing-spaces)

charts/n8n/templates/statefulset.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)


[warning] 9-9: wrong indentation: expected 2 but found 4

(indentation)


[warning] 10-10: wrong indentation: expected 2 but found 4

(indentation)


[warning] 11-11: wrong indentation: expected 2 but found 4

(indentation)

🪛 LanguageTool
README.md

[uncategorized] ~50-~50: A comma might be missing here.
Context: ...ent, all pods share the same persistent volume which can lead to data corruption as mu...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

🔇 Additional comments (7)
charts/n8n/values.yaml (1)

51-53: LGTM: Well-documented StatefulSet configuration flag

The addition of the useStatefulSet parameter is well-documented and appropriately defaulted to false to maintain backward compatibility with existing deployments. This flag enables users to choose between Deployment and StatefulSet for their n8n instances.

examples/README.md (1)

12-12: LGTM: Clear documentation of the new example

The README has been properly updated to reference the new StatefulSet example configuration file, which will help users understand how to deploy n8n with individual persistent volumes per replica.

charts/n8n/templates/deployment.yaml (1)

1-1: LGTM: Appropriate conditional rendering of Deployment

The conditional wrapping ensures that the Deployment resource is only created when useStatefulSet is false, preventing resource conflicts when using StatefulSets. This implementation allows the seamless transition between deployment types.

The static analysis tool flagging a YAML syntax error is a false positive due to the Helm template syntax being processed before the YAML is rendered.

Also applies to: 125-125

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

charts/n8n/templates/_helpers.tpl (2)

70-70: LGTM: Proper PVC handling for different deployment types

The PVC logic has been correctly modified to only create dynamic PVCs when not using StatefulSets. This prevents duplicate volume claim creation since StatefulSets will handle PVC creation through volumeClaimTemplates.


105-110: LGTM: Important validation to prevent misconfiguration

The new validation function is an excellent safeguard that prevents users from configuring incompatible options. By failing early with a clear error message when both useStatefulSet=true and persistence.existingClaim is specified, you help users avoid confusing runtime errors.

charts/n8n/templates/statefulset.yaml (2)

1-3: Conditional rendering and validation are applied correctly
The if .Values.main.useStatefulSet guard and include "n8n.validateStatefulSet" call ensure the StatefulSet is only rendered when intended and that the configuration is validated.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)


62-70:

❓ Verification inconclusive

Verify envFrom indentation and optionality
Indentation errors in templated blocks can cause unexpected rendering. Use helm template to confirm that envFrom: and its child entries for ConfigMapRef and SecretRef appear only when defined and are indented correctly.


🏁 Script executed:

#!/bin/bash
# Render only the StatefulSet template and lint it
helm template . \
  --values examples/values_stateful.yaml \
  --set main.useStatefulSet=true \
  -s charts/n8n/templates/statefulset.yaml | yamllint -

Length of output: 236


Manual Verification Required: Confirm envFrom Indentation

Our environment couldn’t run the Helm CLI, so automated linting didn’t execute. Please verify locally that:

  • envFrom: only appears when .Values.main.config or .Values.main.secret are set
  • The child entries (configMapRef / secretRef) are indented correctly under envFrom:

Run this command in your local setup and ensure no errors are reported:

helm template . \
  --values examples/values_stateful.yaml \
  --set main.useStatefulSet=true \
  -s charts/n8n/templates/statefulset.yaml \
| yamllint -

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb8f395 and d275b47.

📒 Files selected for processing (2)
  • charts/n8n/templates/pvc.yaml (1 hunks)
  • charts/n8n/templates/statefulset.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
charts/n8n/templates/pvc.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

charts/n8n/templates/statefulset.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)


[warning] 9-9: wrong indentation: expected 2 but found 4

(indentation)


[warning] 10-10: wrong indentation: expected 2 but found 4

(indentation)


[warning] 11-11: wrong indentation: expected 2 but found 4

(indentation)

🔇 Additional comments (4)
charts/n8n/templates/pvc.yaml (2)

1-29: Conditional PVC creation aligns with StatefulSet support.
The addition of (not .Values.main.useStatefulSet) to the if guard on line 1 correctly prevents standalone PVC resources from being rendered when useStatefulSet is enabled, since StatefulSets manage volumes via volumeClaimTemplates. This change avoids PVC conflicts and is consistent with the new StatefulSet template logic.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)


1-29: Ignore YAMLLint false positive on Helm templating.
The YAMLLint error syntax error: expected the node content, but found '-' arises from Helm's Go templating syntax, not an actual YAML issue. You can safely disregard this warning.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

charts/n8n/templates/statefulset.yaml (2)

1-2: Validate StatefulSet configuration at the top-level.
Wrapping the template in {{- if .Values.main.useStatefulSet }} and invoking n8n.validateStatefulSet ensures that StatefulSet-specific preconditions (persistence enabled, no existing claims) are enforced early. This promotes fail-fast behavior for misconfigurations.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)


9-11: Indentation warnings are false positives.
The static analysis warnings at lines 9–11 (wrong indentation) stem from Helm template directives, not actual YAML formatting errors. The existing nindent calls correctly handle indentation for conditional blocks and can be ignored.

🧰 Tools
🪛 YAMLlint (1.37.1)

[warning] 9-9: wrong indentation: expected 2 but found 4

(indentation)


[warning] 10-10: wrong indentation: expected 2 but found 4

(indentation)


[warning] 11-11: wrong indentation: expected 2 but found 4

(indentation)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
examples/values_stateful.yaml (2)

1-1: Nitpick: Standardize header formatting.
There’s no newline before the first line and missing space after #. Consider revising to:

# Stateful deployment for multiple replicas with persistent state per replica
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 1-1: wrong new line character: expected \n

(new-lines)


9-9: Remove trailing whitespace.
Lines 9, 20, and 26 contain trailing spaces. Cleaning these improves YAML linting and readability.

Also applies to: 20-20, 26-26

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 9-9: trailing spaces

(trailing-spaces)

README.md (1)

50-50: Typographical nitpick: missing comma.
Add a comma after "persistent volume" for clarity:

- all pods share the same persistent volume which can lead to data corruption as multiple replicas try to access the same files simultaneously.
+ all pods share the same persistent volume, which can lead to data corruption as multiple replicas try to access the same files simultaneously.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~50-~50: A comma might be missing here.
Context: ...ent, all pods share the same persistent volume which can lead to data corruption as mu...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

charts/n8n/templates/statefulset.yaml (1)

17-21: Expose StatefulSet updateStrategy & podManagementPolicy.
Currently the default update strategy and pod management policy are used. Consider adding configurable updateStrategy and podManagementPolicy in values.yaml to enable controlled rolling updates and parallel pod startups:

main:
  statefulset:
    updateStrategy:
      type: RollingUpdate
      partition: 0
    podManagementPolicy: Parallel
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d275b47 and dc37d49.

📒 Files selected for processing (5)
  • README.md (2 hunks)
  • charts/n8n/templates/service-headless.yaml (1 hunks)
  • charts/n8n/templates/service.yaml (1 hunks)
  • charts/n8n/templates/statefulset.yaml (1 hunks)
  • examples/values_stateful.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
charts/n8n/templates/service.yaml

[error] 4-4: syntax error: expected , but found '{'

(syntax)

charts/n8n/templates/service-headless.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

charts/n8n/templates/statefulset.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)


[warning] 9-9: wrong indentation: expected 2 but found 4

(indentation)


[warning] 10-10: wrong indentation: expected 2 but found 4

(indentation)


[warning] 11-11: wrong indentation: expected 2 but found 4

(indentation)

examples/values_stateful.yaml

[error] 1-1: wrong new line character: expected \n

(new-lines)


[error] 9-9: trailing spaces

(trailing-spaces)


[error] 20-20: trailing spaces

(trailing-spaces)


[error] 26-26: trailing spaces

(trailing-spaces)

🪛 LanguageTool
README.md

[uncategorized] ~50-~50: A comma might be missing here.
Context: ...ent, all pods share the same persistent volume which can lead to data corruption as mu...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

🔇 Additional comments (4)
charts/n8n/templates/service.yaml (1)

4-4: ⚠️ Potential issue

Fix default Service type value.
The default for .Values.main.service.type is defined as "ClusterIP_" (with a trailing underscore) which is invalid. It should be "ClusterIP".
Apply this diff:

-  type: {{ default "ClusterIP_" .Values.main.service.type }}
+  type: {{ default "ClusterIP" .Values.main.service.type }}

Likely an incorrect or invalid review comment.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 4-4: syntax error: expected , but found '{'

(syntax)

charts/n8n/templates/service-headless.yaml (1)

1-5: The headless Service template correctly conditionally renders when useStatefulSet is enabled and aligns with the StatefulSet’s serviceName.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

README.md (1)

44-54: Documentation clear and comprehensive.
The new "Deployment Types" section effectively explains when to use Deployments vs StatefulSets and references the example configuration.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~50-~50: A comma might be missing here.
Context: ...ent, all pods share the same persistent volume which can lead to data corruption as mu...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

charts/n8n/templates/statefulset.yaml (1)

1-3: StatefulSet conditional inclusion & validation.
Including the n8n.validateStatefulSet helper ensures invalid PVC configurations (e.g., existingClaim with StatefulSets) are caught early.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

@joshuabaird
Copy link
Contributor

@fank This is a useful feature. Do you have the time to wrap it up? Thanks!

@fank
Copy link
Collaborator Author

fank commented Aug 7, 2025

@joshuabaird I am still actively using it in production, I will come back to this to clean it up!
I want to ensure I am testing this deeply before I want it to get this merged.

fank added a commit to fank/n8n-helm-chart that referenced this pull request Aug 7, 2025
- Fixed YAML formatting in examples/values_stateful.yaml (removed trailing spaces, added space after comment marker)
- Fixed grammar in README.md (added missing comma)
- Fixed service type default value from 'ClusterIP_' to 'ClusterIP' in charts/n8n/templates/service.yaml
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
charts/n8n/templates/service.yaml (2)

4-4: Quote the generated service name to avoid parsing issues

Although Helm usually renders the value without problems, quoting the entire name string guards against accidental colon/space characters sneaking in from template helpers and makes the YAML friendlier to external linters (they often choke on the first { they see, as hinted by the YAML-lint warning).

-name: {{ include "n8n.fullname" . }}{{ if .Values.main.useStatefulSet }}-svc{{ end }}
+name: "{{ include "n8n.fullname" . }}{{ if .Values.main.useStatefulSet }}-svc{{ end }}"

12-12: Quote the service type for consistency

Upstream Kubernetes examples normally quote the value of type, and quoting also sidesteps edge cases where users pass a lower-case value that is later upper-cased by templating logic.

-type: {{ default "ClusterIP" .Values.main.service.type }}
+type: {{ default "ClusterIP" .Values.main.service.type | quote }}
examples/values_stateful.yaml (2)

1-1: Convert CRLF to LF line endings

The file is committed with \r\n line endings (YAML-lint “wrong new line character”). This causes noisy diffs and can break tooling on Unix environments. Re-save the file with LF endings only.


20-24: Remind users to externalise secrets

encryption_key is hard-coded in the example. Even though it’s a placeholder string, beginners often copy the file verbatim. Adding a brief comment recommending a Kubernetes secret (or at least an environment variable) avoids accidental plaintext keys in Git.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc37d49 and 18f8b6f.

📒 Files selected for processing (3)
  • README.md (2 hunks)
  • charts/n8n/templates/service.yaml (1 hunks)
  • examples/values_stateful.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md
🧰 Additional context used
🪛 YAMLlint (1.37.1)
charts/n8n/templates/service.yaml

[error] 4-4: syntax error: expected , but found '{'

(syntax)

examples/values_stateful.yaml

[error] 1-1: wrong new line character: expected \n

(new-lines)

🔇 Additional comments (2)
charts/n8n/templates/service.yaml (1)

18-20: Confirm selector labels still match the StatefulSet pods

When main.useStatefulSet is true, the workload switches from Deployment to StatefulSet. Please double-check that the StatefulSet template still sets app.kubernetes.io/type: master; otherwise this service will not pick up the pods and traffic will break.

examples/values_stateful.yaml (1)

12-18: Validate persistence.type: dynamic matches the chart enum

The base values.yaml for the chart historically accepted type: pvc / type: hostPath or similar. “dynamic” is new; if the helper templates don’t recognise this value the StatefulSet will not render the volumeClaimTemplates. Please verify the helpers in _helpers.tpl handle "dynamic".

@joshuabaird
Copy link
Contributor

Thanks so much, @fank!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
charts/n8n/templates/deployment.yaml (2)

1-1: Guard clause is correct but should defensively handle a missing value

useStatefulSet is a newly-introduced flag, so older values.yaml files may omit it. Helm treats an undefined value as nil, which is falsy, but the not operator will return true for nil.
If that implicit behaviour is acceptable, leave as-is; otherwise wrap with default for explicitness and future-proofing:

-{{- if not .Values.main.useStatefulSet }}
+{{- if not (default false .Values.main.useStatefulSet) }}

125-125: Closing directive matches, but keep a blank line after it

Helm’s {{- end }} already trims the preceding newline. Adding one explicit newline after the closing tag avoids concatenating with whatever follows in concatenated manifests and keeps helm template output tidy.

-{{- end }}
+{{- end }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18f8b6f and 0f68ce2.

📒 Files selected for processing (6)
  • .github/workflows/lint-test.yaml (1 hunks)
  • README.md (2 hunks)
  • charts/n8n/templates/deployment.yaml (2 hunks)
  • charts/n8n/templates/service.yaml (1 hunks)
  • charts/n8n/values.yaml (1 hunks)
  • examples/README.md (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • examples/README.md
  • .github/workflows/lint-test.yaml
🚧 Files skipped from review as they are similar to previous changes (3)
  • charts/n8n/templates/service.yaml
  • charts/n8n/values.yaml
  • README.md
🧰 Additional context used
🪛 YAMLlint (1.37.1)
charts/n8n/templates/deployment.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

fank added a commit to fank/n8n-helm-chart that referenced this pull request Aug 7, 2025
- Add main.useStatefulSet flag to toggle between Deployment and StatefulSet
- Create StatefulSet template with volumeClaimTemplates for individual PVCs per replica
- Add headless service for StatefulSet DNS management
- Add validation to prevent incompatible persistence configurations
- Update PVC creation logic to skip when using StatefulSet
- Add example configuration for StatefulSet deployment
- Document StatefulSet vs Deployment use cases in README
- Bump chart version to 1.0.12
- Fix CI workflow chart-testing-action version to v2.7.0

This enables horizontal scaling with individual persistent volumes per replica,
useful for multi-instance deployments where each instance needs its own state.

Closes 8gears#187
@fank fank force-pushed the fk_statefulmain branch from 4a63b51 to e589cb9 Compare August 7, 2025 13:44
fank added a commit to fank/n8n-helm-chart that referenced this pull request Aug 7, 2025
- Add main.useStatefulSet flag to toggle between Deployment and StatefulSet
- Create StatefulSet template with volumeClaimTemplates for individual PVCs per replica
- Add headless service for StatefulSet DNS management
- Add validation to prevent incompatible persistence configurations
- Update PVC creation logic to skip when using StatefulSet
- Add example configuration for StatefulSet deployment
- Document StatefulSet vs Deployment use cases in README
- Bump chart version to 1.0.12
- Fix CI workflow chart-testing-action version to v2.7.0

This enables horizontal scaling with individual persistent volumes per replica,
useful for multi-instance deployments where each instance needs its own state.

Closes 8gears#187
@fank fank force-pushed the fk_statefulmain branch from e589cb9 to 92fa413 Compare August 7, 2025 13:46
fank added a commit to fank/n8n-helm-chart that referenced this pull request Aug 7, 2025
- Add main.useStatefulSet flag to toggle between Deployment and StatefulSet
- Create StatefulSet template with volumeClaimTemplates for individual PVCs per replica
- Add headless service for StatefulSet DNS management
- Add validation to prevent incompatible persistence configurations
- Update PVC creation logic to skip when using StatefulSet
- Add example configuration for StatefulSet deployment
- Document StatefulSet vs Deployment use cases in README
- Bump chart version to 1.0.12
- Fix CI workflow chart-testing-action version to v2.7.0

This enables horizontal scaling with individual persistent volumes per replica,
useful for multi-instance deployments where each instance needs its own state.

Closes 8gears#187
@fank fank force-pushed the fk_statefulmain branch from 92fa413 to e1b203f Compare August 7, 2025 13:54
@fank fank marked this pull request as ready for review August 7, 2025 13:54
@fank
Copy link
Collaborator Author

fank commented Aug 7, 2025

@Vad1mo feel free to review

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
charts/n8n/templates/pvc.yaml (1)

15-18: Incorrect use of {{- strips indentation → PVC YAML becomes invalid

Because {{- range ... }} trims the leading four spaces, list items are emitted flush-left:

  accessModes:
- "ReadWriteOnce"

This breaks YAML parsing.

-    {{- range .Values.main.persistence.accessModes }}
-    - {{ . | quote }}
-    {{- end }}
+    {{- range .Values.main.persistence.accessModes }}
+      - {{ . | quote }}
+    {{- end }}

or switch to nindent:

-    {{- range .Values.main.persistence.accessModes }}
-    - {{ . | quote }}
-    {{- end }}
+{{- range .Values.main.persistence.accessModes }}
+  - {{ . | quote }}
+{{- end }}
🧹 Nitpick comments (4)
charts/n8n/templates/deployment.yaml (1)

125-125: Minor: closing {{- end }} is easy to overlook

Consider adding a short comment so future edits don’t accidentally delete the opening guard:

{{- end }}{{/* useStatefulSet guard */}}
.github/workflows/lint-test.yaml (1)

50-50: Missing newline at EOF

Add a trailing newline to satisfy YAML-lint and keep Git diffs clean.

examples/values_stateful.yaml (1)

1-38: CRLF line endings & placeholder secrets

  1. File currently has Windows CRLF endings; convert to LF to avoid helm-lint noise.
  2. encryption_key: "<shared-encryption-key>" is a good reminder, but users often forget. Consider referencing a Kubernetes Secret instead.

Example:

-      encryption_key: "<shared-encryption-key>"
+      # encryption_key: "<shared-encryption-key>"
+      encryption_key__existingSecret: n8n-encryption
charts/n8n/templates/statefulset.yaml (1)

1-16: YAML front-matter & indentation warnings

yamllint flags a top-level syntax error and indentation issues (see pipeline hints).
While templating often confuses linters, adding the standard document delimiter and consistent two-space indentation silences most false positives and improves readability:

+---
 {{- if .Values.main.useStatefulSet }}
 {{- include "n8n.validateStatefulSet" . -}}

Consider running helm template through yamllint -d relaxed in CI to catch real YAML mistakes early.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a63b51 and e1b203f.

📒 Files selected for processing (12)
  • .github/workflows/lint-test.yaml (2 hunks)
  • README.md (2 hunks)
  • charts/n8n/Chart.yaml (2 hunks)
  • charts/n8n/templates/_helpers.tpl (2 hunks)
  • charts/n8n/templates/deployment.yaml (2 hunks)
  • charts/n8n/templates/pvc.yaml (1 hunks)
  • charts/n8n/templates/service-headless.yaml (1 hunks)
  • charts/n8n/templates/service.yaml (1 hunks)
  • charts/n8n/templates/statefulset.yaml (1 hunks)
  • charts/n8n/values.yaml (1 hunks)
  • examples/README.md (1 hunks)
  • examples/values_stateful.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • charts/n8n/Chart.yaml
  • examples/README.md
  • charts/n8n/templates/service.yaml
  • charts/n8n/values.yaml
  • README.md
  • charts/n8n/templates/_helpers.tpl
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/lint-test.yaml

10-10: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 YAMLlint (1.37.1)
.github/workflows/lint-test.yaml

[error] 50-50: no new line character at the end of file

(new-line-at-end-of-file)

charts/n8n/templates/deployment.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

charts/n8n/templates/pvc.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

charts/n8n/templates/service-headless.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

charts/n8n/templates/statefulset.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)


[warning] 9-9: wrong indentation: expected 2 but found 4

(indentation)


[warning] 10-10: wrong indentation: expected 2 but found 4

(indentation)


[warning] 11-11: wrong indentation: expected 2 but found 4

(indentation)

examples/values_stateful.yaml

[error] 1-1: wrong new line character: expected \n

(new-lines)

⏰ 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: lint-test
🔇 Additional comments (4)
charts/n8n/templates/pvc.yaml (1)

1-1: ✅ Condition correctly disables PVC when StatefulSet is enabled

Wrapping the PVC manifest with (not .Values.main.useStatefulSet) cleanly prevents duplicate/conflicting PVCs in StatefulSet mode.

charts/n8n/templates/deployment.yaml (1)

1-1: Deployment correctly gated behind !useStatefulSet

This prevents multiple workload controllers for the same pod spec. Nice.

.github/workflows/lint-test.yaml (1)

10-26: Downgrading core actions may break future CI runners

actions/checkout@v3, azure/[email protected], and [email protected] are all superseded. action-lint is already warning about checkout@v3.

Unless you have a reproducibility reason, upgrade to the latest major versions:

-uses: actions/checkout@v3
+uses: actions/checkout@v4

-uses: azure/[email protected]
+uses: azure/setup-helm@v4
+with:
+  version: v3.14.4   # keep pin if really required

-uses: helm/[email protected]
+uses: helm/chart-testing-action@v3
charts/n8n/templates/statefulset.yaml (1)

20-21: Ensure matching headless Service name

serviceName is set to {{ include "n8n.fullname" . }}-headless, but no headless Service template is included in this PR snippet. Pods will fail DNS resolution (<pod-ordinal>.<serviceName>) unless a Service with the exact same name (clusterIP: None) is rendered.

Please verify the chart renders a Service resource named {{ include "n8n.fullname" . }}-headless.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1b203f and 0357972.

📒 Files selected for processing (3)
  • charts/n8n/templates/pvc.yaml (2 hunks)
  • charts/n8n/templates/service-headless.yaml (1 hunks)
  • charts/n8n/templates/statefulset.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
charts/n8n/templates/pvc.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

charts/n8n/templates/service-headless.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)

charts/n8n/templates/statefulset.yaml

[error] 1-1: syntax error: expected the node content, but found '-'

(syntax)


[warning] 9-9: wrong indentation: expected 2 but found 4

(indentation)


[warning] 10-10: wrong indentation: expected 2 but found 4

(indentation)


[warning] 11-11: wrong indentation: expected 2 but found 4

(indentation)

⏰ 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: lint-test
🔇 Additional comments (2)
charts/n8n/templates/pvc.yaml (1)

16-18: accessModes block can render with zero-indent → invalid YAML

Because {{- range ...}} trims the entire leading whitespace, the list items may be emitted starting at column 0 instead of the required indent under accessModes:. Some Kubernetes validators (and yamllint) will reject the manifest.

-  accessModes:
-{{- range .Values.main.persistence.accessModes }}
-    - {{ . | quote }}
-{{- end }}
+  accessModes:
+{{- range .Values.main.persistence.accessModes }}
+  - {{ . | quote }}
+{{- end }}

Removing the dash from {{- range or using nindent 2 after the range are both acceptable alternatives.

Likely an incorrect or invalid review comment.

charts/n8n/templates/service-headless.yaml (1)

17-18: Port lookup now matches Deployment — good catch

Switching to
get (default (dict) .Values.main.config.n8n) "port"
eliminates the earlier drift between Service and Pod ports.

@fank fank force-pushed the fk_statefulmain branch from 5371faf to 9193f50 Compare August 7, 2025 14:45
@fank fank requested a review from Vad1mo August 20, 2025 05:20
This PR introduces StatefulSet support for n8n deployments, enabling better handling
of persistent storage when running multiple replicas.

## Key Changes

- Add new StatefulSet template with volumeClaimTemplates for individual PVCs per replica
- Add headless Service for StatefulSet DNS management and pod identity
- Add useStatefulSet flag to toggle between Deployment and StatefulSet modes
- Update PVC template to skip creation when using StatefulSet (handled by volumeClaimTemplates)
- Add validation to prevent incompatible persistence configurations (existingClaim with StatefulSet)
- Include example configuration file for StatefulSet deployments
- Add comprehensive documentation explaining when and how to use StatefulSets

## Implementation Details

- StatefulSet creates individual PVCs for each replica, preventing data corruption from shared volumes
- Headless service provides stable network identity for StatefulSet pods
- Regular service (-svc suffix) provides load balancing for external access
- Validation helper ensures users don't misconfigure persistence settings
- All templates include namespace field for proper scoping

## Use Cases

StatefulSets are recommended when:
- Running multiple n8n replicas that need individual persistent storage
- Each instance needs to maintain its own workflow data
- Implementing high availability with proper data isolation

For proper multi-replica operation, users should:
- Enable Redis/Valkey for session state management
- Use external database instead of SQLite
- Configure shared encryption key across all replicas

Fixes 8gears#186
@fank
Copy link
Collaborator Author

fank commented Sep 3, 2025

@Vad1mo changes and commit got cleaned up, based on latest changes in master.

@fank
Copy link
Collaborator Author

fank commented Sep 28, 2025

@RoseSecurity any change for you to review this?

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.

2 participants