Skip to content

Commit

Permalink
Update files
Browse files Browse the repository at this point in the history
  • Loading branch information
raminqaf committed Dec 4, 2024
1 parent b2b2983 commit d894e57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 8 additions & 8 deletions kpops/component_handlers/helm_wrapper/helm_diff.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from collections.abc import Iterable, Iterator
from typing import Any

from kpops.component_handlers.helm_wrapper.model import HelmDiffConfig, HelmTemplate
from kpops.components.common.kubernetes_model import KubernetesManifest
from kpops.utils.dict_differ import Change, render_diff

log = logging.getLogger("HelmDiff")
Expand All @@ -16,7 +16,7 @@ def __init__(self, config: HelmDiffConfig) -> None:
def calculate_changes(
current_release: Iterable[HelmTemplate],
new_release: Iterable[HelmTemplate],
) -> Iterator[Change[dict[str, Any], dict[str, Any]]]:
) -> Iterator[Change[KubernetesManifest | None, KubernetesManifest | None]]:
"""Compare 2 releases and generate a Change object for each difference.
:param current_release: Iterable containing HelmTemplate objects for the current release
Expand All @@ -32,15 +32,15 @@ def calculate_changes(
# get corresponding dry-run release
new_resource = new_release_index.pop(current_resource.filepath, None)
yield Change(
current_resource.manifest.model_dump(),
new_resource.manifest.model_dump() if new_resource else {},
current_resource.manifest,
new_resource.manifest if new_resource else None,
)

# collect added files
for new_resource in new_release_index.values():
yield Change(
{},
new_resource.manifest.model_dump(mode="json"),
None,
new_resource.manifest,
)

def log_helm_diff(
Expand All @@ -51,8 +51,8 @@ def log_helm_diff(
) -> None:
for change in self.calculate_changes(current_release, new_release):
if diff := render_diff(
change.old_value,
change.new_value,
change.old_value.model_dump() if change.old_value else {},
change.new_value.model_dump() if change.new_value else {},
ignore=self.config.ignore,
):
logger.info("\n" + diff)
14 changes: 8 additions & 6 deletions tests/component_handlers/helm_wrapper/test_helm_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ def test_calculate_changes_new_release(self, helm_diff: HelmDiff):
)
) == [
Change(
old_value={},
new_value={
"apiVersion": "v1",
"kind": "Deployment",
"metadata": {"a": "1"},
},
old_value=None,
new_value=KubernetesManifest(
**{
"apiVersion": "v1",
"kind": "Deployment",
"metadata": {"a": "1"},
}
),
),
]

Expand Down

0 comments on commit d894e57

Please sign in to comment.