Skip to content

Commit

Permalink
fix: namespace error with flag migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoVoges committed Jun 28, 2023
1 parent 641dc73 commit d68cc97
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
44 changes: 40 additions & 4 deletions kapitan/omegaconf_inv.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def inventory_omegaconf(
name, config = load_target(target, classes_searchpath, ignore_class_notfound)
inv["nodes"][name] = config
except Exception as e:
logger.error(f"{target['name']}: {e}")
raise e # logger.error(f"{target['name']}: {e}")

return inv

Expand Down Expand Up @@ -132,8 +132,8 @@ def load_target(target: dict, classes_searchpath: str, ignore_class_notfound: bo
"name": {
"full": target_name,
"parts": target_name.split("."),
"path": target_name,
"short": target_name,
"path": target_name.replace(".", "/"),
"short": target_name.split(".")[-1],
}
}

Expand All @@ -144,7 +144,7 @@ def load_target(target: dict, classes_searchpath: str, ignore_class_notfound: bo
target_config = OmegaConf.to_object(target_config)
# target_config = OmegaConf.to_object(OmegaConf.create(OmegaConf.to_object(target_config)))
except errors.OmegaConfBaseException as e:
raise InventoryError(e.__context__)
raise e # InventoryError(e.__context__)

# obtain target name to insert in inv dict
try:
Expand Down Expand Up @@ -175,6 +175,11 @@ def merge(*args):
return merge


def merge_replace(*args):
merge = OmegaConf.merge(*args, list_merge_mode=ListMergeMode.REPLACE)
return merge


def to_dict(input):

if not (isinstance(input, list) or OmegaConf.is_list(input)):
Expand Down Expand Up @@ -206,6 +211,34 @@ def copy(component: str, new_name):
return "${merge:${parameters.components." + component + "},${parameters." + new_name + "}}"


def helm_dep(name: str, source: str):

return {
"type": "helm",
"output_path": f"components/charts/${{parameters.{name}.chart_name}}/${{parameters.{name}.chart_version}}/${{parameters.{name}.application_version}}",
"source": source,
"version": f"${{parameters.{name}.chart_version}}",
"chart_name": f"${{parameters.{name}.chart_name}}",
}


def helm_input(name: str):

return {
"input_type": "helm",
"input_paths": [
f"components/charts/${{parameters.{name}.chart_name}}/${{parameters.{name}.chart_version}}/${{parameters.{name}.application_version}}"
],
"output_path": f"k8s/${{parameters.{name}.namespace}}",
"helm_params": {
"namespace": f"${{parameters.{name}.namespace}}",
"name": f"${{parameters.{name}.chart_name}}",
"output_file": f"{name}.yml",
},
"helm_values": f"${{parameters.{name}.helm_values}}",
}


def register_resolvers():
# utils
OmegaConf.register_new_resolver("key", key)
Expand All @@ -214,11 +247,14 @@ def register_resolvers():

# kapitan helpers
OmegaConf.register_new_resolver("merge", merge)
OmegaConf.register_new_resolver("merge_replace", merge_replace)
OmegaConf.register_new_resolver("dict", to_dict)
OmegaConf.register_new_resolver("list", to_list)
OmegaConf.register_new_resolver("namespace", namespace)
OmegaConf.register_new_resolver("deployment", deployment)
OmegaConf.register_new_resolver("copy", copy)
OmegaConf.register_new_resolver("helm_dep", helm_dep)
OmegaConf.register_new_resolver("helm_input", helm_input)


# def deployment(component: str):
Expand Down
7 changes: 5 additions & 2 deletions kapitan/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ def get_inventory(inventory_path, ignore_class_notfound=False, targets=[]):
# get parsed args from cached.py
args = list(cached.args.values())[0]
use_omegaconf = args.omegaconf
migrate_omegaconf = args.migrate
try:
migrate_omegaconf = args.migrate
except:
...

if use_omegaconf:
# show warning
Expand All @@ -337,7 +340,7 @@ def get_inventory(inventory_path, ignore_class_notfound=False, targets=[]):
try:
inv = inventory_omegaconf(inventory_path, ignore_class_notfound, targets)
except errors.OmegaConfBaseException as e:
raise InventoryError(e)
raise e # InventoryError(e)
else:
logger.debug("Using reclass as inventory backend")
inv = inventory_reclass(inventory_path, ignore_class_notfound)
Expand Down

0 comments on commit d68cc97

Please sign in to comment.