Skip to content

Run migrations before deploying brainstore and service pods - #128

Open
Kevin Green (KevinGreen) wants to merge 14 commits into
mainfrom
kevingreen/inf-869-helm-migration-job
Open

Kevin Green (KevinGreen) wants to merge 14 commits into
mainfrom
kevingreen/inf-869-helm-migration-job

Conversation

@KevinGreen

@KevinGreen Kevin Green (KevinGreen) commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Order changed workloads as migrations → Brainstore → API pools, AI Gateway, and Loop Runtime. deploymentOrdering.enabled (default true) controls the whole sequence; unchanged workloads keep running.

  • Content-address migration Jobs by their image and execution configuration. Reuse successful Jobs and immutable configuration snapshots across upgrades and rollbacks; a no-op upgrade creates no Job or pod rollout.
  • Read desired Brainstore identities from a stable ConfigMap without embedding dependency identities in application pod templates. Require the expected template, observed generation, compatible images, and complete readiness; old or terminating backends cannot satisfy a changed rollout.
  • Select migrations covering the newest API pool or Brainstore release. Opaque pins require an explicit migrationImage and stable minimumVersion assertion.
  • Include every rendered Brainstore role, including automation writers and draining zero-replica roles. Preserve the legacy gate ConfigMap unchanged for old ReplicaSet replacement pods. Gateway has its own configurable ServiceAccount.

This gates container startup, not Kubernetes object updates. The removed api.brainstoreStartupGate setting is ignored; existing opt-outs must set deploymentOrdering.enabled=false. See README configuration and lifecycle.

Input coverage

Input Behavior
Stable tags, with/without v, digest pins Select newest migration release and preserve the selected API pin; never copy a Brainstore digest to the API image.
SHA pins, numeric SHAs, prerelease/custom tags Require explicit migration image and stable floor; opaque Brainstore pods must match desired image and declared version.
Mixed service versions / isolated API pools Include all rendered pools; reject conflicting known majors and known-too-old migration bundles.
No-op / dependency-only changes Stable Job identity and workload templates; only changed templates roll, scale-only changes do not restart pods.
Ordering on/off; missing, partial, null/reused values Keep supported defaults; disabled mode omits gates and ignores unused validation.
Existing legacy gate / fresh install Preserve existing data; do not create a legacy ConfigMap on fresh installs.
Zero replicas / stale or terminating pods Require complete drain; stale templates, generations, migration state or readiness block startup.
AWS, Azure, Google, minimal; Google examples Render with ordering enabled and disabled.

Validation

  • 87 Python tests passed. All 629 Helm cases passed across the full run and focused rerun of the corrected migration fixture; provider rendering and strict lint passed.
  • Temporary revision-7/revision-8 checks proved identical pod templates for all nine enabled deployments and identical migration Job execution/name (20 cases); the fixture was removed.
  • Production render comparisons proved reader-only, writer-only, API-only, migration-only, scale-only, and Brainstore-image changes affect only the intended workload templates and migration inputs. Identical inputs produced identical resources.
  • The actual rollout checker accepted completed rendered templates and rejected old healthy deployments before expected config/scale changes reached them. Opaque API, Brainstore, and numeric pins also passed.
  • AWS/Azure/Google/minimal profiles and all five Google examples rendered with ordering on/off; the autoscaling example used its required API capability flag.
  • Offline validation only; no sandbox deployment or database changes.

Resolves INF-869.

@KevinGreen Kevin Green (KevinGreen) changed the title Run Helm migrations before starting new deployment pods Run migrations and complete Brainstore rollouts before API startup Nov 11, 2026
@KevinGreen Kevin Green (KevinGreen) changed the title Run migrations and complete Brainstore rollouts before API startup Run migrations then directly verify Brainstore rollout before API startup Nov 12, 2026
@KevinGreen Kevin Green (KevinGreen) changed the title Run migrations then directly verify Brainstore rollout before API startup Run migrations before deploying brainstore and API pods Nov 12, 2026
@KevinGreen Kevin Green (KevinGreen) changed the title Run migrations before deploying brainstore and API pods Run migrations before deploying brainstore and service pods Nov 12, 2026
@KevinGreen
Kevin Green (KevinGreen) marked this pull request as ready for review November 12, 2026 22:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T22:15:43.328716Z d460dc9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d460dc908b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "braintrust.brainstoreStartupGate.name" . }}

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.

Can we keep this ConfigMap available through the upgrade? The old API pods are still serving traffic while the new ones wait for Brainstore. If an old pod needs replacing (for example, after a node is drained), its replacement can't start without this ConfigMap. That means we could lose API capacity before the new pods can take over. Could we keep it available?

Comment thread braintrust/templates/migration-job.yaml Outdated
{{- $config := include "braintrust.deploymentOrdering.config" . | fromYaml -}}
{{- if $config.enabled -}}
{{- $name := include "braintrust.migrations.name" . -}}
{{- $api := include "braintrust.apiPoolConfig" (dict "root" . "overrides" (dict)) | fromYaml -}}

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.

How should this handle Brainstore newer than a pinned API? API v2.21.0 + Brainstore v2.22.0 renders a v2.21 migration Job, and the rollout gate accepts that combination. But the v2.21 bundle doesn't contain migration 74, which the v2.22 readers needed in the OE incident. Could we select a migration bundle that covers the Brainstore release and add a mixed-version test? Otherwise the Job can succeed while the required schema is still missing.

Comment thread braintrust/templates/_helpers.tpl Outdated
{{- $ordering := include "braintrust.deploymentOrdering.config" $root | fromYaml -}}
{{- if $ordering.enabled -}}
{{/* Release identity rejects a previous Ready generation before Helm updates it. */}}
{{- $_ := set $annotations "braintrust.dev/release-revision" (toString $root.Release.Revision) -}}

Choose a reason for hiding this comment

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

Question; if we put the release revision in every pod template, a helm upgrade would mean that it would restart all the deployments. Is that the intended/acceptable behavior? I wanted to ask because changing this doesn't really require a migration but would run a fresh migration anyway.

Choose a reason for hiding this comment

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

Question; following up on the upgrade note at the end of the PR description, since this is mounted by the existing replica set of API pods and is required, and the new API pods are waiting on the brainstore rollout. In this window, any old API pods that get rescheduled won't be able to come up since the config map has been deleted already. Could we keep this around for another revision or is this not something that's a big enough problem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that's a good point, there's a chance it could be a problem so I added this back

Comment thread braintrust/values.yaml
# Disable to deploy everything without chart-managed startup ordering.
# See README.md#release-ordering for configuration and operational limits.
deploymentOrdering:
enabled: true

Choose a reason for hiding this comment

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

Question; for customers who have set the old key to true, does this change silently make that key a no-op? More specifically, they didn't change their values.yaml but they get an error saying that the render failed? This is probably somewhat narrow since customers who have specifically opted out of the startup gate aren't likely very many but for those customers, the startup gate stops working and they get onboarded directly into the ordering. This is potentially just a behavior change worth calling out in the readme/release notes.

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.

3 participants