mirror of
https://git.sr.ht/~goorzhel/turboprop
synced 2024-12-14 11:37:37 +00:00
Build namespaces
I initially thought this would be just another release in `releases/common/namespaces`, but there's a lot more potential than that.
This commit is contained in:
parent
6e09298a02
commit
33433a953e
7 changed files with 63 additions and 12 deletions
14
flake.nix
14
flake.nix
|
@ -26,11 +26,15 @@
|
|||
nixhelm,
|
||||
devshell,
|
||||
}: let
|
||||
rakeLeaves = (import ./lib/rake.nix).rakeLeaves;
|
||||
rake = import ./lib/rake.nix;
|
||||
in
|
||||
{
|
||||
releaseData = rakeLeaves ./releases;
|
||||
repos = rakeLeaves ./charts;
|
||||
releaseData = rake.leaves ./releases;
|
||||
repos = rake.leaves ./charts;
|
||||
namespaces = rake.namespaces {
|
||||
root = ./releases;
|
||||
extraMetadata = import ./namespaces.nix;
|
||||
};
|
||||
}
|
||||
// flake-utils.lib.eachDefaultSystem (system: let
|
||||
pkgs = import nixpkgs {
|
||||
|
@ -49,6 +53,7 @@
|
|||
charts = flake-builders.fetchCharts self.repos;
|
||||
releases = flake-builders.buildReleases self.releaseData;
|
||||
extras = flake-builders.buildExtras self.releaseData;
|
||||
namespaces = flake-builders.buildNamespaces self.namespaces;
|
||||
|
||||
collectDerivations = with pkgs.lib; attrsets.collect isDerivation;
|
||||
in {
|
||||
|
@ -56,7 +61,7 @@
|
|||
inherit charts;
|
||||
|
||||
# Useful for debugging; will go to own flake eventually.
|
||||
inherit releases extras;
|
||||
inherit releases extras namespaces;
|
||||
inherit (self) releaseData;
|
||||
|
||||
# Each of the leaves of the `releases` and `extras` attrsets
|
||||
|
@ -69,6 +74,7 @@
|
|||
|
||||
release_drvs = collectDerivations releases;
|
||||
extra_drvs = collectDerivations extras;
|
||||
namespace_drv = namespaces;
|
||||
|
||||
src = builtins.path {
|
||||
path = ./.;
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
app-template = import ./app-template.nix {inherit charts kubelib pkgs;};
|
||||
builders = import ./builders.nix {inherit kubelib pkgs;};
|
||||
fetchers = import ./fetchers.nix {inherit kubelib pkgs;};
|
||||
resources = import ./resources.nix;
|
||||
eureka = import ./eureka {inherit app-template pkgs;};
|
||||
}
|
||||
|
|
|
@ -60,4 +60,11 @@ with builtins; {
|
|||
else {}
|
||||
))
|
||||
releases);
|
||||
|
||||
buildNamespaces = namespaces:
|
||||
lib.builders.buildYAMLStream {
|
||||
name = "namespaces";
|
||||
namespace = "CLUSTER";
|
||||
objs = namespaces;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
# Silence shellcheck SC2154 for these vars but not all others.
|
||||
: "${src:-}"
|
||||
: "${out:-}"
|
||||
# packages.*.default environment inputs:
|
||||
# `packages.*.default` environment inputs:
|
||||
: "${release_drvs:-}"
|
||||
: "${extra_drvs:-}"
|
||||
: "${namespace_drv:-}"
|
||||
|
||||
copy_drv_output(){
|
||||
drvs=$1
|
||||
|
@ -25,6 +26,12 @@ copy_drv_output(){
|
|||
done
|
||||
}
|
||||
|
||||
find_for_kustomization() {
|
||||
find . -mindepth 1 -maxdepth 1 \( -type d -o -name '*.yaml' \) \
|
||||
| grep -Ev "(values|sops|kustomization).yaml$" \
|
||||
| sed 's|^./||' # redundant in Kustomizations
|
||||
}
|
||||
|
||||
find "$src/releases" -type d \
|
||||
| grep -v "^${src}/releases$" \
|
||||
| cut -d/ -f6- \
|
||||
|
@ -46,11 +53,7 @@ do
|
|||
fi
|
||||
done
|
||||
|
||||
find_for_kustomization() {
|
||||
find . -mindepth 1 -maxdepth 1 \( -type d -o -name '*.yaml' \) \
|
||||
| grep -Ev "(values|sops|kustomization).yaml$" \
|
||||
| sed 's|^./||' # redundant in Kustomizations
|
||||
}
|
||||
cp "$namespace_drv" "$out/releases/namespaces.yaml"
|
||||
|
||||
find "$out/releases" -type d \
|
||||
| while read -r dir;
|
||||
|
|
22
lib/rake.nix
22
lib/rake.nix
|
@ -1,5 +1,5 @@
|
|||
let
|
||||
ls = dir: builtins.attrNames (builtins.readDir dir);
|
||||
ls = dir: with builtins; attrNames (readDir dir);
|
||||
|
||||
# e.g.: `dirToAttrs ./src "svc"` renders
|
||||
# {name = "svc"; value = {"sota-slack-spotter" = <lambda>, ...};}
|
||||
|
@ -18,9 +18,27 @@ let
|
|||
})
|
||||
(ls dir));
|
||||
};
|
||||
|
||||
mkNamespace = (import ./resources.nix).mkNamespace;
|
||||
in {
|
||||
rakeLeaves = root:
|
||||
leaves = root:
|
||||
builtins.listToAttrs (
|
||||
map (dirToAttrs root) (ls root)
|
||||
);
|
||||
|
||||
namespaces = {
|
||||
root,
|
||||
extraMetadata ? {},
|
||||
}:
|
||||
map
|
||||
(name: let
|
||||
metadata = with builtins;
|
||||
# Can't use `set?name` or `set.name`
|
||||
# because "name" is taken literally.
|
||||
if hasAttr name extraMetadata
|
||||
then getAttr name extraMetadata
|
||||
else {};
|
||||
in
|
||||
mkNamespace name metadata)
|
||||
(ls root);
|
||||
}
|
||||
|
|
7
lib/resources.nix
Normal file
7
lib/resources.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
mkNamespace = name: extraMetadata: {
|
||||
apiVersion = "v1";
|
||||
kind = "Namespace";
|
||||
metadata = {inherit name;} // extraMetadata;
|
||||
};
|
||||
}
|
9
namespaces.nix
Normal file
9
namespaces.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Assign extra metadata here. For example,
|
||||
# `svc = {labels."istio.io/rev" = "1-18-1"}`
|
||||
# is the equivalent of
|
||||
# `k label ns/svc istio.io/rev=1-18-1`
|
||||
let
|
||||
istioNs = rev: {labels."istio.io/rev" = rev;};
|
||||
in {
|
||||
svc = istioNs "1-18-1";
|
||||
}
|
Loading…
Reference in a new issue