Skip to content

Commit

Permalink
Update target path value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
allenporter committed Dec 24, 2023
1 parent ce0b238 commit 25287f6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
5 changes: 1 addition & 4 deletions flux_local/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def expand_value_references(
helm_release.namespaced_name,
)
continue
if ref.values_key not in found_data:
if (found_data := found_data.get(ref.values_key)) is None:
_LOGGER.warning(
"Unable to find key %s in %s/%s referenced in HelmRelease %s",
ref.values_key,
Expand All @@ -327,9 +327,6 @@ def expand_value_references(
)
continue

found_data = found_data.get(ref.values_key)
if found_data is None:
continue
if ref.target_path:
_LOGGER.debug("Updating %s with %s", ref.target_path, found_data)
parts = ref.target_path.split(".")
Expand Down
41 changes: 41 additions & 0 deletions tests/test_helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,47 @@ def test_values_references_with_values_key() -> None:
}


def test_values_references_with_missing_values_key() -> None:
"""Test for expanding a value reference with a values key that is missing."""
hr = HelmRelease(
name="test",
namespace="test",
chart=HelmChart(
repo_name="test-repo",
repo_namespace="flux-system",
name="test-chart",
version="test-version",
),
values={"test": "test"},
values_from=[
ValuesReference(
kind="ConfigMap",
namespace="test",
name="test-values-configmap",
valuesKey="some-key-does-not-exist",
targetPath="target.path",
)
],
)
ks = Kustomization(
name="test",
namespace="test",
path="example/path",
helm_releases=[hr],
config_maps=[
ConfigMap(
name="test-values-configmap",
namespace="test",
data={"some-key": "example_value"},
)
],
)
updated_hr = expand_value_references(hr, ks)
assert updated_hr.values == {
"test": "test",
}


def test_values_references_invalid_yaml() -> None:
"""Test for expanding a value reference with a values key."""
hr = HelmRelease(
Expand Down
Empty file removed tests/tool/test_helm.py
Empty file.

0 comments on commit 25287f6

Please sign in to comment.