feat: deprecate mkValueOrSecretOption with mkSecretOption

This commit is contained in:
Jaka Hudoklin 2017-12-18 12:22:18 +01:00
parent 1db416b1e1
commit 5179a8d0a7
4 changed files with 35 additions and 28 deletions

View file

@ -14,7 +14,7 @@ let
args = { args = {
inherit pkgs; inherit pkgs;
name = "default"; name = "default";
k8s = { inherit loadJSON loadYAML toYAML toBase64 octalToDecimal mkValueOrSecretOption; }; k8s = { inherit loadJSON loadYAML toYAML toBase64 octalToDecimal mkSecretOption; };
}; };
}; };

33
lib.nix
View file

@ -44,28 +44,29 @@ rec {
value = acc.value + (toInt char) * (exp 8 acc.i); value = acc.value + (toInt char) * (exp 8 acc.i);
}) {i = 0; value = 0;} (stringToCharacters value)).value; }) {i = 0; value = 0;} (stringToCharacters value)).value;
mkValueOrSecretOption = {...}@options: mkOption ({ mkSecretOption = {...}@options: mkOption (options // {
type = types.nullOr (types.either types.str (types.submodule { type = types.nullOr (types.submodule {
options.secret = mkOption { options = {
description = "Name of the secret where password is stored"; name = mkOption {
description = "Name of the secret where secret is stored";
type = types.str; type = types.str;
}; };
options.key = mkOption { key = mkOption {
description = "Name of the key where password is stored"; description = "Name of the key where secret is stored";
type = types.str; type = types.str;
default = "password";
}; };
})); };
apply = value: config = mkIf (hasAttr "default" options) (mkAllDefault options.default 1000);
if isAttrs value });
then {
apply = value: {
valueFrom.secretKeyRef = { valueFrom.secretKeyRef = {
name = value.secret; inherit (value) name key;
key = value.key;
}; };
} };
else {inherit value;};
} // options); default = {};
});
} }

View file

@ -1,7 +1,7 @@
{ config, ... }: { config, ... }:
{ {
kubernetes.version = "1.7"; kubernetes.version = "1.9";
require = [./modules.nix ./deployment.nix]; require = [./modules.nix ./deployment.nix];
} }

View file

@ -13,9 +13,12 @@ with lib;
default = 80; default = 80;
}; };
password = mkValueOrSecretOption { password = mkSecretOption {
description = "Nginx simple auth credentials"; description = "Nginx simple auth credentials";
default.secret = "test"; default = {
name = "test";
key = "password";
};
}; };
}; };
@ -47,7 +50,10 @@ with lib;
}; };
}; };
kubernetes.modules.app-v1.module = "nginx"; kubernetes.modules.app-v1 = {
module = "nginx";
configuration.password.name = "test2";
};
kubernetes.modules.app-v2 = { kubernetes.modules.app-v2 = {
module = "nginx"; module = "nginx";
configuration.port = 8080; configuration.port = 8080;