From 5092a4997e50351822b2b9497e4fa8f2fd458e28 Mon Sep 17 00:00:00 2001 From: Eric G Date: Mon, 17 Jun 2024 20:58:42 +0200 Subject: [PATCH] helm: Accept release candidate versions for compatibility checks (#745) SUMMARY If the helm CLI version includes -rc.1 for example, the version checks fails due to an incomplete regex. The error can be triggered if you use helm v3.15.0-rc.1 for example, and apply a helm chart with wait: true ISSUE TYPE Bugfix Pull Request COMPONENT NAME helm helm_pull ADDITIONAL INFORMATION Reviewed-by: Yuriy Novostavskiy Reviewed-by: Eric G. Reviewed-by: Mike Graves (cherry picked from commit 6a04f42d0bb85756af5c5946907bbd80bdb1666f) --- changelogs/fragments/20240611-helm-rc-version.yaml | 2 ++ plugins/module_utils/helm.py | 4 ++-- tests/unit/module_utils/test_helm.py | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/20240611-helm-rc-version.yaml diff --git a/changelogs/fragments/20240611-helm-rc-version.yaml b/changelogs/fragments/20240611-helm-rc-version.yaml new file mode 100644 index 0000000000..28c4dcd4b3 --- /dev/null +++ b/changelogs/fragments/20240611-helm-rc-version.yaml @@ -0,0 +1,2 @@ +bugfixes: + - helm - Helm version checks did not support RC versions. They now accept any version tags. (https://github.com/ansible-collections/kubernetes.core/pull/745). diff --git a/plugins/module_utils/helm.py b/plugins/module_utils/helm.py index faa12c03ad..edc48f6b0c 100644 --- a/plugins/module_utils/helm.py +++ b/plugins/module_utils/helm.py @@ -184,10 +184,10 @@ def get_helm_binary(self): def get_helm_version(self): command = self.get_helm_binary() + " version" rc, out, err = self.run_command(command) - m = re.match(r'version.BuildInfo{Version:"v([0-9\.]*)",', out) + m = re.match(r'version.BuildInfo{Version:"v(.*?)",', out) if m: return m.group(1) - m = re.match(r'Client: &version.Version{SemVer:"v([0-9\.]*)", ', out) + m = re.match(r'Client: &version.Version{SemVer:"v(.*?)", ', out) if m: return m.group(1) return None diff --git a/tests/unit/module_utils/test_helm.py b/tests/unit/module_utils/test_helm.py index 5db0a017c8..c4b09e4083 100644 --- a/tests/unit/module_utils/test_helm.py +++ b/tests/unit/module_utils/test_helm.py @@ -200,6 +200,10 @@ def test_module_get_values(_ansible_helm_module, no_values, get_all): 'version.BuildInfo{Version:"v3.10.3", GitCommit:7870ab3ed4135f136eec, GoVersion:"go1.18.9"}', "3.10.3", ), + ( + 'version.BuildInfo{Version:"v3.15.0-rc.1", GitCommit:"d7afa3b6b432c09a02cd07342e908ba5bed34940", GitTreeState:"clean", GoVersion:"go1.22.4"}', + "3.15.0-rc.1", + ), ('Client: &version.Version{SemVer:"v3.12.3", ', "3.12.3"), ('Client: &version.Version{SemVer:"v3.12.3"', None), ],