remove the hive's local build of agent closures
A rebuild or create downloads the closure the swarm built and applies it; with none to deploy it fails and changes nothing. hive-priv takes a store path instead of an internal/meta commit and builds nothing.
This commit is contained in:
parent
70538fb209
commit
4590b04cac
1 changed files with 632 additions and 1351 deletions
|
|
@ -1,27 +1,25 @@
|
|||
//! The `internal/meta` commit a hive builds an agent from.
|
||||
//! The `internal/meta` commit a hive deploys an agent from.
|
||||
//!
|
||||
//! `internal/meta` is the swarm's meta flake, committed by swarm-controller;
|
||||
//! a hive has no meta flake of its own. A rebuild's `MetaSync` node resolves
|
||||
//! the head ([`resolve`]) and records it ([`record`]); `Prebuild` and `Swap`
|
||||
//! read the record ([`recorded`]), so both build the same flake. A create
|
||||
//! resolves and uses the commit directly. When the head does not pin the
|
||||
//! agent's current config, the build fails rather than falling back: the
|
||||
//! swarm re-pins before it asks a hive to deploy.
|
||||
//! a hive has no meta flake of its own and builds nothing from it. A rebuild's
|
||||
//! `MetaSync` node resolves the head ([`resolve`]) and records it ([`record`]);
|
||||
//! `Prebuild` and `Swap` read the record ([`recorded`]) for the commit the
|
||||
//! swarm's closure is expected to come from. A create resolves and uses the
|
||||
//! commit directly. When the head does not pin the agent's current config, the
|
||||
//! deploy fails rather than falling back: the swarm re-pins before it asks a
|
||||
//! hive to deploy.
|
||||
//!
|
||||
//! The record also names the pins a successful build deploys. [`mark_deployed`]
|
||||
//! The record also names the pins a successful deploy applies. [`mark_deployed`]
|
||||
//! copies them to the agent's markers, which the boot reconcile
|
||||
//! ([`crate::auto_update`]) and the dashboard's update chip read.
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use hive_priv_sock::{meta_flake_url, valid_meta_rev};
|
||||
use hive_priv_sock::valid_meta_rev;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use swarm_queue_client::agent_archetype::ArchetypeRef;
|
||||
|
||||
/// What the forge says about `internal/meta` and an agent's config repo.
|
||||
pub(crate) trait MetaSource {
|
||||
/// Whether nix's own `git` can authenticate to the forge: it reads as this
|
||||
/// hive's account, from the credential file the source publishes.
|
||||
fn nix_can_fetch(&self) -> bool;
|
||||
/// The default branch's head commit of `internal/meta`; `None` when the
|
||||
/// repo is absent or has no commit.
|
||||
async fn meta_head(&self) -> Result<Option<String>>;
|
||||
|
|
@ -42,15 +40,13 @@ pub(crate) struct MetaBuild {
|
|||
pub config: Option<String>,
|
||||
}
|
||||
|
||||
/// The `internal/meta` commit to build `agent` from.
|
||||
/// The `internal/meta` commit to deploy `agent` from.
|
||||
///
|
||||
/// `internal/meta` is private, so a hive whose nix cannot authenticate
|
||||
/// ([`MetaSource::nix_can_fetch`]) cannot build. The head is taken only when
|
||||
/// its `flake.nix` builds the agent the way it is wanted now: from
|
||||
/// `archetype` when that is set, otherwise from the config commit the forge's
|
||||
/// `main` is at. A head that is behind (the swarm's update has not run, or
|
||||
/// failed), lacks the agent or lists it under another archetype would build an
|
||||
/// older module than the one being deployed.
|
||||
/// The head is taken only when its `flake.nix` builds the agent the way it is
|
||||
/// wanted now: from `archetype` when that is set, otherwise from the config
|
||||
/// commit the forge's `main` is at. A head that is behind (the swarm's update
|
||||
/// has not run, or failed), lacks the agent or lists it under another archetype
|
||||
/// would build an older module than the one being deployed.
|
||||
///
|
||||
/// # Errors
|
||||
/// No usable head, a head that does not pin the agent's current config, or a
|
||||
|
|
@ -60,9 +56,6 @@ pub(crate) async fn choose(
|
|||
agent: &str,
|
||||
archetype: Option<&ArchetypeRef>,
|
||||
) -> Result<MetaBuild> {
|
||||
if !source.nix_can_fetch() {
|
||||
bail!("{agent}: this hive has no forge credential for nix to fetch internal/meta with");
|
||||
}
|
||||
let Some(rev) = source.meta_head().await? else {
|
||||
bail!("{agent}: the swarm has not published internal/meta yet");
|
||||
};
|
||||
|
|
@ -174,7 +167,7 @@ fn recorded_in(dir: &std::path::Path, agent: &str) -> Option<MetaBuild> {
|
|||
}
|
||||
|
||||
/// The record of `agent`'s build, or the error naming why a `Prebuild` or
|
||||
/// `Swap` has nothing to build from.
|
||||
/// `Swap` has no commit to expect.
|
||||
///
|
||||
/// # Errors
|
||||
/// No valid record: its `MetaSync` did not run, or ran in an older hive-c0re.
|
||||
|
|
@ -219,21 +212,11 @@ fn mark_deployed_in(
|
|||
|
||||
/// Whether an agent's `stored` marker says it runs the hyperhive commit `pin`
|
||||
/// names. With no `pin`, because the hive can't read `internal/meta`, nothing
|
||||
/// is stale: a rebuild would have no flake to build from either.
|
||||
/// is stale: a rebuild would have no commit to deploy either.
|
||||
pub(crate) fn marker_is_fresh(pin: Option<&str>, stored: Option<&str>) -> bool {
|
||||
pin.is_none_or(|pin| stored == Some(pin))
|
||||
}
|
||||
|
||||
/// The `<flake>#<agent>` ref [`crate::lifecycle::prebuild_toplevel`] builds
|
||||
/// for `rev`: the same flake hive-priv builds, from the same forge URL.
|
||||
pub(crate) fn flake_ref(agent: &str, rev: &str) -> String {
|
||||
flake_ref_at(crate::forge::forge_http_base(), agent, rev)
|
||||
}
|
||||
|
||||
fn flake_ref_at(forge_base: &str, agent: &str, rev: &str) -> String {
|
||||
format!("{}#{agent}", meta_flake_url(forge_base, rev))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -249,13 +232,9 @@ mod tests {
|
|||
head: Option<&'static str>,
|
||||
flake: String,
|
||||
config_head: Option<&'static str>,
|
||||
fetchable: bool,
|
||||
}
|
||||
|
||||
impl MetaSource for Forge {
|
||||
fn nix_can_fetch(&self) -> bool {
|
||||
self.fetchable
|
||||
}
|
||||
async fn meta_head(&self) -> Result<Option<String>> {
|
||||
Ok(self.head.map(str::to_owned))
|
||||
}
|
||||
|
|
@ -313,7 +292,6 @@ mod tests {
|
|||
head: Some(META),
|
||||
flake: flake(),
|
||||
config_head,
|
||||
fetchable: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -369,9 +347,6 @@ mod tests {
|
|||
async fn an_archetype_agent_is_taken_when_the_head_lists_that_archetype() {
|
||||
struct Archetypes(Forge);
|
||||
impl MetaSource for Archetypes {
|
||||
fn nix_can_fetch(&self) -> bool {
|
||||
self.0.nix_can_fetch()
|
||||
}
|
||||
async fn meta_head(&self) -> Result<Option<String>> {
|
||||
self.0.meta_head().await
|
||||
}
|
||||
|
|
@ -422,19 +397,6 @@ mod tests {
|
|||
assert_unpinned(&choose(&source, "rev", None).await.unwrap_err(), "rev");
|
||||
}
|
||||
|
||||
/// A hive without the credential nix's git reads cannot build from the
|
||||
/// repo even though its own token reads it; the first test is the control.
|
||||
#[tokio::test]
|
||||
async fn a_hive_whose_nix_cannot_authenticate_cannot_build() {
|
||||
let mut source = forge(Some(ARGUS_HEAD));
|
||||
source.fetchable = false;
|
||||
let err = choose(&source, "argus", None).await.unwrap_err();
|
||||
assert!(
|
||||
format!("{err:#}").contains("no forge credential"),
|
||||
"{err:#}"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn no_repo_or_no_commit_is_an_error_naming_the_agent() {
|
||||
let mut source = forge(Some(ARGUS_HEAD));
|
||||
|
|
@ -568,12 +530,4 @@ mod tests {
|
|||
assert!(marker_is_fresh(None, Some(STALE)), "no pin to compare with");
|
||||
assert!(marker_is_fresh(None, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_prebuild_ref_is_the_flake_hive_priv_builds() {
|
||||
assert_eq!(
|
||||
flake_ref_at("http://forge.t.local", "argus", META),
|
||||
format!("git+http://forge.t.local/internal/meta.git?rev={META}#argus")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue