Skip to content

Commit

Permalink
fork test
Browse files Browse the repository at this point in the history
  • Loading branch information
ademariag committed May 30, 2024
1 parent 6baf45e commit 82bfe95
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 278 deletions.
4 changes: 1 addition & 3 deletions examples/kubernetes/compiled/jsonnet-env/jsonnet-env/env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ parameters:
c: ccccc
kapitan:
compile:
- input_params: {}
input_paths:
- input_paths:
- components/jsonnet-env/env.jsonnet
input_type: jsonnet
output_path: jsonnet-env
Expand All @@ -34,7 +33,6 @@ parameters:
recipients:
- fingerprint: D9234C61F58BEB3ED8552A57E28DC07A3CBFAE7C
name: example@kapitan.dev
target_full_path: jsonnet-env
vars:
managed_by: kapitan
namespace: jsonnet-env
Expand Down
2 changes: 1 addition & 1 deletion kapitan/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def from_dict(cache_dict):
global inv, global_inv, inv_cache, gpg_obj, gkms_obj, awskms_obj, azkms_obj, dot_kapitan, ref_controller_obj, revealer_obj, inv_sources, args

inv = cache_dict["inv"]
global_inv = Dict(inv.inventory)
global_inv = cache_dict["global_inv"]
inv_cache = cache_dict["inv_cache"]
inv_sources = cache_dict["inv_sources"]
gpg_obj = cache_dict["gpg_obj"]
Expand Down
3 changes: 2 additions & 1 deletion kapitan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,9 @@ def build_parser():

def main():
"""main function for command line usage"""

try:
multiprocessing.set_start_method("spawn")
multiprocessing.set_start_method("fork")
# main() is explicitly multiple times in tests
# and will raise RuntimeError
except RuntimeError:
Expand Down
1 change: 1 addition & 0 deletions kapitan/inventory/inv_omegaconf/inv_omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, *args, **kwargs):

def render_targets(self, targets: list[OmegaConfTarget] = None, ignore_class_not_found: bool = False) -> None:
if not self.initialised:

manager = mp.Manager()
shared_targets = manager.dict()
with mp.Pool(min(len(targets), os.cpu_count())) as pool:
Expand Down
2 changes: 2 additions & 0 deletions kapitan/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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
from kadet import Dict

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -333,6 +334,7 @@ def get_inventory(inventory_path, ignore_class_not_found: bool = False) -> Inven
inventory_backend = backend(inventory_path=inventory_path, compose_target_name=compose_target_name, ignore_class_not_found=ignore_class_not_found)

cached.inv = inventory_backend
cached.global_inv = Dict(inventory_backend.inventory)
# migrate inventory to selected inventory backend
if hasattr(cached.args, "migrate") and cached.args.migrate:
inventory_backend.migrate()
Expand Down
9 changes: 2 additions & 7 deletions kapitan/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

logger = logging.getLogger(__name__)


def compile_targets(
inventory_path, search_paths, output_path, parallelism, desidered_targets, labels, ref_controller, **kwargs
):
Expand Down Expand Up @@ -73,7 +72,7 @@ def compile_targets(
logger.debug(f"Parallel not set, defaulting to {parallelism} processes {os.cpu_count()} {len(targets)}")

logger.info(f"Compiling {len(targets)}/{len(discovered_targets)} targets using {parallelism} concurrent processes: ({os.cpu_count()} CPU detected)")

with multiprocessing.Pool(parallelism) as pool:
try:
fetching_start = time.time()
Expand Down Expand Up @@ -132,7 +131,6 @@ def compile_targets(
compile_path=temp_compile_path,
ref_controller=ref_controller,
inventory_path=inventory_path,
globals_cached=cached.as_dict(),
**kwargs,
)

Expand Down Expand Up @@ -254,16 +252,13 @@ def search_targets(inventory, targets, labels):
return targets_found


def compile_target(target_obj, search_paths, compile_path, ref_controller, globals_cached=None, **kwargs):
def compile_target(target_obj, search_paths, compile_path, ref_controller, **kwargs):
"""Compiles target_obj and writes to compile_path"""
start = time.time()
compile_objs = target_obj["compile"]
ext_vars = target_obj["vars"]
target_name = ext_vars["target"]

if globals_cached:
cached.from_dict(globals_cached)

use_go_jsonnet = kwargs.get("use_go_jsonnet", False)
if use_go_jsonnet:
logger.debug("Using go-jsonnet over jsonnet")
Expand Down
Loading

0 comments on commit 82bfe95

Please sign in to comment.