Watch
0
0
Fork
You've already forked hyperhive
0

seed a hyperhive/hyperhive mirror so update_meta finds it on a fresh swarm

This commit is contained in:
atlas 2026-11-09 12:19:46 +01:00
commit a6b5bafa83
2 changed files with 173 additions and 15 deletions

View file

@ -311,6 +311,8 @@ struct TeamState {
struct RepoState {
private: bool,
empty: bool,
/// A pull-mirror. A plain repo at a mirror's `dest` is left as it is.
mirror: bool,
mirror_interval: Option<String>,
}
@ -485,7 +487,9 @@ fn plan(desired: &Desired, observed: &Observed) -> Vec<Action> {
repo: m.repo.clone(),
upstream: m.upstream.clone(),
}),
Seen::Present(s) if s.mirror_interval.as_deref() != Some(MIRROR_INTERVAL) => {
Seen::Present(s)
if s.mirror && s.mirror_interval.as_deref() != Some(MIRROR_INTERVAL) =>
{
actions.push(Action::SetMirrorInterval {
owner: m.owner.clone(),
repo: m.repo.clone(),
@ -697,6 +701,7 @@ impl Client {
|r| RepoState {
private: r.private.unwrap_or(false),
empty: r.empty.unwrap_or(false),
mirror: r.mirror.unwrap_or(false),
mirror_interval: r.mirror_interval,
},
);
@ -1191,10 +1196,18 @@ mod tests {
RepoState {
private,
empty,
mirror: false,
mirror_interval: interval.map(str::to_owned),
}
}
fn mirror_state(interval: Option<&str>) -> RepoState {
RepoState {
mirror: true,
..repo_state(false, false, interval)
}
}
/// Every object of [`desired`] present with its desired settings.
fn converged() -> Observed {
let mut o = Observed::default();
@ -1218,7 +1231,7 @@ mod tests {
);
o.repos.insert(
key("actions", "checkout"),
Seen::Present(repo_state(false, false, Some(MIRROR_INTERVAL))),
Seen::Present(mirror_state(Some(MIRROR_INTERVAL))),
);
o.avatar_set = true;
o
@ -1299,7 +1312,7 @@ mod tests {
);
o.repos.insert(
(s("actions"), s("checkout")),
Seen::Present(repo_state(false, false, None)),
Seen::Present(mirror_state(None)),
);
o.avatar_set = false;
assert_eq!(
@ -1329,6 +1342,28 @@ mod tests {
);
}
#[test]
fn a_plain_repo_at_a_mirror_dest_is_left_alone() {
let mut o = converged();
o.repos.insert(
(s("actions"), s("checkout")),
Seen::Present(repo_state(false, false, None)),
);
assert_eq!(plan(&desired(), &o), Vec::new());
// Control: the same repo as a mirror with no interval is patched.
o.repos.insert(
(s("actions"), s("checkout")),
Seen::Present(mirror_state(None)),
);
assert_eq!(
plan(&desired(), &o),
vec![Action::SetMirrorInterval {
owner: s("actions"),
repo: s("checkout"),
}]
);
}
#[test]
fn an_unreadable_object_gets_no_write() {
let mut o = nothing();

View file

@ -40,6 +40,15 @@ const REV_FILE: &str = "/etc/hyperhive/swarm-controller.json";
const HYPERHIVE_OWNER: &str = "hyperhive";
const HYPERHIVE_REPO: &str = "hyperhive";
/// The error for a swarm forge with no readable hyperhive repo, naming the nix
/// option that mirrors one there.
fn missing_hyperhive() -> String {
format!(
"{HYPERHIVE_OWNER}/{HYPERHIVE_REPO} is empty or absent on the swarm forge; \
services.hyperhive.deploy.forgejo.hyperhiveUpstream mirrors it there"
)
}
/// What every agent of the swarm gets, the same on every hive.
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
@ -365,8 +374,9 @@ async fn hyperhive_pin(
let Some(flake) = committed_flake else {
let head = forge
.head_files(HYPERHIVE_OWNER, HYPERHIVE_REPO, None, &[])
.await?
.with_context(|| format!("{HYPERHIVE_OWNER}/{HYPERHIVE_REPO} is empty or absent"))?;
.await
.with_context(missing_hyperhive)?
.with_context(missing_hyperhive)?;
return Ok(HyperhivePin {
rev: head.commit,
moved: false,
@ -841,6 +851,29 @@ mod tests {
);
}
#[tokio::test]
async fn a_forge_without_hyperhive_names_the_option_that_mirrors_it() {
let mut forge = forge_with(&[]);
forge.repos.remove("hyperhive/hyperhive");
let err = update(
&forge,
&FakeLocker::locked(),
&settings(),
None,
&argus_and_reviewer(),
&[],
)
.await
.unwrap_err();
let err = format!("{err:#}");
assert!(
err.contains("hyperhive/hyperhive is empty or absent")
&& err.contains("services.hyperhive.deploy.forgejo.hyperhiveUpstream"),
"{err}"
);
assert!(forge.commits.lock().unwrap().is_empty());
}
#[tokio::test]
async fn a_refused_lock_commits_nothing() {
let forge = forge_with(&[]);