Skip to content

[feat] Support topologySpreadConstraints on backend, workflows, workers and code executor - #422

Open
jrhuerta wants to merge 3 commits into
tryretool:mainfrom
jrhuerta:topology-spread-constraints
Open

jrhuerta wants to merge 3 commits into
tryretool:mainfrom
jrhuerta:topology-spread-constraints

Conversation

@jrhuerta

@jrhuerta jrhuerta commented Nov 9, 2026 •

Copy link
Copy Markdown

Summary

The chart exposes affinity, nodeSelector and tolerations but not topologySpreadConstraints. Without them, there is no way to spread Retool replicas evenly across availability zones. On clusters with per-zone node pools (for example Karpenter), the scheduler keeps placing new replicas in the first zone that has room. Running pods are never rebalanced, so one zone fills up first.

This PR adds topologySpreadConstraints to these Deployments:

  • main backend (deployment_backend.yaml)
  • workflow backend (deployment_workflows.yaml)
  • workflow, agent, agent eval, retoolos and rr agent workers (_workers.tpl)
  • code executor (deployment_code_executor.yaml)

Values

  • topologySpreadConstraints: new top-level list, default [].
  • Per-component overrides, resolved most specific first:
    • workers: <parent>.worker / agents.evalWorker, then <parent>, then global
    • workflow backend: workflows, then global
    • code executor: codeExecutor, then global

The first block that sets the key wins. An explicit [] therefore disables constraints for that component, and an unset key inherits from the next block. This uses hasKey rather than default, because default would treat [] as unset.

A constraint without a labelSelector gets the selector labels of the pod's own component, through the retool.topologySpreadConstraints helper. One global list then spreads each Deployment over its own pods only:

topologySpreadConstraints:
  - maxSkew: 1
    topologyKey: topology.kubernetes.io/zone
    whenUnsatisfiable: DoNotSchedule
  - maxSkew: 2
    topologyKey: kubernetes.io/hostname
    whenUnsatisfiable: ScheduleAnyway

A constraint that sets its own labelSelector is rendered unchanged.

Testing

New .github/test_topology_spread_constraints.py, added to the lint-chart job. It asserts that:

  • the default values render no constraints;
  • with the global list, each of the 5 Deployments gets both constraints, each selector equals that Deployment's spec.selector.matchLabels, and no two components share a selector;
  • an explicit labelSelector is kept as written (the code executor in the fixture);
  • a worker-level override (agents.evalWorker) applies to that worker only;
  • a parent override (agents) applies to both agent workers and not to the workflow worker;
  • an explicit [] override disables constraints for that component only.

I mutation-tested the assertions. Each of these changes makes at least one test fail: default semantics instead of hasKey, the backend selector used for workers, and always overwriting labelSelector.

Also checked:

  • With the default [], helm template output is identical to main for ci/test-install-values.yaml merged with each existing ci/*-option.yaml file. Only random generated secrets differ.
  • helm lint passes. Both values.yaml copies are in sync. The chart version is bumped to 6.14.3. schema/generate.sh --check passes; the new top-level key is marked @schema hidden like its neighbours.

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The rules affect pod placement across several Retool Deployments in one chart.

The PR appears safe to merge, with non-blocking improvements needed for empty overrides and tests.

Findings

  1. P2 Empty overrides still inherit rules ▶
  2. P2 Wrong selectors can pass checks ▶

Reviews (1) · Last reviewed commit: "[feat] Support topologySpreadConstraints..." · Reviewed by Greptile

Comment thread charts/retool/templates/_workers.tpl Resolved
jrhuerta and others added 3 commits November 23, 2026 16:32
…rs and code executor

Add a top-level topologySpreadConstraints value, with per-component
overrides that follow the existing affinity fallback order
(worker -> parent -> global, or component -> global).

A constraint without a labelSelector gets the selector labels of the pod's
own component. One list can then spread each Deployment on its own pods,
for example across zones, without a separate selector per component.

The default is an empty list, so rendered manifests do not change unless
the value is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the list by key presence instead of `default`: the most specific
values block that sets topologySpreadConstraints wins, so an explicit []
disables constraints for that component while an unset key still inherits.

Add .github/test_topology_spread_constraints.py with render assertions:
each component selects only its own pods, an explicit labelSelector is
kept, worker and parent overrides apply only where set, an empty override
disables constraints, and the default renders none. The option fixture
now uses an explicit selector that differs from the injected one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hema

Follows the convention from tryretool#427: top-level keys without schema
annotations are marked @Schema hidden, so they stay out of
values.schema.json and README.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jrhuerta
jrhuerta force-pushed the topology-spread-constraints branch from ee3202a to 829d716 Compare November 23, 2026 21:35
@jrhuerta

Copy link
Copy Markdown
Author

@mertbozfakioglu @tomgoren-retool could one of you take a look at this when you have a moment?

I rebased it onto main (chart version now 6.14.3) and added @schema hidden for the new top-level key, following #427. schema/generate.sh --check, helm lint and all .github/test_*.py scripts pass locally. CI will also need approval to run, since this comes from a fork.

Thanks!

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