Skip to content

K8s: Gate distributed component replicas on external datastore#3175

Merged
VietND96 merged 1 commit into
trunkfrom
k8s-gate-component-replicas
Jul 13, 2026
Merged

K8s: Gate distributed component replicas on external datastore#3175
VietND96 merged 1 commit into
trunkfrom
k8s-gate-component-replicas

Conversation

@VietND96

Copy link
Copy Markdown
Member

What

In distributed mode (isolateComponents: true), the Distributor, SessionQueue, and SessionMap components can be scaled to multiple replicas only when they share state through an external datastore (Redis/Postgres). This gates the replica count on that datastore so multi-replica setups without shared state can't be created by accident.

  • Adds a seleniumGrid.component.replicaCount helper: it honors components.<x>.replicas when that component's externalDatastore.enabled is true, and otherwise forces 1 (nil-safe via dig).
  • Uses it in the three distributed-mode deployments: distributor, session-queue, session-map.

Replica counts remain fully settable from chart values once a datastore is configured — this only prevents the silently-broken case of >1 replica with no shared state.

Why

Running multiple Distributor/SessionQueue/SessionMap replicas without a shared datastore breaks the grid (each replica has independent state). Previously replicas: {{ max 1 (...) }} allowed >1 regardless of datastore.

Verify

helm template with isolateComponents=true:

Scenario distributor session-queue session-map
datastore ON, replicas 3/2/4 3 2 4
datastore OFF, replicas 3/2/4 1 1 1
mixed (only sessionMap datastore ON), all replicas=5 1 1 5

helm lint passes.

🤖 Generated with Claude Code

Distributor, SessionQueue and SessionMap can scale to multiple replicas only
when they share state through an external datastore (Redis/Postgres). Add a
seleniumGrid.component.replicaCount helper that honors components.<x>.replicas
when that component's externalDatastore is enabled and otherwise forces 1, and
use it in the three distributed-mode deployments. This prevents silently broken
multi-replica setups (no shared state) while keeping replica counts fully
settable from chart values once a datastore is configured.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Helm: Gate distributed component replica counts on external datastore

🐞 Bug fix ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Prevent Distributor/SessionQueue/SessionMap from scaling >1 without shared external state.
• Add a reusable Helm helper to compute safe replica counts per component.
• Apply the helper to distributed-mode deployments to avoid silently broken grids.
Diagram

graph TD
A["Chart values"] --> B["replicaCount helper"] --> C["Distributor deploy"]
B --> D["SessionQueue deploy"]
B --> E["SessionMap deploy"]
A --> F["externalDatastore.enabled"] --> B
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Fail fast on invalid configuration (template error)
  • ➕ Makes misconfiguration immediately visible during install/upgrade
  • ➕ Avoids surprising behavior where user sets replicas>1 but gets 1
  • ➖ Breaking/stricter behavior for existing users relying on current values
  • ➖ Harder to support mixed scenarios unless error conditions are nuanced
2. Enforce via values.schema.json (JSON Schema validation)
  • ➕ Validates early with clear, structured error messages
  • ➕ Keeps templates simpler and shifts rules into schema
  • ➖ Schema cannot always express cross-field constraints cleanly for per-component nesting
  • ➖ Helm schema support varies by tooling; still may need template-side guards
3. Introduce a global 'distributedSharedStateRequired' toggle
  • ➕ Explicit operator intent; avoids implicit gating
  • ➕ Can be documented as a hard requirement for distributed mode
  • ➖ Adds another knob and potential confusion
  • ➖ Does not inherently prevent the broken state unless combined with validation

Recommendation: The implemented helper-based gating is a good default because it prevents the most harmful misconfiguration without breaking installs. If operators prefer strictness, consider a follow-up optional fail-fast mode (or schema validation) that errors when replicas>1 and externalDatastore is disabled, while keeping the current safe-default behavior as the baseline.

Files changed (4) +19 / -3

Bug fix (4) +19 / -3
_helpers.tplAdd helper to gate distributed component replica counts +16/-0

Add helper to gate distributed component replica counts

• Introduces a new Helm helper (seleniumGrid.component.replicaCount) that returns the configured replicas only when externalDatastore.enabled is true; otherwise forces replicas to 1. Uses dig for nil-safe access to nested values.

charts/selenium-grid/templates/_helpers.tpl

distributor-deployment.yamlUse gated replicaCount helper for Distributor deployment +1/-1

Use gated replicaCount helper for Distributor deployment

• Replaces the direct max(1, replicas) expression with the shared replicaCount helper so Distributor cannot scale beyond 1 without an external datastore.

charts/selenium-grid/templates/distributor-deployment.yaml

session-map-deployment.yamlUse gated replicaCount helper for SessionMap deployment +1/-1

Use gated replicaCount helper for SessionMap deployment

• Switches SessionMap replica calculation to the shared helper, allowing multi-replica only when its external datastore is enabled.

charts/selenium-grid/templates/session-map-deployment.yaml

session-queue-deployment.yamlUse gated replicaCount helper for SessionQueue deployment +1/-1

Use gated replicaCount helper for SessionQueue deployment

• Updates SessionQueue deployment to compute replicas via the shared helper, preventing multi-replica setups without shared external state.

charts/selenium-grid/templates/session-queue-deployment.yaml

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@VietND96
VietND96 merged commit a5a34f5 into trunk Jul 13, 2026
106 of 113 checks passed
@VietND96
VietND96 deleted the k8s-gate-component-replicas branch July 13, 2026 12:05
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