Skip to content

Commit

Permalink
Raise CompileError instead of logging for compile labels
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianchifor committed Oct 7, 2019
1 parent 84070d6 commit 3aa2e0d
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions kapitan/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ def compile_targets(inventory_path, search_paths, output_path, parallel, targets
multiprocessing pool with parallel number of processes.
kwargs are passed to compile_target()
"""
# temp_path will hold compiled items
temp_path = tempfile.mkdtemp(suffix='.kapitan')
updated_targets = search_targets(inventory_path, targets, labels)
# If --cache is set
if kwargs.get('cache'):
additional_cache_paths = kwargs.get('cache_paths')
generate_inv_cache_hashes(inventory_path, targets, additional_cache_paths)

if not targets:
updated_targets = changed_targets(inventory_path, output_path)
logger.debug("Changed targets since last compilation: %s", updated_targets)
if len(updated_targets) == 0:
logger.info("No changes since last compilation.")
return

pool = multiprocessing.Pool(parallel)

try:
# temp_path will hold compiled items
temp_path = tempfile.mkdtemp(suffix='.kapitan')
updated_targets = search_targets(inventory_path, targets, labels)
# If --cache is set
if kwargs.get('cache'):
additional_cache_paths = kwargs.get('cache_paths')
generate_inv_cache_hashes(inventory_path, targets, additional_cache_paths)

if not targets:
updated_targets = changed_targets(inventory_path, output_path)
logger.debug("Changed targets since last compilation: %s", updated_targets)
if len(updated_targets) == 0:
logger.info("No changes since last compilation.")
return

target_objs = load_target_inventory(inventory_path, updated_targets)

# append "compiled" to output_path so we can safely overwrite it
Expand Down Expand Up @@ -314,8 +314,7 @@ def search_targets(inventory_path, targets, labels):
try:
labels_dict = dict(label.split('=') for label in labels)
except ValueError:
logger.error("Compile error: Failed to parse labels, should be formatted like: kapitan compile -l env=prod app=example")
sys.exit(1)
raise CompileError("Compile error: Failed to parse labels, should be formatted like: kapitan compile -l env=prod app=example")

targets_found = []
inv = inventory_reclass(inventory_path)
Expand All @@ -337,8 +336,7 @@ def search_targets(inventory_path, targets, labels):
targets_found.append(target_name)

if len(targets_found) == 0:
logger.error("No targets found with labels: {}".format(labels))
sys.exit(1)
raise CompileError("No targets found with labels: {}".format(labels))

return targets_found

Expand Down

0 comments on commit 3aa2e0d

Please sign in to comment.