require k8s: swarm services with a pod run in the cluster only
This commit is contained in:
parent
272af0b3e8
commit
57d40ae8ea
1 changed files with 1044 additions and 3125 deletions
|
|
@ -41,24 +41,20 @@ let
|
|||
deploy.hive-controller.hyperhiveRev = lib.fixedWidthString 40 "b" "";
|
||||
};
|
||||
|
||||
# `allLocal` with the controller's TCP listener on, the one fixture that has
|
||||
# the store, the controller and the gateway together: the two roles, the two
|
||||
# issue grants and the vhost all render from this one option. The firewall is
|
||||
# opened so the lookup that finds the port is shown to find it. Off is
|
||||
# `allLocal` itself.
|
||||
# `allLocal` with the firewall opened for the controller's TCP listener, the one
|
||||
# fixture that has the store, the controller and the gateway together: the two
|
||||
# roles, the two issue grants and the vhost all render from the listener's
|
||||
# option. The firewall is opened so the lookup that finds the port is shown to
|
||||
# find it.
|
||||
allLocalTcp = hiveWithController {
|
||||
deploy.singleHostSwarm = true;
|
||||
swarm.controller.tcp = {
|
||||
enable = true;
|
||||
domain = "controller.t.local";
|
||||
};
|
||||
deploy.swarm-controller.tcp.openFirewall = true;
|
||||
};
|
||||
|
||||
# The listener asked for with nothing to name it by.
|
||||
# A controller on a swarm with no domain, so nothing to name the listener by.
|
||||
tcpNoDomain = hive {
|
||||
deploy.swarm-controller.enable = true;
|
||||
swarm.controller.tcp.enable = true;
|
||||
swarm.domain = lib.mkForce null;
|
||||
};
|
||||
|
||||
bare = shared.bareWithController;
|
||||
|
|
@ -178,10 +174,9 @@ let
|
|||
};
|
||||
|
||||
# A container the operator runs that hyperhive doesn't own, next to one it
|
||||
# does (the classifier's).
|
||||
# does (the secret store's).
|
||||
withForeignContainer = hiveWith [ { containers.operator-box.config = { }; } ] {
|
||||
deploy.bao.enable = true;
|
||||
deploy.review-classifier.enable = true;
|
||||
};
|
||||
|
||||
# On the store's host, which mints the runner's store identity.
|
||||
|
|
@ -196,13 +191,6 @@ let
|
|||
deploy.review-classifier.enable = true;
|
||||
};
|
||||
|
||||
# The same classifier on a host that runs a hive: its metrics path is the
|
||||
# same as without one.
|
||||
withClassifierOnHive = hiveWithController {
|
||||
deploy.bao.enable = true;
|
||||
deploy.review-classifier.enable = true;
|
||||
};
|
||||
|
||||
# The host fetches that restart their consumer when the store's value
|
||||
# changes (../host-modules/lib/refresh-consumer.nix), each on a fixture
|
||||
# that renders it.
|
||||
|
|
@ -817,11 +805,10 @@ let
|
|||
ok =
|
||||
let
|
||||
l = allLocal.services.nginx.virtualHosts."t.local".locations;
|
||||
socket = allLocal.services.hyperhive.deploy.swarm-controller.socketPath;
|
||||
in
|
||||
lib.hasInfix "auth_request /__hive_authelia;" l."/api/".extraConfig
|
||||
&& lib.hasInfix socket l."/api/".proxyPass
|
||||
&& lib.hasInfix socket l."/webhook/forge/".proxyPass
|
||||
&& lib.hasInfix "swarm_controller_upstream" l."/api/".proxyPass
|
||||
&& lib.hasInfix "swarm_controller_upstream" l."/webhook/forge/".proxyPass
|
||||
&& !(lib.hasInfix "auth_request" l."/webhook/forge/".extraConfig);
|
||||
}
|
||||
{
|
||||
|
|
@ -1004,23 +991,24 @@ let
|
|||
ok = forceServiceConfigs withCi.containers.swarm-ci-runner.config;
|
||||
}
|
||||
{
|
||||
# It spends money on an operator's key, so no host runs it by default.
|
||||
name = "the review classifier's container exists only where its host enables it";
|
||||
# It spends money on an operator's key, so no host runs it by default, and
|
||||
# where one does it is a pod: no container.
|
||||
name = "the review classifier is enabled only where its host asks, and runs as a pod";
|
||||
ok =
|
||||
!(bare.containers ? swarm-review-classifier)
|
||||
&& !(centralToggleOff.containers ? swarm-review-classifier)
|
||||
&& withClassifier.containers ? swarm-review-classifier;
|
||||
!bare.services.hyperhive.deploy.review-classifier.enable
|
||||
&& !centralToggleOff.services.hyperhive.deploy.review-classifier.enable
|
||||
&& withClassifier.services.hyperhive.deploy.review-classifier.enable
|
||||
&& !(withClassifier.containers ? swarm-review-classifier);
|
||||
}
|
||||
{
|
||||
# The daemon holds its store leaf, handed in by nspawn without a copy on
|
||||
# disk, and nothing else from the host; a key is read per run and
|
||||
# reaches only the model child's environment. Reading the claude path
|
||||
# also evaluates the container's unfree allowance.
|
||||
name = "the review classifier loads only its store leaf and carries no API or provider key in its unit";
|
||||
name = "the review classifier's unit names only its store leaf and carries no API or provider key";
|
||||
ok =
|
||||
let
|
||||
svc =
|
||||
withClassifier.containers.swarm-review-classifier.config.systemd.services.swarm-review-classifier;
|
||||
svc = withClassifier.services.hyperhive.deploy.review-classifier.unit;
|
||||
env = svc.environment;
|
||||
in
|
||||
lib.elem "review-classifier-bao-key" svc.serviceConfig.LoadCredential
|
||||
|
|
@ -1031,44 +1019,12 @@ let
|
|||
&& lib.hasSuffix "/bin/opencode" env.SWARM_REVIEW_CLASSIFIER_OPENCODE
|
||||
&& !(env ? ANTHROPIC_API_KEY)
|
||||
&& !(env ? ACP_PROVIDER_API_KEY)
|
||||
&& lib.elem "--load-credential=review-classifier-bao-key:/var/lib/swarm-bao-pki/review-classifier-key.pem" (
|
||||
withClassifier.containers.swarm-review-classifier.extraFlags
|
||||
)
|
||||
# No host unit copies the leaf into the container's root.
|
||||
&& !(lib.any (u: lib.hasInfix "nixos-containers/swarm-review-classifier" (u.script or "")) (
|
||||
lib.attrValues withClassifier.systemd.services
|
||||
));
|
||||
}
|
||||
{
|
||||
# The collector the classifier's metrics reach is the container's own
|
||||
# forwarder, which holds the service's client, so the path is the same
|
||||
# with or without a hive on the host. The logs pipeline is the control
|
||||
# that the lookup finds what is there.
|
||||
name = "the review classifier pushes its metrics to the swarm collector through its own forwarder, with or without a hive";
|
||||
ok =
|
||||
let
|
||||
check =
|
||||
h:
|
||||
let
|
||||
c = h.containers.swarm-review-classifier.config;
|
||||
s = c.services.opentelemetry-collector.settings;
|
||||
otel = h.services.hyperhive.swarm.otel;
|
||||
in
|
||||
c.systemd.services.swarm-review-classifier.environment.OTEL_EXPORTER_OTLP_ENDPOINT
|
||||
== "http://127.0.0.1:4318"
|
||||
&& s.receivers.otlp.protocols.http.endpoint == "127.0.0.1:4318"
|
||||
&& s.service.pipelines.metrics.receivers == [ "otlp" ]
|
||||
&& s.service.pipelines.metrics.exporters == [ "otlphttp" ]
|
||||
&& s.exporters.otlphttp.endpoint == "https://${otel.domain}/swarm-review-classifier"
|
||||
&& s.exporters.otlphttp.auth.authenticator == "oauth2client/swarm"
|
||||
&& s.service.pipelines.logs.receivers == [ "journald" ];
|
||||
in
|
||||
check withClassifier && check withClassifierOnHive;
|
||||
&& !(withClassifier.systemd.services ? swarm-review-classifier);
|
||||
}
|
||||
{
|
||||
# The runner serves its Prometheus endpoint on loopback in its own
|
||||
# netns, and the container's forwarder scrapes exactly that address into
|
||||
# a pipeline that leaves through the swarm exporter. The classifier's
|
||||
# a pipeline that leaves through the swarm exporter.
|
||||
# forwarder, which sets no extra targets, is the control: no extra
|
||||
# receiver, no extra pipeline.
|
||||
name = "the CI runner's built-in metrics are scraped on loopback by its forwarder";
|
||||
|
|
@ -1076,8 +1032,6 @@ let
|
|||
let
|
||||
cc = withCi.containers.swarm-ci-runner.config;
|
||||
s = cc.services.opentelemetry-collector.settings;
|
||||
c =
|
||||
withClassifier.containers.swarm-review-classifier.config.services.opentelemetry-collector.settings;
|
||||
runner = cc.services.gitea-actions-runner.instances.swarm.settings;
|
||||
in
|
||||
runner.metrics.enabled == true
|
||||
|
|
@ -1091,21 +1045,7 @@ let
|
|||
]
|
||||
&& s.service.pipelines."metrics/extra".receivers == [ "prometheus/extra" ]
|
||||
&& s.service.pipelines."metrics/extra".exporters == [ "otlphttp" ]
|
||||
&& s.exporters ? otlphttp
|
||||
&& !(c.receivers ? "prometheus/extra")
|
||||
&& !(c.service.pipelines ? "metrics/extra");
|
||||
}
|
||||
{
|
||||
# Only the classifier asks the forwarder for a metrics receiver; the
|
||||
# others carry a journal. The classifier is the control.
|
||||
name = "a service forwarder without an OTLP port has no metrics pipeline";
|
||||
ok =
|
||||
let
|
||||
s = withCi.containers.swarm-ci-runner.config.services.opentelemetry-collector.settings;
|
||||
c =
|
||||
withClassifier.containers.swarm-review-classifier.config.services.opentelemetry-collector.settings;
|
||||
in
|
||||
c.service.pipelines ? metrics && !(s.service.pipelines ? metrics) && !(s.receivers ? otlp);
|
||||
&& s.exporters ? otlphttp;
|
||||
}
|
||||
{
|
||||
# The hive tier is the labelling point for a hive's telemetry, so it runs
|
||||
|
|
@ -1127,15 +1067,6 @@ let
|
|||
&& lib.elem "hive-collector.hive" bare.services.hyperhive.gateway.localNames
|
||||
&& !(lib.elem "hive-collector.hive" shared.servicesHere.services.hyperhive.gateway.localNames);
|
||||
}
|
||||
{
|
||||
# See the same case in ./builder.nix.
|
||||
name = "the review classifier's container runs the leaf-minting unit before every start";
|
||||
ok =
|
||||
let
|
||||
c = withClassifier.systemd.services."container@swarm-review-classifier";
|
||||
in
|
||||
lib.elem "swarm-bao-pki.service" c.wants && lib.elem "swarm-bao-pki.service" c.after;
|
||||
}
|
||||
{
|
||||
# The collector reaches these routes through the gateway now, so each
|
||||
# store needs an ingest location of its own. Without one the write rides
|
||||
|
|
@ -2504,7 +2435,7 @@ let
|
|||
&&
|
||||
old.containers.swarm-builder.config.systemd.services.swarm-builder.environment.SWARM_BUILDER_NIXPKGS_FLAKE
|
||||
== "path:/legacy/nixpkgs"
|
||||
&& (locs sw.nats.domain)."= /metrics".proxyPass == "http://127.0.0.1:17777/metrics"
|
||||
&& lib.hasInfix ":17777;" (locs sw.nats.domain)."= /metrics".extraConfig
|
||||
&& old.containers.hive-matrix.config.services.matrix-tuwunel.settings.global.allow_encryption
|
||||
&& lib.all warned [
|
||||
"swarm.controller.queue.natsUrl"
|
||||
|
|
@ -2539,7 +2470,7 @@ let
|
|||
&& h.deploy.nats.monitorPort == 8222
|
||||
&& h.deploy.nats.otel.telemetryPort == 8891
|
||||
&& h.deploy.swarm-otel.telemetryPort == 8889
|
||||
&& (locs h.swarm.nats.domain)."= /metrics".proxyPass == "http://127.0.0.1:7777/metrics"
|
||||
&& lib.hasInfix ":7777;" (locs h.swarm.nats.domain)."= /metrics".extraConfig
|
||||
&&
|
||||
(locs h.swarm.victorialogs.domain)."= /metrics".proxyPass
|
||||
== "http://unix:/run/swarm-victorialogs/victorialogs.sock:/metrics"
|
||||
|
|
@ -2938,13 +2869,8 @@ let
|
|||
"swarm-authelia"
|
||||
"swarm-bao"
|
||||
"swarm-builder"
|
||||
"swarm-claude-login"
|
||||
"swarm-grafana"
|
||||
"swarm-nats"
|
||||
"swarm-notify-router"
|
||||
"swarm-otel"
|
||||
"swarm-review-classifier"
|
||||
"swarm-stt"
|
||||
"swarm-victorialogs"
|
||||
"swarm-victoriametrics"
|
||||
]
|
||||
|
|
@ -3007,9 +2933,7 @@ let
|
|||
lib.attrNames withForeignContainer.containers == [
|
||||
"operator-box"
|
||||
"swarm-bao"
|
||||
"swarm-review-classifier"
|
||||
]
|
||||
&& lib.length (checks "swarm-review-classifier") == 1
|
||||
&& lib.length (checks "swarm-bao") == 1
|
||||
&& checks "operator-box" == [ ];
|
||||
}
|
||||
|
|
@ -3127,42 +3051,6 @@ let
|
|||
mentions "privateListenAddresses holds"
|
||||
&& !(mentions "while services.hyperhive.gateway.privateListenAddresses is empty");
|
||||
}
|
||||
{
|
||||
# The off arm of the controller's TCP listener: a host that never set it
|
||||
# renders what it rendered before it existed. The gateway still reaches
|
||||
# the controller by socket, nothing TCP-shaped is rendered, and the
|
||||
# store writes neither role nor grant. The `swarm-services-cert` unit is
|
||||
# the presence control for the unit lookup, and the socket in
|
||||
# `proxyPass` for the location lookup.
|
||||
name = "a swarm without the controller's TCP listener renders the socket-only controller";
|
||||
ok =
|
||||
let
|
||||
m = allLocal;
|
||||
l = m.services.nginx.virtualHosts."t.local".locations;
|
||||
socket = "http://unix:${m.services.hyperhive.deploy.swarm-controller.socketPath}:";
|
||||
env = m.systemd.services.swarm-controller.environment;
|
||||
policies = m.systemd.services.swarm-bao-controller-policy.script;
|
||||
issuer = m.systemd.services.swarm-bao-services-issuer-policy.script;
|
||||
in
|
||||
l."/api/".proxyPass == socket
|
||||
&& l."/webhook/forge/".proxyPass == socket
|
||||
&& !(lib.hasInfix "proxy_ssl_certificate" l."/api/".extraConfig)
|
||||
&& !(lib.hasInfix "proxy_ssl" l."/webhook/forge/".extraConfig)
|
||||
&& !(m.systemd.services ? swarm-controller-tls)
|
||||
&& !(m.systemd.services ? swarm-controller-gateway-client)
|
||||
&& !(m.systemd.timers ? swarm-controller-tls)
|
||||
&& !(m.systemd.timers ? swarm-controller-gateway-client)
|
||||
&& m.systemd.services ? swarm-services-cert
|
||||
&& !(lib.any (lib.hasPrefix "SWARM_CONTROLLER_TCP_") (lib.attrNames env))
|
||||
&& !(lib.elem 9443 m.networking.firewall.allowedTCPPorts)
|
||||
&& !(lib.hasInfix "swarm-controller-tls" policies)
|
||||
&& !(lib.hasInfix "swarm-controller-gateway-client" policies)
|
||||
&& !(lib.hasInfix "swarm-controller-gateway-client" issuer)
|
||||
&& lib.hasInfix "issue/swarm-services" issuer
|
||||
&& env.SWARM_CONTROLLER_PUBLIC_URL == "https://t.local"
|
||||
&& m.services.hyperhive.deploy.swarm-controller.tcp.openFirewall == false
|
||||
&& allLocalTcp.services.hyperhive.deploy.swarm-controller.tcp.openFirewall == true;
|
||||
}
|
||||
{
|
||||
# The on arm. The gateway dials the listener by name over TLS, verified,
|
||||
# with the client leaf, and keeps the operator gate on `/api/` and the
|
||||
|
|
@ -3175,7 +3063,7 @@ let
|
|||
let
|
||||
m = allLocalTcp;
|
||||
l = m.services.nginx.virtualHosts."t.local".locations;
|
||||
upstream = "https://controller.t.local:9443";
|
||||
upstream = "https://\$swarm_controller_upstream";
|
||||
tls = m.services.hyperhive.deploy.hive-controller.tls.stateDir;
|
||||
env = m.systemd.services.swarm-controller.environment;
|
||||
dialled =
|
||||
|
|
@ -3203,8 +3091,9 @@ let
|
|||
&& env.SWARM_CONTROLLER_TCP_CLIENT_NAME == "gateway-client.t.local"
|
||||
&& lib.elem 9443 m.networking.firewall.allowedTCPPorts
|
||||
&& env.SWARM_CONTROLLER_PUBLIC_URL == "https://t.local"
|
||||
&& m.systemd.services.swarm-controller-tls.wantedBy == [ "multi-user.target" ]
|
||||
&& lib.elem "swarm-controller-tls.service" m.systemd.services.swarm-controller.after;
|
||||
# The listener's leaf is the pod's, so the host has no unit for it.
|
||||
&& !(m.systemd.services ? swarm-controller-tls)
|
||||
&& !(m.systemd.timers ? swarm-controller-tls);
|
||||
}
|
||||
{
|
||||
# The two roles carry opposite flag pairs, which is the whole reason the
|
||||
|
|
@ -3260,7 +3149,7 @@ let
|
|||
&& allLocalTcp.systemd.timers ? swarm-controller-gateway-client;
|
||||
}
|
||||
{
|
||||
name = "the controller's TCP listener is refused at eval with no name to dial it by";
|
||||
name = "the controller is refused at eval where no swarm domain names its listener";
|
||||
ok =
|
||||
let
|
||||
fired = lib.filter (a: !a.assertion) tcpNoDomain.assertions;
|
||||
|
|
|
|||
Loading…
Reference in a new issue