fix(#977): add MANAGER_CONTAINER=h-root, migrate root container name
This commit is contained in:
parent
286a7c8fd3
commit
68cc433ac9
5 changed files with 115 additions and 29 deletions
|
|
@ -10,11 +10,14 @@ use tokio::process::Command;
|
|||
/// name itself can be at most `MAX_AGENT_NAME` chars.
|
||||
pub const AGENT_PREFIX: &str = "h-";
|
||||
pub const MAX_AGENT_NAME: usize = 9;
|
||||
/// Container name of the manager. Lives in the same path scheme as sub-agents
|
||||
/// (`/var/lib/hyperhive/agents/root/`, `/var/lib/hyperhive/applied/root/`),
|
||||
/// but its container has no `h-` prefix and extends a different
|
||||
/// nixosConfiguration (`root`, not `agent-base`).
|
||||
/// Logical name of the manager agent (broker recipient, state-dir key,
|
||||
/// meta flake attribute). All persistent state lives under `root/`.
|
||||
pub const MANAGER_NAME: &str = "root";
|
||||
/// Container name of the manager. Uses the same `h-` prefix as sub-agents
|
||||
/// so `nixos-container list` output is uniform and the list filter is
|
||||
/// a single `starts_with(AGENT_PREFIX)` check. Logical name → container
|
||||
/// name: `root` → `h-root`.
|
||||
pub const MANAGER_CONTAINER: &str = "h-root";
|
||||
|
||||
/// Mount point of the per-agent runtime directory inside the container.
|
||||
pub const CONTAINER_RUNTIME_MOUNT: &str = "/run/hive";
|
||||
|
|
@ -72,7 +75,7 @@ pub fn agent_web_port(name: &str) -> u16 {
|
|||
#[must_use]
|
||||
pub fn container_name(name: &str) -> String {
|
||||
if name == MANAGER_NAME {
|
||||
MANAGER_NAME.to_owned()
|
||||
MANAGER_CONTAINER.to_owned()
|
||||
} else {
|
||||
format!("{AGENT_PREFIX}{name}")
|
||||
}
|
||||
|
|
@ -161,7 +164,7 @@ async fn port_collision(self_name: &str) -> Option<String> {
|
|||
let port = agent_web_port(self_name);
|
||||
let raw = list().await.unwrap_or_default();
|
||||
for c in raw {
|
||||
let other = if c == MANAGER_NAME {
|
||||
let other = if c == MANAGER_CONTAINER {
|
||||
MANAGER_NAME.to_owned()
|
||||
} else if let Some(n) = c.strip_prefix(AGENT_PREFIX) {
|
||||
n.to_owned()
|
||||
|
|
@ -233,7 +236,7 @@ async fn agents_for_meta(name_to_add: Option<&str>) -> Result<Vec<crate::meta::A
|
|||
let mut out: Vec<crate::meta::AgentSpec> = containers
|
||||
.into_iter()
|
||||
.filter_map(|c| {
|
||||
let (name, is_manager) = if c == MANAGER_NAME {
|
||||
let (name, is_manager) = if c == MANAGER_CONTAINER {
|
||||
(MANAGER_NAME.to_owned(), true)
|
||||
} else if let Some(n) = c.strip_prefix(AGENT_PREFIX) {
|
||||
(n.to_owned(), false)
|
||||
|
|
@ -598,7 +601,7 @@ pub async fn list() -> Result<Vec<String>> {
|
|||
Ok(String::from_utf8_lossy(&out.stdout)
|
||||
.lines()
|
||||
.map(str::trim)
|
||||
.filter(|line| line.starts_with(AGENT_PREFIX) || *line == MANAGER_NAME)
|
||||
.filter(|line| line.starts_with(AGENT_PREFIX))
|
||||
.map(str::to_owned)
|
||||
.collect())
|
||||
}
|
||||
|
|
@ -1076,9 +1079,8 @@ fn set_nspawn_flags(
|
|||
let path = format!("/etc/nixos-containers/{container}.conf");
|
||||
let original = std::fs::read_to_string(&path).with_context(|| format!("read {path}"))?;
|
||||
|
||||
// Logical agent name (container name minus the sub-agent prefix).
|
||||
// For the manager the strip is a no-op — harmless, manager paths
|
||||
// below are gated on `container == MANAGER_NAME` anyway.
|
||||
// Logical agent name — strip the `h-` prefix.
|
||||
// For the manager: `h-root` → `root`. For sub-agents: `h-iris` → `iris`.
|
||||
let agent_name = container.strip_prefix(AGENT_PREFIX).unwrap_or(container);
|
||||
|
||||
// Claude credentials land at `/home/<agent>/.claude` so the
|
||||
|
|
@ -1099,7 +1101,7 @@ fn set_nspawn_flags(
|
|||
// the `/agents` bind below already exposes both (along with
|
||||
// every sub-agent's). For regular agents the harness dir is
|
||||
// the sibling of notes_dir (same parent, "harness" subdir).
|
||||
if container != MANAGER_NAME {
|
||||
if container != MANAGER_CONTAINER {
|
||||
let _ = write!(
|
||||
binds,
|
||||
" --bind={notes}:/agents/{agent_name}/state",
|
||||
|
|
@ -1120,7 +1122,7 @@ fn set_nspawn_flags(
|
|||
);
|
||||
}
|
||||
}
|
||||
if container == MANAGER_NAME {
|
||||
if container == MANAGER_CONTAINER {
|
||||
// systemd-nspawn refuses to start a container whose bind
|
||||
// source doesn't exist. The meta repo is created by the
|
||||
// startup migration, but make sure the directory is there
|
||||
|
|
|
|||
Loading…
Reference in a new issue