mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 16:10:05 +01:00
feat(k8s): add function for injecting names from hashed data objects (#33)
This commit is contained in:
parent
71cb0a2a47
commit
473fb3ae50
3 changed files with 62 additions and 1 deletions
|
|
@ -62,6 +62,23 @@ with lib; rec {
|
|||
} // labels;
|
||||
};
|
||||
|
||||
# Returns "<name>-<hash(data)>"
|
||||
mkNameHash = { name, data, length ? 10 }:
|
||||
"${name}-${builtins.substring 0 length (builtins.hashString "sha1" (builtins.toJSON data))}";
|
||||
|
||||
# Returns the same resources with addition of injected (or overwritten) metadata.name with hashed data
|
||||
# name of the resource in Nix does not change for reference reasons
|
||||
# useful for the ConfigMap and Secret resources
|
||||
injectHashedNames = attrs:
|
||||
lib.mapAttrs
|
||||
(name: o:
|
||||
recursiveUpdate o {
|
||||
metadata.name = mkNameHash { inherit name; data = o.data; };
|
||||
}
|
||||
)
|
||||
attrs;
|
||||
|
||||
|
||||
inherit (lib) toBase64;
|
||||
inherit (lib) octalToDecimal;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue