mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-14 00:43:49 +01:00
feat: interface and lib refactoring
This commit is contained in:
parent
e260ad9bb4
commit
5d8b66f8a0
10 changed files with 111 additions and 88 deletions
54
lib/k8s.nix
Normal file
54
lib/k8s.nix
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
{ lib }:
|
||||
|
||||
with lib;
|
||||
|
||||
rec {
|
||||
mkSecretOption = {description ? "", default ? null}: mkOption {
|
||||
inherit description;
|
||||
type = types.nullOr (types.submodule {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "Name of the secret where secret is stored";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
key = mkOption {
|
||||
description = "Name of the key where secret is stored";
|
||||
type = types.str;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkDefault (if default == null then {} else default);
|
||||
});
|
||||
default = {};
|
||||
};
|
||||
|
||||
secretToEnv = value: {
|
||||
valueFrom.secretKeyRef = {
|
||||
inherit (value) name key;
|
||||
};
|
||||
};
|
||||
|
||||
# Creates kubernetes list from a list of kubernetes objects
|
||||
mkList = { items, labels ? {} }: {
|
||||
kind = "List";
|
||||
apiVersion = "v1";
|
||||
|
||||
inherit items labels;
|
||||
};
|
||||
|
||||
# Creates hashed kubernetes list from a list of kubernetes objects
|
||||
mkHashedList = { items, labels ? {} }: let
|
||||
hash = builtins.hashString "sha1" (builtins.toJSON items);
|
||||
|
||||
labeledItems = map (item: recursiveUpdate item {
|
||||
metadata.labels."kubenix/hash" = hash;
|
||||
}) items;
|
||||
|
||||
in mkList {
|
||||
items = labeledItems;
|
||||
labels = {
|
||||
"kubenix/hash" = hash;
|
||||
} // labels;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue