Skip to content

Commit

Permalink
Fix helm version check (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
sujuka99 authored Jun 13, 2023
1 parent 15ce42c commit 4bbf6fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 5 additions & 3 deletions kpops/component_handlers/helm_wrapper/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ def get_manifest(self, release_name: str, namespace: str) -> Iterable[HelmTempla
def get_version(self) -> Version:
command = ["helm", "version", "--short"]
short_version = self.__execute(command)
version_match = re.search(r"v(\d+\.\d+\.\d+)", short_version)
version_match = re.search(r"^v(\d+(\.\d+){0,2})", short_version)
if version_match is None:
raise RuntimeError("Could not parse the Helm version.")

major, minor, patch = map(int, version_match.group(1).split("."))
version = version_match.group(1)
while re.match(r"^(\d+(\.\d+)?)$", version):
version += ".0"
major, minor, patch = map(int, version.split("."))
return Version(major, minor, patch)

@staticmethod
Expand Down
21 changes: 19 additions & 2 deletions tests/component_handlers/helm_wrapper/test_helm_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,17 @@ def test_should_call_run_command_method_when_helm_template_without_optional_args
],
)

def test_should_call_helm_version(self, run_command: MagicMock):
run_command.return_value = "v3.12.0+gc9f554d"
@pytest.mark.parametrize(
"version",
[
"v3.12.0+gc9f554d",
"v3.12.0",
"v3.12",
"v3",
],
)
def test_should_call_helm_version(self, run_command: MagicMock, version):
run_command.return_value = version
Helm(helm_config=HelmConfig())

run_command.assert_called_once_with(
Expand All @@ -477,3 +486,11 @@ def test_should_raise_exception_if_helm_version_is_old(
assert str(runtime_error.value) == (
"The supported Helm version is 3.x.x. The current Helm version is 2.9.0"
)

def test_should_raise_exception_if_helm_version_cannot_be_parsed(
self, run_command: MagicMock
):
run_command.return_value = "123"
with pytest.raises(RuntimeError) as runtime_error:
Helm(helm_config=HelmConfig())
assert str(runtime_error.value) == ("Could not parse the Helm version.")

0 comments on commit 4bbf6fd

Please sign in to comment.