Persist server-mode auth state on session PVC#1
Conversation
There was a problem hiding this comment.
Pull request overview
Updates server-mode agent deployments so OpenCode auth/config/state can persist on the existing session PVC (when enabled), instead of being written under /tmp, and adds CI plumbing to publish a patched controller image to GHCR.
Changes:
- When
Agent.spec.persistence.sessionsis enabled, setHOMEand XDG (XDG_CONFIG_HOME,XDG_DATA_HOME,XDG_STATE_HOME) to directories under/data/sessions. - Extend controller unit tests to cover both persisted and non-persisted session cases.
- Add a manual GitHub Actions workflow to build and push a controller image to GHCR.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/controller/server_builder.go | Sets persistent HOME/XDG env vars when session PVC persistence is enabled. |
| internal/controller/server_builder_test.go | Adds/extends tests validating env var behavior for persisted vs non-persisted sessions. |
| .github/workflows/build-ghcr-kubeopencode.yaml | Adds a manual workflow to build/push the controller image to GHCR. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| envVars = append(envVars, corev1.EnvVar{ | ||
| Name: OpenCodeDBEnvVar, | ||
| Value: ServerSessionDBPath, | ||
| }) | ||
| envVars = append(envVars, | ||
| corev1.EnvVar{Name: "HOME", Value: ServerPersistentHomeDir}, | ||
| corev1.EnvVar{Name: "XDG_CONFIG_HOME", Value: ServerPersistentXDGConfigHome}, | ||
| corev1.EnvVar{Name: "XDG_DATA_HOME", Value: ServerPersistentXDGDataHome}, | ||
| corev1.EnvVar{Name: "XDG_STATE_HOME", Value: ServerPersistentXDGStateHome}, | ||
| ) |
There was a problem hiding this comment.
When session persistence is enabled, this appends a second HOME env var after the default HOME set earlier. Having duplicate env var names in container.Env is easy to miss (tests map-overwrite it) and can lead to confusing/ordering-dependent behavior. Prefer computing the desired HOME value up front and setting HOME exactly once, then conditionally add the XDG_* env vars.
| // Verify OPENCODE_DB env var | ||
| var foundEnv bool | ||
| envMap := make(map[string]string, len(container.Env)) | ||
| for _, env := range container.Env { | ||
| envMap[env.Name] = env.Value | ||
| if env.Name == OpenCodeDBEnvVar { | ||
| foundEnv = true |
There was a problem hiding this comment.
The tests build an envMap from container.Env, which will silently drop duplicates (e.g., two HOME entries). Since the production code currently appends HOME twice when session persistence is enabled, these assertions won’t catch it. Consider adding explicit checks that HOME appears exactly once (and likewise for XDG_*), in addition to validating values.
This patches server-mode agent deployments so persisted agents store OpenCode auth/config/state on the existing session PVC instead of
/tmp.Changes:
Agent.spec.persistence.sessionsis enabled, setHOME,XDG_CONFIG_HOME,XDG_DATA_HOME, andXDG_STATE_HOMEunder/data/sessions/tmpfallback for non-persisted agentsRelated deploy issue: https://github.com/aimtheory/quantifai-deploy/issues/7