feat(admin): open a fresh region from the portal (ADR-0182 section 15)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m31s
Foundation / postgres-tools (push) Successful in 27s
Foundation / server-image (push) Successful in 4m33s
Foundation / image (push) Successful in 5m39s

The Regions page opens the next region in place of the one DEV serves: the
admin API reads the region overlay, its kustomization, the grant broker and the
portal deployment from main at one commit, rewrites only the region id, routes,
genesis commit and seeded wildlife range (refusing files whose layout differs),
commits them in one Gitea multi-file commit as aevolution-bot, then starts a full
Argo sync of exactly that commit. The page follows the sync until the region is
live, across the portal's own restart.

Credentials come from Secret aevolution-admin mounted read-only as files
(--deploy-config); without it the feature stays off. A small OpenSSL HTTPS
client talks to Gitea (verified) and argocd-server (verification per
ARGOCD_TLS_VERIFY). The portal's NetworkPolicy gains egress to the node's
ingress for Gitea and to the argocd-server pods, as approved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-28 13:51:36 -04:00
co-authored by Claude Opus 5.5
parent e0f9512567
commit 9b854e6960
16 changed files with 1317 additions and 14 deletions
+28
View File
@@ -1,6 +1,7 @@
#pragma once
#include "evo/persistence/postgres.hpp"
#include "evo/server/admin/https_client.hpp"
#include "evo/server/broker/access_token.hpp"
#include "evo/server/ops_http.hpp"
@@ -55,6 +56,13 @@
// `key = value` lines, applied to the baseline file or to
// revision REV (which must be the newest: 409 stale_base),
// keeping its comments; then as above
// GET /api/deploy[?argo=1] ADR-0182 section 15: whether opening a region is
// configured, the region Git main serves, the next region
// and its seeded wildlife range, and the Argo Application's
// sync (argo=1: the Argo status only)
// POST /api/deploy/region?region=N[&reason=R] opens region N (the next one) in place of
// the served region: one Gitea commit to the region,
// broker and portal files, then a full Argo sync
namespace evo::server::admin {
struct AdminAsset {
std::string path; // "/index.html", ...; "/" serves "/index.html".
@@ -73,6 +81,18 @@ struct AdminConfig {
std::chrono::milliseconds db_timeout{3000};
std::chrono::milliseconds view_cache{750}; // A fetched view answers repeats this long.
};
// ADR-0182 section 15: where the admin API commits a region switch and what it syncs. The
// tokens come from mounted Secret files and are only ever sent in request headers.
struct AdminDeployConfig {
std::string gitea_base; // https://git.example[:port][/prefix]
std::string gitea_repository; // owner/name
std::string gitea_token;
std::string branch{"main"};
std::string argo_server; // host:port, https assumed
std::string argo_application;
std::string argo_token;
bool argo_verify{true};
};
using AdminConnect = std::function<std::unique_ptr<persistence::Postgres>()>;
// The region's /admin/view body, or nullopt when it cannot be reached or is not ready.
using AdminRegionView = std::function<std::optional<std::string>(std::uint64_t region)>;
@@ -84,6 +104,8 @@ class AdminApi {
// `now_seconds` is wall time (token expiry); `now` paces the view cache.
[[nodiscard]] OpsResponse handle(const ApiRequest& request, std::uint64_t now_seconds,
std::chrono::steady_clock::time_point now);
// Turns on /api/deploy with the given services and transport (tests pass a fake).
void enable_deploy(AdminDeployConfig config, HttpsTransport transport);
private:
[[nodiscard]] OpsResponse api(std::string_view method, std::string_view path,
@@ -109,6 +131,10 @@ class AdminApi {
[[nodiscard]] OpsResponse tuning_text(std::uint64_t revision);
[[nodiscard]] OpsResponse set_tuning(std::string_view query, std::string_view text,
const broker::AccessTokenClaims& admin);
[[nodiscard]] OpsResponse deploy_status(std::string_view query);
[[nodiscard]] OpsResponse open_region(std::string_view query,
const broker::AccessTokenClaims& admin);
[[nodiscard]] std::optional<std::uint64_t> next_region(std::uint64_t served);
[[nodiscard]] std::optional<persistence::PgRows> query(const std::string& sql,
std::vector<std::string> parameters);
@@ -117,6 +143,8 @@ class AdminApi {
AdminConnect connect_;
AdminRegionView view_;
std::vector<AdminAsset> assets_;
std::optional<AdminDeployConfig> deploy_;
HttpsTransport https_;
std::unique_ptr<persistence::Postgres> db_;
struct CachedView {
std::chrono::steady_clock::time_point at;