88 lines
2.5 KiB
Nix
88 lines
2.5 KiB
Nix
# Kubernetes manifests for the swarm services this host deploys, rendered by
|
|
# ./render.nix from their systemd units, and the module that applies them to the
|
|
# cluster (./runtime.nix). docs/4-implementation/k8s/manifests.md
|
|
# and runtime.md have 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));
|
|
|
|
rendered = import ./render.nix { inherit lib pkgs config; };
|
|
in
|
|
{
|
|
imports = [
|
|
./host-services.nix
|
|
./join.nix
|
|
./node.nix
|
|
./pod-logs.nix
|
|
./runtime.nix
|
|
];
|
|
|
|
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, and the images their pods run into `system.build.k8sImages`.
|
|
The manifests reference their Secrets by name only.
|
|
|
|
The manifests are applied on a host with
|
|
{option}`services.hyperhive.deploy.k8s.enable`.
|
|
'';
|
|
};
|
|
|
|
namespace = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "hyperhive";
|
|
description = "The Kubernetes namespace the rendered objects live in.";
|
|
};
|
|
|
|
rendered = lib.mkOption {
|
|
type = lib.types.raw;
|
|
readOnly = true;
|
|
internal = true;
|
|
description = ''
|
|
What ./runtime.nix applies: each enabled service's
|
|
objects, the namespace object, and the CA ConfigMap's name
|
|
and host files.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
services.hyperhive.k8s.rendered = {
|
|
inherit (rendered)
|
|
caConfigMap
|
|
caSources
|
|
serviceNames
|
|
userNamespaces
|
|
;
|
|
services = withoutContext rendered.services;
|
|
namespaceObject = withoutContext rendered.objects.namespace;
|
|
};
|
|
|
|
# The images those pods run, for a node to load: ./node.nix.
|
|
system.build.k8sImages = rendered.images;
|
|
|
|
system.build.k8sManifests = pkgs.linkFarm "hyperhive-k8s-manifests" (
|
|
lib.mapAttrsToList (path: object: {
|
|
name = "${path}.yaml";
|
|
path = yaml.generate "${baseNameOf path}.yaml" (withoutContext object);
|
|
}) rendered.objects
|
|
);
|
|
};
|
|
}
|