k8s: render the in-cluster services' manifests from their units
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.
This commit is contained in:
parent
5a884a8d09
commit
d2acf3080a
1 changed files with 773 additions and 0 deletions
|
|
@ -32,6 +32,63 @@ in
|
|||
echo ${pkgs.lib.escapeShellArg moduleEvalShared.allLocal.systemd.services.nginx.serviceConfig.ExecStart} > $out
|
||||
'';
|
||||
|
||||
# The single-host swarm fixture's k8s manifests (../host-modules/k8s),
|
||||
# validated offline by `kubeconform -strict` against the schemas below.
|
||||
# The invalid Deployment must fail, which shows the schemas load and an
|
||||
# unknown field is refused.
|
||||
k8s-manifests-all-local =
|
||||
let
|
||||
# Standalone strict JSON schemas for Kubernetes 1.35, one per kind the
|
||||
# renderer emits, named the way `-schema-location` below looks them up.
|
||||
schemaRev = "11639286f15b208b6c7f1f93bc2c1a70f42cfbcb";
|
||||
schemas = pkgs.linkFarm "k8s-1.35-schemas" (
|
||||
pkgs.lib.mapAttrsToList
|
||||
(file: hash: {
|
||||
name = "${file}.json";
|
||||
path = pkgs.fetchurl {
|
||||
url = "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/${schemaRev}/v1.35.0-standalone-strict/${file}.json";
|
||||
inherit hash;
|
||||
};
|
||||
})
|
||||
{
|
||||
deployment-apps-v1 = "sha256-Rtx8xL7CyaYkAEkeK4BXY1r7+mg4mZxRj3vqXGIamJs=";
|
||||
cronjob-batch-v1 = "sha256-324f6Z2U41lEAnt7xDFwOfIvSc/0DE6x3AtU8C/PiUA=";
|
||||
persistentvolumeclaim-v1 = "sha256-YTaHGsAzfxGkjaUjGigHQHxzhpZ+NDLzRBQbkC9qU4w=";
|
||||
configmap-v1 = "sha256-4Ord69Z3wIqgkrLaImTYasT8NO7RErn6wpRbPwDB6bE=";
|
||||
namespace-v1 = "sha256-Mk+uZ3uY0abVQ0DbDDNNBT6P+6/Os/czJuQd4mENWEM=";
|
||||
}
|
||||
);
|
||||
invalid = pkgs.writeText "invalid-deployment.yaml" ''
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: invalid
|
||||
spec:
|
||||
replicaCount: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: invalid
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: invalid
|
||||
spec:
|
||||
containers:
|
||||
- name: invalid
|
||||
image: invalid
|
||||
'';
|
||||
validate = "kubeconform -strict -summary -schema-location '${schemas}/{{ .ResourceKind }}{{ .KindSuffix }}.json'";
|
||||
in
|
||||
pkgs.runCommand "k8s-manifests-all-local" { nativeBuildInputs = [ pkgs.kubeconform ]; } ''
|
||||
${validate} ${moduleEvalShared.allLocal.system.build.k8sManifests}/
|
||||
test -e ${moduleEvalShared.allLocal.system.build.k8sManifests}/swarm-controller/deployment.yaml
|
||||
if ${validate} ${invalid}; then
|
||||
echo "kubeconform accepted a Deployment with an unknown field" >&2
|
||||
exit 1
|
||||
fi
|
||||
touch $out
|
||||
'';
|
||||
|
||||
# The only checks here that cover **nix**. Every other one is a Rust
|
||||
# derivation, so a `.nix`-only diff moves no hash and the whole set is
|
||||
# cache hits — green without evaluating what changed. See
|
||||
|
|
@ -63,6 +120,11 @@ in
|
|||
inherit (pkgs) lib;
|
||||
shared = moduleEvalShared;
|
||||
};
|
||||
module-eval-k8s = import ./module-eval/k8s.nix {
|
||||
inherit pkgs self nixosSystem;
|
||||
inherit (pkgs) lib;
|
||||
shared = moduleEvalShared;
|
||||
};
|
||||
module-eval-nats-authelia = import ./module-eval/nats-authelia.nix {
|
||||
inherit pkgs self nixosSystem;
|
||||
inherit (pkgs) lib;
|
||||
|
|
|
|||
Loading…
Reference in a new issue