# Kubernetes manifests for the swarm services this host deploys, rendered by # ./render.nix from their systemd units, and the per-service switch that moves # a service between its host unit and the cluster (./runtime.nix). Rendering # alone changes no unit and applies nothing. 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 ./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. Rendering only: the host's units stay as they are, and nothing applies the manifests to a cluster. A service with a `runtime` option is applied when it says `k8s`, 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 moves services with: each enabled service's objects and switch, 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 switches 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 ); }; }