k8s: the controller pod keeps no volume; the state gate goes
This commit is contained in:
parent
140ee7f38a
commit
4ea3b0e10d
1 changed files with 233 additions and 1110 deletions
|
|
@ -128,22 +128,6 @@ let
|
|||
];
|
||||
};
|
||||
|
||||
# The state gate: one image and script for every pod that keeps state in a
|
||||
# volume (./state-gate.nix).
|
||||
stateGateBin = "hyperhive-state-gate";
|
||||
stateGateImage = mkServiceImage {
|
||||
name = "state-gate";
|
||||
package = import ./state-gate.nix { inherit pkgs lib; };
|
||||
bin = stateGateBin;
|
||||
};
|
||||
|
||||
# What a service's state gate reads of the install: whether its
|
||||
# `k8s.freshState` holds, and the option's path, which the refusal names.
|
||||
freshOf = name: cfg: {
|
||||
enabled = cfg.k8s.freshState;
|
||||
option = "services.hyperhive.deploy.${name}.k8s.freshState";
|
||||
};
|
||||
|
||||
# The swarm services that run in the cluster. `unit` is the evaluated
|
||||
# systemd unit the host runs today; nothing reads it unless `enable` holds.
|
||||
# `healthEnv` names the variable that binds the daemon's /healthz and
|
||||
|
|
@ -152,11 +136,9 @@ let
|
|||
# the paths the unit names that hold one to theirs. `listener`, where a
|
||||
# service has one, is the TCP port the pod publishes on the node
|
||||
# (`hostAddress`) and the directory its init container writes the leaf to.
|
||||
# `fresh` (`freshOf`) is set on a service whose state is worth moving: the
|
||||
# volume's first init container, the state gate, refuses to start the pod on
|
||||
# one that holds no migrated state unless the install is fresh. A service
|
||||
# without it starts on whatever volume it gets, and one with
|
||||
# `ephemeralState` gets an `emptyDir` in place of a claim.
|
||||
# `ephemeralState` gives a service an `emptyDir` in place of a claim for its
|
||||
# state directory: what it keeps there is re-derived at start. A pod starts on
|
||||
# whatever volume it gets.
|
||||
# `switch` is null for a service that always runs on the host, and for one
|
||||
# with a `runtime` option names the option's value and the host unit or units
|
||||
# that run the service when it is `"host"`. `otlp` is where the pod pushes
|
||||
|
|
@ -192,7 +174,7 @@ let
|
|||
# The unit pushes to the swarm collector's route and mints its own bearer
|
||||
# (../glue-controller-env.nix, `otel_http_client.rs`).
|
||||
otlp = "own";
|
||||
fresh = freshOf "swarm-controller" controllerCfg;
|
||||
ephemeralState = true;
|
||||
switch = {
|
||||
inherit (controllerCfg) runtime;
|
||||
hostUnit = "swarm-controller.service";
|
||||
|
|
@ -776,43 +758,6 @@ let
|
|||
package = leafImagePackage;
|
||||
bin = leafIssueBin;
|
||||
};
|
||||
# The volume the state gate checks, and where it is mounted: that of a
|
||||
# service with a `fresh` option, none for the rest.
|
||||
stateVolume =
|
||||
if svc ? fresh && stateDir != null then
|
||||
{
|
||||
volume = "state";
|
||||
path = stateDir;
|
||||
}
|
||||
else
|
||||
null;
|
||||
|
||||
stateGate = lib.optionalAttrs (stateVolume != null) {
|
||||
name = "state-gate";
|
||||
image = "${stateGateImage.imageName}:${stateGateImage.imageTag}";
|
||||
imagePullPolicy = "Never";
|
||||
command = [ "/bin/${stateGateBin}" ];
|
||||
env =
|
||||
lib.mapAttrsToList
|
||||
(n: v: {
|
||||
name = n;
|
||||
value = v;
|
||||
})
|
||||
{
|
||||
STATE_GATE_DIR = stateVolume.path;
|
||||
STATE_GATE_SERVICE = name;
|
||||
STATE_GATE_FRESH = lib.boolToString svc.fresh.enabled;
|
||||
STATE_GATE_OPTION = svc.fresh.option;
|
||||
};
|
||||
volumeMounts = [
|
||||
{
|
||||
name = stateVolume.volume;
|
||||
mountPath = stateVolume.path;
|
||||
}
|
||||
];
|
||||
inherit (container) securityContext;
|
||||
};
|
||||
|
||||
# What the service adds to the daemon's pod.
|
||||
extra = {
|
||||
containers = [ ];
|
||||
|
|
@ -890,11 +835,8 @@ let
|
|||
};
|
||||
}
|
||||
// lib.optionalAttrs baoLogin { serviceAccountName = name; }
|
||||
// lib.optionalAttrs (stateVolume != null || listener != { } || extra.initContainers != [ ]) {
|
||||
initContainers =
|
||||
lib.optional (stateVolume != null) stateGate
|
||||
++ lib.optional (listener != { }) leafContainer
|
||||
++ extra.initContainers;
|
||||
// lib.optionalAttrs (listener != { } || extra.initContainers != [ ]) {
|
||||
initContainers = lib.optional (listener != { }) leafContainer ++ extra.initContainers;
|
||||
}
|
||||
// lib.optionalAttrs (extra.hostAliases != [ ]) { inherit (extra) hostAliases; }
|
||||
// extra.podSpec;
|
||||
|
|
@ -1014,10 +956,7 @@ let
|
|||
{
|
||||
inherit objects image;
|
||||
# What the pod's other containers run.
|
||||
extraImages =
|
||||
lib.optional (stateVolume != null) stateGateImage
|
||||
++ lib.optional (listener != { }) leafImage
|
||||
++ extra.images;
|
||||
extraImages = lib.optional (listener != { }) leafImage ++ extra.images;
|
||||
};
|
||||
|
||||
enabled = lib.mapAttrs workload (lib.filterAttrs (_: svc: svc.enable) services);
|
||||
|
|
|
|||
Loading…
Reference in a new issue