From 365fa9c5e9560e1063d3f8bb4c23bc7f6f19f736 Mon Sep 17 00:00:00 2001 From: Alessandro De Maria Date: Sat, 17 Aug 2024 19:57:22 +0000 Subject: [PATCH] Do not read multiple times --- kapitan/resources.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kapitan/resources.py b/kapitan/resources.py index 71696b533..3bc358f16 100644 --- a/kapitan/resources.py +++ b/kapitan/resources.py @@ -22,6 +22,7 @@ import kapitan.cached as cached from kapitan import __file__ as kapitan_install_path +from kapitan.inputs.kadet import Dict from kapitan.errors import CompileError, InventoryError, KapitanError from kapitan.inventory import Inventory, ReclassInventory, AVAILABLE_BACKENDS from kapitan.utils import PrettyDumper, deep_get, flatten_dict, render_jinja2_file, sha256_string @@ -334,6 +335,13 @@ def get_inventory(inventory_path, ignore_class_not_found: bool = False) -> Inven cached.inv = inventory_backend cached.global_inv = cached.inv.inventory + + # if we use forked processes, we need to load the inventory for kadet once + # and pass it to the children, to avoid re-reading the inventory for each child + # TODO(adenaria): Improve to only do it for kadet + if cached.args.mp_method != "spawn": + cached.inventory_global_kadet = Dict(cached.global_inv) + # migrate inventory to selected inventory backend if hasattr(cached.args, "migrate") and cached.args.migrate: inventory_backend.migrate()