Skip to content

fix(chart): suppress replicas when hpa is enabled#133

Open
kamiKAC wants to merge 1 commit into
n8n-io:mainfrom
kamiKAC:fix/replicas-with-hpa
Open

fix(chart): suppress replicas when hpa is enabled#133
kamiKAC wants to merge 1 commit into
n8n-io:mainfrom
kamiKAC:fix/replicas-with-hpa

Conversation

@kamiKAC
Copy link
Copy Markdown

@kamiKAC kamiKAC commented May 13, 2026

Pull Request

Description

Fixes replica handling in deployment templates so spec.replicas is not rendered when HPA is enabled for that component.

This prevents conflicts between Kubernetes HPA-managed scaling and statically defined replicas in the chart output.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Example/configuration update
  • CI/CD improvements

Related Issues

Fixes # (issue)
Relates to # (issue)

Changes Made

  • Updated charts/n8n/templates/deployment-main.yaml to render replicas only when hpa.main.enabled is false.
  • Updated charts/n8n/templates/deployment-worker.yaml to render replicas only when hpa.worker.enabled is false.
  • Updated charts/n8n/templates/deployment-webhook-processor.yaml to render replicas only when hpa.webhookProcessor.enabled is false.

Testing Performed

Chart Validation

  • helm lint charts/n8n passes
  • ./scripts/validate-examples.sh passes
  • Template rendering works with all examples

Deployment Testing (if applicable)

  • Tested with minimal configuration
  • Tested with production configuration
  • Tested upgrade path from previous version
  • All pods start successfully
  • Application is accessible

Specific Testing for Changes

Describe any specific testing you performed for your changes:

  • Ran helm lint charts/n8n successfully.
  • Verified the branch only changes the three deployment templates needed for this fix.
  • Confirmed the implementation conditionally omits spec.replicas when the related HPA flag is enabled.

Breaking Changes

If this includes breaking changes, describe what they are and provide migration instructions:

  • None.

Documentation Updates

  • Updated Chart.yaml version (if needed)
  • Updated CHANGELOG.md
  • Updated README.md (if needed)
  • Updated examples (if needed)
  • Updated CONTRIBUTING.md (if needed)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added examples that demonstrate the changes (if applicable)
  • All new and existing tests pass

Screenshots (if applicable)

Add screenshots to help explain your changes.

Additional Notes

  • This PR is intentionally limited to conditional replicas rendering for HPA-enabled deployments.
  • No schema, values, or documentation changes are included in this branch.

Summary by cubic

Suppress spec.replicas in Helm deployment templates when HPA is enabled, so HPA controls scaling without conflicts. Applies to main, worker, and webhook-processor deployments.

Written for commit 6ba4942. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Architecture diagram
sequenceDiagram
    participant HelmClient as Helm Client (CLI/CI)
    participant Chart as n8n Helm Chart
    participant Values as values.yaml / --set flags
    participant TemplateEngine as Helm Template Engine
    participant DeployYaml as Generated Deployment YAML
    participant Kubernetes as Kubernetes API Server
    participant HPA as HorizontalPodAutoscaler

    Note over HelmClient,Kubernetes: Helm Chart Rendering Flow

    HelmClient->>Chart: helm install/upgrade with values
    Chart->>Values: Read .Values from values.yaml + CLI overrides

    rect rgb(240, 240, 240)
        Note over Values,DeployYaml: Per-component decision (main, worker, webhook-processor)
        alt .Values.hpa.main.enabled == true
            Values->>TemplateEngine: hpa.main.enabled=true
            TemplateEngine->>TemplateEngine: CHANGED: Skip rendering replicas in deployment-main.yaml
            TemplateEngine->>DeployYaml: Generate Deployment (no spec.replicas field)
            DeployYaml-->>Kubernetes: Submit Deployment without replicas
            Kubernetes->>HPA: HPA manages replica count
            HPA->>Kubernetes: Set desired replicas based on metrics
        else .Values.hpa.main.enabled == false
            Values->>TemplateEngine: hpa.main.enabled=false
            TemplateEngine->>TemplateEngine: CHANGED: Render replicas from .Values.replicaCount
            TemplateEngine->>DeployYaml: Generate Deployment with spec.replicas=N
            DeployYaml-->>Kubernetes: Submit Deployment with static replicas
            Kubernetes->>Kubernetes: Start N pods (no HPA interference)
        end
    end

    Note over Values,DeployYaml: Identical logic applies for worker and webhook-processor components

    Kubernetes-->>HelmClient: Deployment created/updated (success)
Loading

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