1
0
Fork 0
mirror of https://git.sr.ht/~goorzhel/turboprop synced 2024-12-15 17:50:52 +00:00

Forcibly set namespace on all Helm charts

This commit is contained in:
Antonio Gurgel 2023-11-26 13:36:35 -08:00
parent 1bfa6e2f2d
commit 021d366351
3 changed files with 21 additions and 19 deletions

View file

@ -10,10 +10,11 @@
kubelib, kubelib,
pkgs, pkgs,
}: let }: let
alwaysList = (import ./resources.nix).alwaysList;
setNsOnObjects = namespace: setNsOnObjects = namespace:
# Attrset is on LHS in case object sets its own namespace. # Attrset is on LHS in case object sets its own namespace.
map (obj: pkgs.lib.attrsets.recursiveUpdate {metadata.namespace = namespace;} obj); map (obj: pkgs.lib.attrsets.recursiveUpdate {metadata.namespace = namespace;} obj);
in { in rec {
derivation = { derivation = {
name, name,
namespace, namespace,
@ -29,14 +30,17 @@ in {
installPhase = "cp -rv $src $out"; installPhase = "cp -rv $src $out";
}; };
helmChart = kubelib.buildHelmChart; helmChart = {
# BUG: some charts lack diligence in setting `Release.Namespace` on every name,
# object they create. Perhaps they assume the user has `.kube/config` with namespace,
# the correct context set. ...
# See, this is why I can't stand `helm install` and the like. Kubernetes } @ args: let
# manifests are _declarative_. Why throw all of that away? objs = alwaysList (kubelib.fromHelm args);
# Anyway, the simplest solution I see is to wrap this within `yamlStream` # Some charts lack diligence in setting `Release.Namespace`
# (and make this attrset recursive). # on the objects they create, necessitating a round-trip through
# yamlStream, which sets namespaces on all objects lacking one.
in
yamlStream {inherit name namespace objs;};
# Adapted from github:farcaller/nix-kube-generators ("kubelib"). # Adapted from github:farcaller/nix-kube-generators ("kubelib").
yamlStream = { yamlStream = {

View file

@ -16,16 +16,8 @@
# from charts that provide them. # from charts that provide them.
# Doc: https://helm.sh/docs/chart_template_guide/builtin_objects/ # Doc: https://helm.sh/docs/chart_template_guide/builtin_objects/
gatherApis = yamlPath: let gatherApis = yamlPath: let
data = parseYAMLFile yamlPath; data = resources.alwaysList (parseYAMLFile yamlPath);
crds = let crds = builtins.filter (obj: obj.kind == "CustomResourceDefinition") data;
input =
# This was a dagger partly of my own making:
# https://github.com/farcaller/nix-kube-generators/pull/5
if builtins.typeOf data == "list"
then data
else [data];
in
builtins.filter (obj: obj.kind == "CustomResourceDefinition") input;
in in
pkgs.lib.lists.flatten pkgs.lib.lists.flatten
(map (map

View file

@ -4,4 +4,10 @@
kind = "Namespace"; kind = "Namespace";
metadata = {inherit name;} // extraMetadata; metadata = {inherit name;} // extraMetadata;
}; };
alwaysList = data:
# This was a dagger partly of my own making:
# https://github.com/farcaller/nix-kube-generators/pull/5
if builtins.typeOf data == "list"
then data
else [data];
} }