Skip to content

Commit

Permalink
Kapitan Release 0.34.2 (#1263)
Browse files Browse the repository at this point in the history
## Proposed Changes

* Fix inventory validation for OmegaConf
* Refactor inventory modules
* Minor refactoring
  • Loading branch information
ademariag authored Nov 8, 2024
1 parent dfa5d33 commit c9aeb04
Show file tree
Hide file tree
Showing 20 changed files with 302 additions and 307 deletions.
8 changes: 4 additions & 4 deletions docs/pages/inventory/reclass-rs.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ The example inventory renders to a total of 25MB of YAML.
$ time kapitan inventory -v --inventory-backend=reclass > inv.yml
[ ... some output omitted ... ]
kapitan.resources DEBUG Using reclass as inventory backend
kapitan.inventory.inv_reclass DEBUG Inventory reclass: No config file found. Using reclass inventory config defaults
kapitan.inventory.inv_reclass DEBUG Inventory rendering with reclass took 0:01:06.037057
kapitan.inventory.backends.reclass DEBUG Inventory reclass: No config file found. Using reclass inventory config defaults
kapitan.inventory.backends.reclass DEBUG Inventory rendering with reclass took 0:01:06.037057

real 1m23.840s
user 1m23.520s
Expand All @@ -56,11 +56,11 @@ The rest of the runtime (roughly 18 seconds) is spent in writing the resulting 2
$ time kapitan inventory -v --inventory-backend=reclass-rs > inv-rs.yml
[ ... some output omitted ... ]
kapitan.resources DEBUG Using reclass-rs as inventory backend
kapitan.inventory.inv_reclass DEBUG Inventory reclass: No config file found. Using reclass inventory config defaults
kapitan.inventory.backends.reclass DEBUG Inventory reclass: No config file found. Using reclass inventory config defaults
reclass-config.yml entry 'storage_type=yaml_fs' not implemented yet, ignoring...
reclass-config.yml entry 'inventory_base_uri=./inventory' not implemented yet, ignoring...
reclass-config.yml entry 'allow_none_override=true' not implemented yet, ignoring...
kapitan.inventory.inv_reclass_rs DEBUG Inventory rendering with reclass-rs took 0:00:01.717107
kapitan.inventory.backends.reclass_rs DEBUG Inventory rendering with reclass-rs took 0:00:01.717107
real 0m19.921s
user 0m35.586s
Expand Down
8 changes: 8 additions & 0 deletions kapitan/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class InventoryError(KapitanError):
"""inventory error"""


class InventoryValidationError(InventoryError):
"""inventory validation error"""


class InvalidTargetError(InventoryError):
"""inventory validation error"""


class SecretError(KapitanError):
"""secrets error"""

Expand Down
1 change: 0 additions & 1 deletion kapitan/inputs/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import subprocess

from kapitan.inputs.base import InputType
from kapitan.utils import copy_tree

logger = logging.getLogger(__name__)

Expand Down
8 changes: 4 additions & 4 deletions kapitan/inventory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from kapitan.utils import StrEnum

from .inventory import Inventory
from .inventory import Inventory, InventoryError, InventoryTarget


class InventoryBackends(StrEnum):
Expand All @@ -20,7 +20,7 @@ def load_reclass_backend():
"""
Enable the reclass inventory backend.
"""
from .inv_reclass import ReclassInventory
from .backends.reclass import ReclassInventory

return ReclassInventory

Expand All @@ -29,7 +29,7 @@ def load_reclass_rs_backend():
"""
Enable the reclass-rs inventory backend.
"""
from .inv_reclass_rs import ReclassRsInventory
from .backends.reclass_rs import ReclassRsInventory

return ReclassRsInventory

Expand All @@ -38,7 +38,7 @@ def load_omegaconf_backend():
"""
Enable the omegaconf inventory backend.
"""
from .inv_omegaconf.inv_omegaconf import OmegaConfInventory
from .backends.omegaconf import OmegaConfInventory

return OmegaConfInventory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
from kadet import Dict
from omegaconf import ListMergeMode, OmegaConf

from kapitan.errors import InventoryError
from kapitan.inventory import Inventory, InventoryTarget
from kapitan.inventory.model import KapitanInventoryMetadata, KapitanInventoryParameters

from ..inventory import Inventory, InventoryError, InventoryTarget
from .migrate import migrate
from .resolvers import register_resolvers

Expand All @@ -30,6 +31,10 @@ def keys_to_strings(ob):
return ob


class OmegaConfRenderingError(InventoryError):
pass


@keys_to_strings.register
def _handle_dict(ob: dict):
return {str(k): keys_to_strings(v) for k, v in ob.items()}
Expand Down Expand Up @@ -75,6 +80,9 @@ def render_targets(
)
r.wait()

if not r.successful():
raise OmegaConfRenderingError("Error while loading the OmegaConf inventory")

for target in shared_targets.values():
self.targets[target.name] = target

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from reclass.errors import NotFoundError, ReclassException

from kapitan.errors import InventoryError

from .inventory import Inventory, InventoryTarget
from kapitan.inventory import Inventory, InventoryTarget

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import reclass_rs

from kapitan.errors import InventoryError

from .inv_reclass import get_reclass_config
from .inventory import Inventory, InventoryTarget
from kapitan.inventory import Inventory
from kapitan.inventory.backends.reclass import get_reclass_config

logger = logging.getLogger(__name__)

Expand Down
Empty file.
14 changes: 1 addition & 13 deletions kapitan/inventory/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from pydantic import BaseModel, ConfigDict, Field

from kapitan.errors import KapitanError
from kapitan.errors import InventoryError
from kapitan.inventory.model import KapitanInventoryParameters

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -141,15 +141,3 @@ def migrate(self):

def __getitem__(self, key):
return self.inventory[key]


class InventoryError(KapitanError):
"""inventory error"""


class InventoryValidationError(InventoryError):
"""inventory validation error"""


class InvalidTargetError(InventoryError):
"""inventory validation error"""
9 changes: 5 additions & 4 deletions kapitan/inventory/model/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Literal, Optional, Union
from typing import Annotated, Literal, Optional, Union

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, Field

from kapitan.utils import StrEnum

Expand Down Expand Up @@ -39,6 +39,7 @@ class KapitanDependencyHttpsConfig(KapitanDependencyBaseConfig):
unpack: bool = False


DependencyTypeConfig = Union[
KapitanDependencyHelmConfig, KapitanDependencyHttpsConfig, KapitanDependencyGitConfig
DependencyTypeConfig = Annotated[
Union[KapitanDependencyHelmConfig, KapitanDependencyHttpsConfig, KapitanDependencyGitConfig],
Field(discriminator="type"),
]
15 changes: 10 additions & 5 deletions kapitan/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,16 @@ def get_inventory(inventory_path, ignore_class_not_found: bool = False) -> Inven
backend = get_inventory_backend(backend_id)

logger.debug(f"Using {backend.__name__} as inventory backend")
inventory_backend = backend(
inventory_path=inventory_path,
compose_target_name=compose_target_name,
ignore_class_not_found=ignore_class_not_found,
)

try:
inventory_backend = backend(
inventory_path=inventory_path,
compose_target_name=compose_target_name,
ignore_class_not_found=ignore_class_not_found,
)
except InventoryError as e:
logger.fatal(e)
raise

cached.inv = inventory_backend
cached.global_inv = cached.inv.inventory
Expand Down
2 changes: 1 addition & 1 deletion kapitan/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""Project description variables."""

PROJECT_NAME = "kapitan"
VERSION = "0.34.1"
VERSION = "0.34.2"
DESCRIPTION = "Generic templated configuration management for Kubernetes, Terraform and other things"
AUTHOR = "Ricardo Amaro"
AUTHOR_EMAIL = "[email protected]"
Expand Down
Loading

0 comments on commit c9aeb04

Please sign in to comment.