swarm-controller: set_agent_state takes the placement sub-state and the forge

This commit is contained in:
atlas 2026-11-30 13:27:17 +01:00
commit c79c894ebe
3 changed files with 116 additions and 53 deletions

View file

@ -879,7 +879,7 @@ mod tests {
.await
.expect("seed");
crate::egress_allow::clear_on_destroy(&state, "pr1ma", "atlas").await;
crate::egress_allow::clear_on_destroy(state.status.as_ref(), "pr1ma", "atlas").await;
assert_eq!(list_of(&client).await, [manual("crates.io", "iris")]);
}

View file

@ -14,6 +14,8 @@
//! refused when the proxy already allows it to everyone. The names the proxy
//! always allows are the ones in [`ENV_BASE_DOMAINS`].
use std::sync::Arc;
use axum::Json;
use axum::extract::State;
use axum::http::StatusCode;
@ -22,9 +24,10 @@ use swarm_controller_api::egress::{AllowedDomain, AllowedDomains};
use swarm_queue_client::egress_allow;
use swarm_wire::egress_allow::{AllowList, Entry, KEY, MAX_ENTRIES, covered_by, normalize_domain};
use crate::routes::{AppState, error_problem, wanted_error_status};
use crate::schedules::{live_of, queue, queue_of, read_or_default, refused, write_revision};
use crate::routes::{error_problem, wanted_error_status};
use crate::schedules::{live_of, queue_of, read_or_default, refused, write_revision};
use crate::secrets::SecretsState;
use crate::status::StatusReader;
/// How many times a losing writer re-reads and re-applies, as in
/// `wanted::MAX_ATTEMPTS`.
@ -345,9 +348,9 @@ pub(crate) async fn modify(
/// is free again once its agent is destroyed, and the next agent of that name
/// would inherit what it left. A failure is logged and does not stop the
/// destroy, as in `agent_permissions::clear_on_destroy`.
pub(crate) async fn clear_on_destroy(state: &AppState, hive: &str, agent: &str) {
pub(crate) async fn clear_on_destroy(status: Option<&Arc<StatusReader>>, hive: &str, agent: &str) {
let cleared = async {
let client = queue(state).map_err(|(_, why)| anyhow::anyhow!(why))?;
let client = queue_of(status).map_err(|(_, why)| anyhow::anyhow!(why))?;
modify(&client, |mut list| {
list.entries.retain(|e| e.agent.as_deref() != Some(agent));
list
@ -371,6 +374,7 @@ pub(crate) async fn clear_on_destroy(state: &AppState, hive: &str, agent: &str)
mod tests {
use super::*;
use crate::agent_limits::tests::{declared, state};
use crate::routes::AppState;
use crate::test_nats::TestNats;
use axum::extract::FromRef as _;

View file

@ -23,6 +23,8 @@
//! (`swarm_wire::hive_status::EGRESS_DENY_APPLIED`); [`behind`] names the hives
//! whose report does not match, which the reads show as `behind`.
use std::sync::Arc;
use axum::Json;
use axum::extract::State;
use axum::http::StatusCode;
@ -32,10 +34,10 @@ use swarm_queue_client::egress_allow;
use swarm_wire::egress_allow::{DENY_KEY, DenyEntry, DenyList, MAX_ENTRIES, normalize_domain};
use swarm_wire::hive_status::egress_deny_applied;
use crate::routes::{AppState, error_problem, wanted_error_status};
use crate::schedules::{live_of, queue, queue_of, read_or_default, refused, write_revision};
use crate::routes::{error_problem, wanted_error_status};
use crate::schedules::{live_of, queue_of, read_or_default, refused, write_revision};
use crate::secrets::SecretsState;
use crate::status::{Freshness, HiveStatus};
use crate::status::{Freshness, HiveStatus, StatusReader};
/// How many times a losing writer re-reads and re-applies, as in
/// `egress_allow::MAX_ATTEMPTS`.
@ -306,9 +308,9 @@ pub(crate) async fn remove_denied_domain(
/// is destroyed, and the next agent of that name would inherit what it left. A
/// list that was never written stays unwritten. A failure is logged and does
/// not stop the destroy, as in `egress_allow::clear_on_destroy`.
pub(crate) async fn clear_on_destroy(state: &AppState, hive: &str, agent: &str) {
pub(crate) async fn clear_on_destroy(status: Option<&Arc<StatusReader>>, hive: &str, agent: &str) {
let cleared = async {
let client = queue(state).map_err(|(_, why)| anyhow::anyhow!(why))?;
let client = queue_of(status).map_err(|(_, why)| anyhow::anyhow!(why))?;
let Some(store) = egress_allow::open(&client).await? else {
return Ok(());
};
@ -345,6 +347,7 @@ pub(crate) async fn clear_on_destroy(state: &AppState, hive: &str, agent: &str)
mod tests {
use super::*;
use crate::agent_limits::tests::{declared, state};
use crate::routes::AppState;
use crate::test_nats::TestNats;
use axum::extract::FromRef as _;
use swarm_wire::hive_status::EGRESS_DENY_APPLIED;
@ -695,7 +698,7 @@ mod tests {
add(&state, "evil.com", None).await.expect("swarm-wide");
add(&state, "bad.io", Some("atlas")).await.expect("atlas's");
clear_on_destroy(&state, "pr1ma", "atlas").await;
clear_on_destroy(state.status.as_ref(), "pr1ma", "atlas").await;
assert_eq!(listed(&state).await, [("evil.com".to_owned(), None)]);
}