Skip to content

feat(helm): render nodeSelector, tolerations, and affinity on the componentized chart migrations Job - #39843

Merged
mateo-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_lit_7015_migration_job_node_selector
Sep 5, 2026
Merged

mateo-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_lit_7015_migration_job_node_selector

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • The componentized chart's migrations Job ignores node placement
  • gateway, backend, and ui take nodeSelector; migrationJob has no such key
  • The Job pod can land on any node, including ones too small for it

How it solves it:

  • Add migrationJob.nodeSelector, migrationJob.tolerations, and migrationJob.affinity to helm/litellm
  • Render them on the Job pod the same way the three Deployments do
  • Chart tests pin the default, the rendered values, and that the Job does not inherit gateway.*

User Flow

Before: an operator pins every LiteLLM pod to their intent: no-csi-nodes node pool, and the migrations Job is the one pod that still schedules anywhere

  1. They set nodeSelector: {intent: no-csi-nodes} under gateway, backend, ui, and migrationJob in their values file for the componentized chart at helm/litellm
  2. They run helm template litellm helm/litellm -f values.yaml
  3. The gateway, backend, and ui Deployments render nodeSelector: {intent: no-csi-nodes}; the litellm-litellm-migrations Job renders no nodeSelector, tolerations, or affinity at all, and values.yaml has no such keys under migrationJob to set
  4. They run helm upgrade --install litellm helm/litellm -f values.yaml -n litellm; the pre-upgrade migrations Job is created without a node selector, so its pod (4 CPU / 12Gi in their values) can land on any node in the cluster instead of the pool they sized for it

After: the same values file pins the migrations Job to the pool too

  1. They set nodeSelector: {intent: no-csi-nodes} under gateway, backend, ui, and migrationJob in their values file for the componentized chart at helm/litellm
  2. They run helm template litellm helm/litellm -f values.yaml
  3. All three Deployments and the litellm-litellm-migrations Job render nodeSelector: {intent: no-csi-nodes}; migrationJob.tolerations and migrationJob.affinity render on the Job the same way, and all three keys are documented under migrationJob in values.yaml
  4. They run helm upgrade --install litellm helm/litellm -f values.yaml -n litellm; the migrations Job pod carries the node selector, so it can only be placed on the intent: no-csi-nodes pool

Relevant issues

Linear ticket

Resolves LIT-7015

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. helm unittest helm/litellm -f 'tests/*.yaml' (13 suites, 121 tests)
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Shared setup: a values file shaped like an operator's real one, with the same intent: no-csi-nodes selector on every component, plus tolerations and affinity on the Job to show all three fields

cat > pin-values.yaml <<'YAML'
database:
  writer:
    host: postgres.example.com
    dbname: litellm
backend:
  nodeSelector:
    intent: no-csi-nodes
gateway:
  nodeSelector:
    intent: no-csi-nodes
ui:
  nodeSelector:
    intent: no-csi-nodes
migrationJob:
  enabled: true
  nodeSelector:
    intent: no-csi-nodes
  tolerations:
    - key: intent
      operator: Equal
      value: no-csi-nodes
      effect: NoSchedule
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: intent
                operator: In
                values:
                  - no-csi-nodes
YAML

cat > scheduling_per_pod.py <<'PY'
import sys
import yaml

for doc in yaml.safe_load_all(sys.stdin):
    if not doc or doc.get("kind") not in ("Deployment", "Job"):
        continue
    spec = doc["spec"]["template"]["spec"]
    tolerations = spec.get("tolerations") or []
    print(f'{doc["kind"]:<11} {doc["metadata"]["name"]:<30} nodeSelector={spec.get("nodeSelector")} tolerations={len(tolerations)} affinity={spec.get("affinity")}')
PY

Live cluster leg: a one-node kind cluster (kind create cluster --name lit7015), the same values file, helm upgrade --install litellm <chart> -f pin-values.yaml -n <ns> --create-namespace --timeout 40s on each side (the pre-install hook times out on purpose because there is no database, and the Job it created stays behind for inspection)

Before (41c8c2f)

  1. helm template litellm helm/litellm -f pin-values.yaml | python3 scheduling_per_pod.py

    Deployment  litellm-litellm-backend        nodeSelector={'intent': 'no-csi-nodes'} tolerations=0 affinity=None
    Deployment  litellm-litellm-gateway        nodeSelector={'intent': 'no-csi-nodes'} tolerations=0 affinity=None
    Deployment  litellm-litellm-ui             nodeSelector={'intent': 'no-csi-nodes'} tolerations=0 affinity=None
    Job         litellm-litellm-migrations     nodeSelector=None tolerations=0 affinity=None
    
  2. helm template litellm helm/litellm -f pin-values.yaml -s templates/migrations-job.yaml | python3 -c 'import sys,yaml; print(sorted(yaml.safe_load(sys.stdin)["spec"]["template"]["spec"].keys()))'

    ['automountServiceAccountToken', 'containers', 'restartPolicy', 'serviceAccountName']
    
  3. Live cluster: the Job renders without scheduling fields, so the pod is assigned to the unlabeled node right away, and once that node carries the pool taint the pod cannot schedule at all because the chart renders no tolerations

    $ kubectl -n base get job litellm-litellm-migrations -o jsonpath='nodeSelector={.spec.template.spec.nodeSelector} tolerations={.spec.template.spec.tolerations} affinity={.spec.template.spec.affinity}'
    nodeSelector= tolerations= affinity=
    $ kubectl -n base get pod -l app.kubernetes.io/component=migrations -o custom-columns='NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName'
    NAME                               STATUS    NODE
    litellm-litellm-migrations-p8ktf   Pending   lit7015-control-plane
    $ kubectl -n base get events --field-selector involvedObject.kind=Pod -o custom-columns='REASON:.reason,MESSAGE:.message'
    Scheduled   Successfully assigned base/litellm-litellm-migrations-p8ktf to lit7015-control-plane
    $ kubectl taint node lit7015-control-plane intent=no-csi-nodes:NoSchedule && kubectl -n base delete pod -l app.kubernetes.io/component=migrations
    $ kubectl -n base get events --field-selector involvedObject.kind=Pod -o custom-columns='REASON:.reason,MESSAGE:.message' | tail -1
    FailedScheduling   0/1 nodes are available: 1 node(s) had untolerated taint(s). preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
    

After (2674934)

The tip is 3b9568b, a merge of litellm_internal_staging into this branch to pick up its CI fixes; it touches nothing under helm/, so it cannot change the rendered chart and the run above stands

  1. helm template litellm helm/litellm -f pin-values.yaml | python3 scheduling_per_pod.py

    Deployment  litellm-litellm-backend        nodeSelector={'intent': 'no-csi-nodes'} tolerations=0 affinity=None
    Deployment  litellm-litellm-gateway        nodeSelector={'intent': 'no-csi-nodes'} tolerations=0 affinity=None
    Deployment  litellm-litellm-ui             nodeSelector={'intent': 'no-csi-nodes'} tolerations=0 affinity=None
    Job         litellm-litellm-migrations     nodeSelector={'intent': 'no-csi-nodes'} tolerations=1 affinity={'nodeAffinity': {'requiredDuringSchedulingIgnoredDuringExecution': {'nodeSelectorTerms': [{'matchExpressions': [{'key': 'intent', 'operator': 'In', 'values': ['no-csi-nodes']}]}]}}}
    
  2. helm template litellm helm/litellm -f pin-values.yaml -s templates/migrations-job.yaml | python3 -c 'import sys,yaml; d=yaml.safe_load(sys.stdin)["spec"]["template"]["spec"]; print(yaml.safe_dump({k: d.get(k) for k in ("nodeSelector","tolerations","affinity")}, sort_keys=False))'

    nodeSelector:
      intent: no-csi-nodes
    tolerations:
    - effect: NoSchedule
      key: intent
      operator: Equal
      value: no-csi-nodes
    affinity:
      nodeAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
          nodeSelectorTerms:
          - matchExpressions:
            - key: intent
              operator: In
              values:
              - no-csi-nodes
  3. helm lint helm/litellm --set database.writer.host=h --set database.writer.dbname=d reports 1 chart(s) linted, 0 chart(s) failed, and helm unittest helm/litellm -f 'tests/*.yaml' reports 13 suites and 121 tests passing. With the template change reverted and the new tests kept, the positive render test fails, so the tests do catch a regression

  4. Live cluster: the Job carries all three fields, the API server accepts them, the pod stays Pending until a node matches the selector, and once the node is labeled and tainted as the pool the pod is assigned there (the toleration is honored)

    $ kubectl -n head get job litellm-litellm-migrations -o jsonpath='nodeSelector={.spec.template.spec.nodeSelector} tolerations={.spec.template.spec.tolerations} affinity={.spec.template.spec.affinity}'
    nodeSelector={"intent":"no-csi-nodes"} tolerations=[{"effect":"NoSchedule","key":"intent","operator":"Equal","value":"no-csi-nodes"}] affinity={"nodeAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":{"nodeSelectorTerms":[{"matchExpressions":[{"key":"intent","operator":"In","values":["no-csi-nodes"]}]}]}}}
    $ kubectl -n head get pod -l app.kubernetes.io/component=migrations -o custom-columns='NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName'
    NAME                               STATUS    NODE
    litellm-litellm-migrations-dkz27   Pending   <none>
    $ kubectl -n head get events --field-selector involvedObject.kind=Pod -o custom-columns='REASON:.reason,MESSAGE:.message'
    FailedScheduling   0/1 nodes are available: 1 node(s) didn't match Pod's node affinity/selector. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
    $ kubectl label node lit7015-control-plane intent=no-csi-nodes && kubectl taint node lit7015-control-plane intent=no-csi-nodes:NoSchedule
    $ kubectl -n head get pod -l app.kubernetes.io/component=migrations -o custom-columns='NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName'
    NAME                               STATUS    NODE
    litellm-litellm-migrations-dkz27   Pending   lit7015-control-plane
    $ kubectl -n head get events --field-selector involvedObject.kind=Pod -o custom-columns='REASON:.reason,MESSAGE:.message' | grep Scheduled
    Scheduled          Successfully assigned head/litellm-litellm-migrations-dkz27 to lit7015-control-plane
    

Type

🆕 New Feature

Caveats (if any)

Low

  • The Job does not inherit gateway.nodeSelector; set migrationJob.nodeSelector explicitly
    • Same scoping as every other component in this chart; the classic litellm-helm chart uses top-level keys instead
  • A nodeSelector matching no node leaves the hook Job Pending
    • helm upgrade then fails at its --timeout before touching running pods

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

  • 2674934 passes /live-pr-risk

@mateo-berri
mateo-berri requested a review from a team September 5, 2026 01:29
@greptile-apps

greptile-apps Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds independently configurable scheduling controls to the componentized chart’s migrations Job.

  • Renders migrationJob.nodeSelector, migrationJob.tolerations, and migrationJob.affinity in the Job pod specification.
  • Keeps the scheduling fields absent by default, preserving existing behavior.
  • Documents that migration scheduling does not inherit gateway settings.
  • Adds Helm tests for defaults, configured values, and component isolation.

Confidence Score: 5/5

The PR appears safe to merge; the scheduling options are opt-in, render in the correct pod-spec location, and have focused regression coverage.

No actionable new issues remain. The prior documentation-policy finding was correctly withdrawn after mateo-berri explained that values.yaml serves as the chart’s configuration reference, and the thread is resolved.

Important Files Changed

Filename Overview
helm/litellm/templates/migrations-job.yaml Correctly renders optional migration Job scheduling fields at the pod-spec level.
helm/litellm/tests/migration_job_tests.yaml Adds focused coverage for default omission, configured scheduling, and non-inheritance from gateway values.
helm/litellm/values.yaml Adds backward-compatible empty defaults and useful configuration guidance for migration Job scheduling.

Reviews (4): Last reviewed commit: "Merge remote-tracking branch 'origin/lit..." | Re-trigger Greptile

Comment thread helm/litellm/values.yaml Resolved
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3b9568b. Configure here.

@mateo-berri
mateo-berri merged commit aea5358 into litellm_internal_staging Sep 5, 2026
608 of 629 checks passed
@mateo-berri
mateo-berri deleted the litellm_lit_7015_migration_job_node_selector branch September 5, 2026 05:19
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