Merge pull request 'Inventory/interface: add enable flag for service instances' (#2227) from hsjobeki/clan-core:hsjobeki-main into main
This commit is contained in:
@@ -63,6 +63,7 @@ let
|
||||
++ (lib.foldlAttrs (
|
||||
# [ Modules ], String, ServiceConfig
|
||||
acc2: instanceName: serviceConfig:
|
||||
|
||||
let
|
||||
resolvedRoles = builtins.mapAttrs (
|
||||
roleName: members:
|
||||
@@ -119,8 +120,9 @@ let
|
||||
globalExtraModules ++ machineExtraModules ++ roleServiceExtraModules
|
||||
);
|
||||
in
|
||||
|
||||
if isInService then
|
||||
if !(serviceConfig.enabled or true) then
|
||||
acc2
|
||||
else if isInService then
|
||||
acc2
|
||||
++ [
|
||||
{
|
||||
|
||||
@@ -184,6 +184,19 @@ in
|
||||
# instance name
|
||||
{ name, ... }:
|
||||
{
|
||||
options.enabled = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Enable or disable the complete service.
|
||||
|
||||
If the service is disabled, it will not be added to any machine.
|
||||
|
||||
!!! Note
|
||||
This flag is primarily used to temporarily disable a service.
|
||||
I.e. A 'backup service' without any 'server' might be incomplete and would cause failure if enabled.
|
||||
'';
|
||||
};
|
||||
options.meta = metaOptionsWith name;
|
||||
options.extraModules = extraModulesOption;
|
||||
options.config = moduleConfig // {
|
||||
|
||||
@@ -200,4 +200,33 @@ in
|
||||
msg = "no machine with tag '\\w+' found";
|
||||
};
|
||||
};
|
||||
test_inventory_disabled_service =
|
||||
let
|
||||
configs = buildInventory {
|
||||
directory = ./.;
|
||||
inventory = {
|
||||
services = {
|
||||
borgbackup.instance_1 = {
|
||||
enabled = false;
|
||||
roles.client.machines = [ "machine_1" ];
|
||||
};
|
||||
};
|
||||
machines = {
|
||||
"machine_1" = {
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
expr = {
|
||||
machine_1_config = (builtins.head configs."machine_1");
|
||||
};
|
||||
expected = {
|
||||
# Empty config
|
||||
machine_1_config = { };
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user