services.hyperhive.k8s.enable renders a Deployment (swarm-controller, swarm-notify-router) or CronJob (swarm-ci-metrics) per service this host deploys into system.build.k8sManifests. The renderer reads each evaluated unit: its environment, LoadCredential ids, state and runtime directories, ExecStart and timer. Files the unit names are mounted at the same paths, so the environment carries over as it is. Secrets are referenced by name only. No unit changes. checks: k8s-manifests-all-local (kubeconform -strict, offline schemas) and module-eval-k8s; the allLocal fixture turns the rendering on.
52 lines
1.7 KiB
Nix
52 lines
1.7 KiB
Nix
# Kubernetes manifests for the swarm services this host deploys, rendered by
|
|
# ./render.nix from their systemd units. Rendering only: nothing here applies
|
|
# them or changes a unit. docs/4-implementation/k8s/manifests.md has the
|
|
# design.
|
|
{
|
|
pkgs,
|
|
lib,
|
|
config,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.services.hyperhive.k8s;
|
|
|
|
yaml = pkgs.formats.yaml { };
|
|
|
|
# The manifests name store paths that live in the images, not on the host,
|
|
# so the YAML carries no string context: building it builds no image and
|
|
# no daemon.
|
|
withoutContext = v: builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.toJSON v));
|
|
in
|
|
{
|
|
options.services.hyperhive.k8s = {
|
|
enable = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = false;
|
|
description = ''
|
|
Render Kubernetes manifests for the in-cluster swarm services this
|
|
host deploys (swarm-controller, swarm-notify-router and
|
|
swarm-ci-metrics) into `system.build.k8sManifests`, one YAML file per
|
|
object. The manifests reference their Secrets by name only.
|
|
|
|
Rendering only: the host's units stay as they are, and nothing
|
|
applies the manifests to a cluster.
|
|
'';
|
|
};
|
|
|
|
namespace = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "hyperhive";
|
|
description = "The Kubernetes namespace the rendered objects live in.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
system.build.k8sManifests = pkgs.linkFarm "hyperhive-k8s-manifests" (
|
|
lib.mapAttrsToList (path: object: {
|
|
name = "${path}.yaml";
|
|
path = yaml.generate "${baseNameOf path}.yaml" (withoutContext object);
|
|
}) (import ./render.nix { inherit lib pkgs config; })
|
|
);
|
|
};
|
|
}
|