k8s: the queue's pod mounts the host unit's store in place
This commit is contained in:
parent
a793df9708
commit
140ee7f38a
2 changed files with 267 additions and 155 deletions
|
|
@ -115,7 +115,6 @@ let
|
|||
config:
|
||||
lib.recursiveUpdate config {
|
||||
services.hyperhive.deploy = {
|
||||
nats.k8s.freshState = true;
|
||||
swarm-controller.k8s.freshState = true;
|
||||
};
|
||||
};
|
||||
|
|
@ -1595,7 +1594,7 @@ let
|
|||
# Everything of the pod is read off the manifest the module renders. The
|
||||
# `tmp` volume is the control that the lookup of a volume's medium finds
|
||||
# a plain one.
|
||||
name = "the queue's pod is one replaced copy of the responder, the server and the exporter, started after the state gate, the leaf and the callout config";
|
||||
name = "the queue's pod is one replaced copy of the responder, the server and the exporter, started after the leaf and the callout config, on the host unit's own store directory";
|
||||
ok =
|
||||
let
|
||||
o = objects."swarm-nats/deployment";
|
||||
|
|
@ -1603,6 +1602,8 @@ let
|
|||
named = n: lib.findFirst (c: c.name == n) { } spec.containers;
|
||||
volume = n: lib.findFirst (v: v.name == n) null spec.volumes;
|
||||
pvc = objects."swarm-nats/persistentvolumeclaim";
|
||||
pv = objects."swarm-nats/persistentvolume";
|
||||
hostStore = "/var/lib/nixos-containers/swarm-nats/var/lib/nats";
|
||||
env = envOf "swarm-nats";
|
||||
in
|
||||
o.spec.replicas == 1
|
||||
|
|
@ -1624,7 +1625,6 @@ let
|
|||
)
|
||||
&&
|
||||
map (c: c.name) spec.initContainers == [
|
||||
"state-gate"
|
||||
"tls-issue"
|
||||
"callout-config"
|
||||
]
|
||||
|
|
@ -1686,6 +1686,32 @@ let
|
|||
&& !((volume "tmp").emptyDir ? medium)
|
||||
&& (volume "nats-data").persistentVolumeClaim.claimName == pvc.metadata.name
|
||||
&& pvc.spec.accessModes == [ "ReadWriteOnce" ]
|
||||
# The claim binds by name the static local volume on the container's
|
||||
# store directory, on this node, and only that: its class is its own.
|
||||
# The controller's claim is the control that a claim does not.
|
||||
&& pvc.spec.volumeName == pv.metadata.name
|
||||
&& pvc.spec.storageClassName == pv.spec.storageClassName
|
||||
&& pv.spec.storageClassName != ""
|
||||
&& !(objects."swarm-controller/persistentvolumeclaim".spec ? volumeName)
|
||||
&& pv.spec.local.path == hostStore
|
||||
&& pv.spec.persistentVolumeReclaimPolicy == "Retain"
|
||||
&& !(pv.metadata ? namespace)
|
||||
&&
|
||||
pv.spec.nodeAffinity.required.nodeSelectorTerms == [
|
||||
{
|
||||
matchExpressions = [
|
||||
{
|
||||
key = "kubernetes.io/hostname";
|
||||
operator = "In";
|
||||
values = [ (lib.toLower allLocal.networking.hostName) ];
|
||||
}
|
||||
];
|
||||
}
|
||||
]
|
||||
# A pod on a host that never ran the container gets the directory made;
|
||||
# a host with the container needs no rule.
|
||||
&& lib.any (lib.hasPrefix "d ${hostStore} ") onCluster.systemd.tmpfiles.rules
|
||||
&& !(lib.any (lib.hasPrefix "d ${hostStore} ") withNode.systemd.tmpfiles.rules)
|
||||
&& !(lib.any (c: c ? resources) spec.containers)
|
||||
&& !(lib.any (v: v ? secret) spec.volumes);
|
||||
}
|
||||
|
|
@ -1713,21 +1739,19 @@ let
|
|||
volume = "state";
|
||||
option = "deploy.swarm-controller.k8s.freshState";
|
||||
};
|
||||
swarm-nats = {
|
||||
path = "/var/lib/nats";
|
||||
volume = "nats-data";
|
||||
option = "deploy.nats.k8s.freshState";
|
||||
};
|
||||
};
|
||||
# The poller keeps a claim for its cursor and the speech-to-text pod
|
||||
# keeps none; neither is gated.
|
||||
# The poller keeps a claim for its cursor and the queue one on the host's
|
||||
# directory; the speech-to-text pod keeps none. None is gated.
|
||||
unclaimed = [
|
||||
"swarm-notify-router"
|
||||
"swarm-review-classifier"
|
||||
"swarm-claude-login"
|
||||
"swarm-stt"
|
||||
];
|
||||
ungated = unclaimed ++ [ "swarm-ci-metrics" ];
|
||||
ungated = unclaimed ++ [
|
||||
"swarm-ci-metrics"
|
||||
"swarm-nats"
|
||||
];
|
||||
one =
|
||||
name: g:
|
||||
let
|
||||
|
|
@ -1861,9 +1885,9 @@ let
|
|||
services = (migrateOf withNode).services;
|
||||
stateful = [
|
||||
"swarm-controller"
|
||||
"swarm-nats"
|
||||
];
|
||||
stateless = [
|
||||
"swarm-nats"
|
||||
"swarm-notify-router"
|
||||
"swarm-review-classifier"
|
||||
"swarm-claude-login"
|
||||
|
|
@ -1908,8 +1932,8 @@ let
|
|||
in
|
||||
(migrateOf withNode).namespace == "hyperhive"
|
||||
&& host.swarm-controller.state.hostPath == "/var/lib/swarm-controller"
|
||||
&& host.swarm-nats.state.hostPath == "/var/lib/nixos-containers/swarm-nats/var/lib/nats"
|
||||
&& host.swarm-nats.state.mount == "/var/lib/nats"
|
||||
# The queue's store is mounted in place, so nothing is copied.
|
||||
&& host.swarm-nats.state == null
|
||||
&& host.swarm-ci-metrics.state == null
|
||||
&& host.swarm-stt.state == null
|
||||
&&
|
||||
|
|
@ -1922,7 +1946,7 @@ let
|
|||
&& lib.all (s: s.runtime == "host") (lib.attrValues host)
|
||||
# The runtime follows the option: the cluster fixture has every one on k8s.
|
||||
&& lib.all (s: s.runtime == "k8s") (lib.attrValues cluster)
|
||||
&& cluster.swarm-nats.state == host.swarm-nats.state;
|
||||
&& cluster.swarm-controller.state == host.swarm-controller.state;
|
||||
}
|
||||
{
|
||||
# A pure function, so the case needs no host of its own. A path inside the
|
||||
|
|
|
|||
|
|
@ -367,7 +367,7 @@ let
|
|||
# The xkey exists only at runtime, so the server's config is rendered as
|
||||
# it starts: always the wrapper, and never the store-rendered settings
|
||||
# alone, which carry no xkey. `+` so the render may write `runtimeDir`.
|
||||
name = "the queue's server starts only through the config rendered with its xkey";
|
||||
name = "the queue's server starts only through the config rendered with its xkey, then takes its store directory back";
|
||||
ok =
|
||||
lib.all
|
||||
(
|
||||
|
|
@ -375,11 +375,17 @@ let
|
|||
let
|
||||
c = h.containers.swarm-nats.config;
|
||||
nats = c.systemd.services.nats.serviceConfig;
|
||||
pre = nats.ExecStartPre or "";
|
||||
pre = lib.toList (nats.ExecStartPre or [ ]);
|
||||
render = lib.head pre;
|
||||
in
|
||||
lib.hasSuffix "/bin/nats-server -c /var/lib/nats-callout/nats.conf" nats.ExecStart
|
||||
&& lib.hasPrefix "+/nix/store/" pre
|
||||
&& lib.hasSuffix "-swarm-nats-render-config" pre
|
||||
&& lib.hasPrefix "+/nix/store/" render
|
||||
&& lib.hasSuffix "-swarm-nats-render-config" render
|
||||
# Then the store directory goes back to the server's user, which the
|
||||
# pod, mounting it in place, leaves owned by its own.
|
||||
&& lib.length pre == 2
|
||||
&& lib.hasPrefix "+/nix/store/" (lib.elemAt pre 1)
|
||||
&& lib.hasSuffix "/bin/chown -R nats:nats /var/lib/nats" (lib.elemAt pre 1)
|
||||
&& !(c.services.nats.settings.authorization.auth_callout ? xkey)
|
||||
)
|
||||
[
|
||||
|
|
|
|||
Loading…
Reference in a new issue