Skip to content

Commit

Permalink
feat: introduce boolean algebra resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoVoges committed Sep 4, 2023
1 parent 688934e commit cd17d66
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion kapitan/inventory/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#
# SPDX-License-Identifier: Apache-2.0

import copy
import logging
import os
import sys
import copy

from omegaconf import Container, ListMergeMode, Node, OmegaConf

Expand Down Expand Up @@ -139,6 +139,36 @@ def write_to_key(destination: str, origin: str, _root_):
return "DONE"


def condition_if(condition: str, config: dict):
if bool(condition):
return config
else:
return {}


def condition_if_else(condition: str, config_if: dict, config_else: dict):
if bool(condition):
return config_if
else:
return config_else


def condition_not(condition: str):
return not bool(condition)


def condition_and(*conditions: str):
return all(conditions)


def condition_or(*conditions: str):
return any(conditions)


def condition_equal(*configs):
return all(config == configs[0] for config in configs)


def helm_dep(name: str, source: str):
"""kapitan template for a helm chart dependency"""
return {
Expand Down Expand Up @@ -186,6 +216,14 @@ def register_resolvers(inventory_path: str) -> None:
OmegaConf.register_new_resolver("default", default, replace=replace)
OmegaConf.register_new_resolver("write", write_to_key, replace=replace)

# boolean algebra
OmegaConf.register_new_resolver("if", condition_if, replace=replace)
OmegaConf.register_new_resolver("ifelse", condition_if_else, replace=replace)
OmegaConf.register_new_resolver("and", condition_and, replace=replace)
OmegaConf.register_new_resolver("or", condition_or, replace=replace)
OmegaConf.register_new_resolver("not", condition_not, replace=replace)
OmegaConf.register_new_resolver("equal", condition_equal, replace=replace)

# kapitan helpers / templates
OmegaConf.register_new_resolver("helm_dep", helm_dep, replace=replace)
OmegaConf.register_new_resolver("helm_input", helm_input, replace=replace)
Expand Down

0 comments on commit cd17d66

Please sign in to comment.