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:
parent
1bfa6e2f2d
commit
021d366351
3 changed files with 21 additions and 19 deletions
|
@ -10,10 +10,11 @@
|
|||
kubelib,
|
||||
pkgs,
|
||||
}: let
|
||||
alwaysList = (import ./resources.nix).alwaysList;
|
||||
setNsOnObjects = namespace:
|
||||
# Attrset is on LHS in case object sets its own namespace.
|
||||
map (obj: pkgs.lib.attrsets.recursiveUpdate {metadata.namespace = namespace;} obj);
|
||||
in {
|
||||
in rec {
|
||||
derivation = {
|
||||
name,
|
||||
namespace,
|
||||
|
@ -29,14 +30,17 @@ in {
|
|||
installPhase = "cp -rv $src $out";
|
||||
};
|
||||
|
||||
helmChart = kubelib.buildHelmChart;
|
||||
# BUG: some charts lack diligence in setting `Release.Namespace` on every
|
||||
# object they create. Perhaps they assume the user has `.kube/config` with
|
||||
# the correct context set.
|
||||
# See, this is why I can't stand `helm install` and the like. Kubernetes
|
||||
# manifests are _declarative_. Why throw all of that away?
|
||||
# Anyway, the simplest solution I see is to wrap this within `yamlStream`
|
||||
# (and make this attrset recursive).
|
||||
helmChart = {
|
||||
name,
|
||||
namespace,
|
||||
...
|
||||
} @ args: let
|
||||
objs = alwaysList (kubelib.fromHelm args);
|
||||
# Some charts lack diligence in setting `Release.Namespace`
|
||||
# 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").
|
||||
yamlStream = {
|
||||
|
|
|
@ -16,16 +16,8 @@
|
|||
# from charts that provide them.
|
||||
# Doc: https://helm.sh/docs/chart_template_guide/builtin_objects/
|
||||
gatherApis = yamlPath: let
|
||||
data = parseYAMLFile yamlPath;
|
||||
crds = let
|
||||
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;
|
||||
data = resources.alwaysList (parseYAMLFile yamlPath);
|
||||
crds = builtins.filter (obj: obj.kind == "CustomResourceDefinition") data;
|
||||
in
|
||||
pkgs.lib.lists.flatten
|
||||
(map
|
||||
|
|
|
@ -4,4 +4,10 @@
|
|||
kind = "Namespace";
|
||||
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];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue