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
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:
@@ -30,8 +30,10 @@ class JsonValue {
|
||||
[[nodiscard]] const JsonValue* member(std::string_view name) const;
|
||||
[[nodiscard]] const std::vector<JsonValue>* array() const;
|
||||
|
||||
// Whole-document parse; nullopt for anything malformed or out of bounds.
|
||||
[[nodiscard]] static std::optional<JsonValue> parse(std::string_view text);
|
||||
// Whole-document parse; nullopt for anything malformed or out of bounds. `limit` bounds
|
||||
// the text: access tokens and keys keep the default; a service's answer may allow more.
|
||||
[[nodiscard]] static std::optional<JsonValue> parse(std::string_view text,
|
||||
std::size_t limit = max_json_bytes);
|
||||
|
||||
private:
|
||||
friend class JsonParser;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// ADR-0182 section 15: a bounded, blocking HTTPS/1.1 client for the admin API's two outbound
|
||||
// services (Gitea and Argo CD). One request per connection (Connection: close); the system
|
||||
// trust store and host name check unless `verify` is false. Credentials travel only in the
|
||||
// request headers and are never logged.
|
||||
namespace evo::server::admin {
|
||||
struct HttpsRequest {
|
||||
std::string host;
|
||||
std::uint16_t port{443};
|
||||
std::string method{"GET"};
|
||||
std::string target{"/"}; // Path and query, already percent-encoded.
|
||||
std::vector<std::pair<std::string, std::string>> headers;
|
||||
std::string body;
|
||||
bool verify{true};
|
||||
std::chrono::milliseconds timeout{10'000};
|
||||
std::size_t limit{std::size_t{4} << 20U}; // Largest body accepted.
|
||||
};
|
||||
struct HttpsResponse {
|
||||
int status{};
|
||||
std::string body;
|
||||
};
|
||||
// The transport the admin API uses; tests substitute a fake.
|
||||
using HttpsTransport = std::function<std::optional<HttpsResponse>(const HttpsRequest&)>;
|
||||
|
||||
// Sends `request` over TLS: the answer, or nullopt on any connection, TLS, timeout, size or
|
||||
// framing failure.
|
||||
[[nodiscard]] std::optional<HttpsResponse> https_request(const HttpsRequest& request);
|
||||
// An HTTP/1.1 response read to the end of the connection: the status and the body (by
|
||||
// Content-Length, chunked, or to the end), or nullopt when malformed or over `limit`.
|
||||
[[nodiscard]] std::optional<HttpsResponse> parse_http_response(std::string_view raw,
|
||||
std::size_t limit);
|
||||
// "https://host[:port][/...]" split into host, port and the path prefix (no trailing slash).
|
||||
struct HttpsBase {
|
||||
std::string host;
|
||||
std::uint16_t port{443};
|
||||
std::string prefix;
|
||||
};
|
||||
[[nodiscard]] std::optional<HttpsBase> parse_https_base(std::string_view url);
|
||||
} // namespace evo::server::admin
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
// ADR-0182 section 15: the admin portal opens a fresh region in place of the one DEV serves.
|
||||
// The change is four Git files edited in place: the region overlay's values (world, region,
|
||||
// life routes, the opening's genesis commit and seeded wildlife range, both for the region
|
||||
// Deployment and its provision Job), its kustomization header, and the region named by the
|
||||
// grant broker's routes and the admin portal. Anything else is left exactly as it is; a file
|
||||
// whose layout differs from the expected lines is refused rather than guessed at.
|
||||
namespace evo::server::admin {
|
||||
inline constexpr std::array<std::string_view, 4> region_switch_paths{
|
||||
"deploy/kubernetes/region/dev/region-values.yaml",
|
||||
"deploy/kubernetes/region/dev/kustomization.yaml",
|
||||
"deploy/kubernetes/grant-broker-dev/deployment.yaml",
|
||||
"deploy/kubernetes/admin-portal-dev/deployment.yaml",
|
||||
};
|
||||
// The four files' text, in region_switch_paths order.
|
||||
using RegionSwitchFiles = std::array<std::string, 4>;
|
||||
// What the files say DEV serves: the world and region, the opening's genesis commit (32
|
||||
// lowercase hex digits) and the first seeded wildlife identity.
|
||||
struct RegionLayout {
|
||||
std::uint64_t world{}, region{};
|
||||
std::string commit;
|
||||
std::uint64_t wildlife_first{};
|
||||
auto operator<=>(const RegionLayout&) const = default;
|
||||
};
|
||||
// The served layout, or the name of the line that is missing, repeated or inconsistent.
|
||||
[[nodiscard]] std::expected<RegionLayout, std::string>
|
||||
read_region_layout(const RegionSwitchFiles& files);
|
||||
// The files serving `to` (same world) instead, with `note` (one line, no line breaks) recorded
|
||||
// as a comment above the opening; or why the files or `to` cannot be switched.
|
||||
[[nodiscard]] std::expected<RegionSwitchFiles, std::string>
|
||||
switch_region(const RegionSwitchFiles& files, const RegionLayout& to, std::string_view note);
|
||||
} // namespace evo::server::admin
|
||||
Reference in New Issue
Block a user