Skip to content

Commit 4406260

Browse files
Merge pull request #147 from agentevals-dev/feature/extend-helm-and-automigrate
Extend Helm chart with auto-migrate and extraVolumes options
2 parents ddbad2e + 7796a07 commit 4406260

3 files changed

Lines changed: 70 additions & 5 deletions

File tree

charts/agentevals/templates/deployment.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ spec:
2929
securityContext:
3030
{{- toYaml .Values.podSecurityContext | nindent 8 }}
3131
serviceAccountName: {{ include "agentevals.serviceAccountName" . }}
32-
{{- if .Values.ephemeralVolume.enabled }}
32+
{{- if or .Values.ephemeralVolume.enabled .Values.extraVolumes }}
3333
volumes:
34+
{{- if .Values.ephemeralVolume.enabled }}
3435
- name: agentevals-tmp
3536
{{- if or .Values.ephemeralVolume.sizeLimit (eq .Values.ephemeralVolume.medium "Memory") }}
3637
emptyDir:
@@ -43,6 +44,10 @@ spec:
4344
{{- else }}
4445
emptyDir: {}
4546
{{- end }}
47+
{{- end }}
48+
{{- with .Values.extraVolumes }}
49+
{{- toYaml . | nindent 8 }}
50+
{{- end }}
4651
{{- end }}
4752
containers:
4853
- name: agentevals
@@ -70,6 +75,8 @@ spec:
7075
value: "postgres"
7176
- name: AGENTEVALS_DATABASE_SCHEMA
7277
value: {{ .Values.database.postgres.schema | quote }}
78+
- name: AGENTEVALS_AUTO_MIGRATE
79+
value: {{ .Values.database.postgres.autoMigrate | quote }}
7380
{{- if .Values.database.postgres.urlFile }}
7481
- name: AGENTEVALS_DATABASE_URL_FILE
7582
value: {{ .Values.database.postgres.urlFile | quote }}
@@ -135,10 +142,15 @@ spec:
135142
port: http
136143
initialDelaySeconds: 15
137144
periodSeconds: 20
138-
{{- if .Values.ephemeralVolume.enabled }}
145+
{{- if or .Values.ephemeralVolume.enabled .Values.extraVolumeMounts }}
139146
volumeMounts:
147+
{{- if .Values.ephemeralVolume.enabled }}
140148
- name: agentevals-tmp
141149
mountPath: /tmp
150+
{{- end }}
151+
{{- with .Values.extraVolumeMounts }}
152+
{{- toYaml . | nindent 12 }}
153+
{{- end }}
142154
{{- end }}
143155
{{- with .Values.nodeSelector }}
144156
nodeSelector:

charts/agentevals/values.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ env: []
159159
# -- Extra envFrom sources (ConfigMapRef, SecretRef)
160160
envFrom: []
161161

162+
# -- Extra volumes appended to the pod spec. Use this to mount additional
163+
# config files or secrets (e.g. result-sink credentials) into the pod.
164+
extraVolumes: []
165+
166+
# -- Extra volumeMounts appended to the main container. Pair with
167+
# extraVolumes by name. securityContext.readOnlyRootFilesystem is true by
168+
# default; that only makes the root filesystem read-only, mounted paths
169+
# themselves are unaffected, so a writable extraVolumes entry works fine.
170+
extraVolumeMounts: []
171+
162172
# ==============================================================================
163173
# STORAGE (preview feature)
164174
#
@@ -195,6 +205,12 @@ database:
195205
urlFile: ""
196206
# -- Postgres schema to use for agentevals tables.
197207
schema: agentevals
208+
# -- Apply pending database migrations during server startup before the
209+
# HTTP listener opens. The Postgres advisory lock serialises concurrent
210+
# replica starts so this is safe with replicaCount > 1. When set to
211+
# false the server refuses to start if the schema is behind or dirty;
212+
# run "agentevals migrate up" manually in that case.
213+
autoMigrate: true
198214
# -- Bundled Postgres instance for development and evaluation only.
199215
# Not suitable for production. Deployed when enabled is true and url /
200216
# urlFile are not set.

src/agentevals/api/app.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ..run.sinks import log_registered_sinks
2121
from ..run.worker import AsyncRunWorker
2222
from ..storage import StorageSettings, build_repos
23-
from ..storage.postgres.migrator import Migrator
23+
from ..storage.postgres.migrator import Migrator, discover_migrations
2424
from ..utils.log_buffer import log_buffer
2525
from .debug_routes import debug_router
2626
from .routes import router
@@ -31,6 +31,22 @@
3131

3232
logger = logging.getLogger(__name__)
3333

34+
_TRUE_VALUES = {"true", "1", "yes", "on"}
35+
_FALSE_VALUES = {"false", "0", "no", "off"}
36+
37+
38+
def _env_bool(name: str, *, default: bool) -> bool:
39+
raw = os.getenv(name)
40+
if raw is None or raw == "":
41+
return default
42+
val = raw.strip().lower()
43+
if val in _TRUE_VALUES:
44+
return True
45+
if val in _FALSE_VALUES:
46+
return False
47+
raise ValueError(f"{name} must be one of true/false/1/0/yes/no/on/off (got: {raw!r})")
48+
49+
3450
try:
3551
from dotenv import load_dotenv
3652

@@ -68,13 +84,34 @@ async def lifespan(app: FastAPI):
6884
logger.error("Storage configuration invalid; /api/runs will not be available: %s", exc)
6985

7086
if storage_settings is not None and storage_settings.backend == "postgres":
71-
logger.info("Applying any pending migrations to schema '%s'", storage_settings.schema_name)
7287
migrator = Migrator(
7388
dsn=storage_settings.database_url or "",
7489
schema=storage_settings.schema_name,
7590
lock_timeout_s=storage_settings.migrate_lock_timeout_s,
7691
)
77-
await migrator.up()
92+
if _env_bool("AGENTEVALS_AUTO_MIGRATE", default=True):
93+
logger.info("Applying any pending migrations to schema '%s'", storage_settings.schema_name)
94+
await migrator.up()
95+
else:
96+
logger.info(
97+
"AGENTEVALS_AUTO_MIGRATE is disabled; verifying schema '%s' is up to date",
98+
storage_settings.schema_name,
99+
)
100+
status = await migrator.status()
101+
if status.dirty:
102+
raise RuntimeError(
103+
f"schema_migrations is dirty at version {status.version}. "
104+
"Resolve manually and run 'agentevals migrate force <version>', "
105+
"or set AGENTEVALS_AUTO_MIGRATE=true to retry on startup."
106+
)
107+
current = status.version
108+
pending = [m.version for m in discover_migrations() if current is None or m.version > current]
109+
if pending:
110+
raise RuntimeError(
111+
f"Database schema is behind: pending migrations {pending}. "
112+
"Run 'agentevals migrate up' to apply them, "
113+
"or set AGENTEVALS_AUTO_MIGRATE=true to apply on startup."
114+
)
78115

79116
repos = await build_repos(storage_settings)
80117
app.state.storage_settings = storage_settings

0 commit comments

Comments
 (0)