mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-25 08:54:51 +00:00
* helm: use --rollback-on-failure for atomic on Helm v4
Helm v4 renamed the `--atomic` flag to `--rollback-on-failure`. The old
flag is deprecated on `helm upgrade` and removed entirely from `helm
install`, so `atomic: true` failed against Helm v4 (issue #1143).
Emit the version-appropriate flag from deploy() using the existing
is_helm_v4() helper, covering both the upgrade and the replace/install
code paths. The public `atomic` option is unchanged.
Fixes: https://github.com/ansible-collections/kubernetes.core/issues/1143
Co-Authored-By: Claude Opus 4.8
* fix wrong link in the changelog fragment
---------
(cherry picked from commit bc17b33d44)
Signed-off-by: Yuriy Novostavskiy <yuriy@novostavskiy.kyiv.ua>
Co-authored-by: Yuriy Novostavskiy <yuriy@novostavskiy.kyiv.ua>
This commit is contained in:
@@ -710,3 +710,81 @@ class TestForceFlagHelmVersion(unittest.TestCase):
|
||||
}
|
||||
)
|
||||
helm.main()
|
||||
|
||||
|
||||
class TestAtomicFlagHelmVersion(unittest.TestCase):
|
||||
"""Helm v4 renamed '--atomic' to '--rollback-on-failure' (issue #1143)."""
|
||||
|
||||
def setUp(self):
|
||||
self.mock_module_helper = patch.multiple(
|
||||
basic.AnsibleModule,
|
||||
exit_json=exit_json,
|
||||
fail_json=fail_json,
|
||||
get_bin_path=get_bin_path,
|
||||
)
|
||||
self.mock_module_helper.start()
|
||||
self.addCleanup(self.mock_module_helper.stop)
|
||||
|
||||
self.chart_info = {
|
||||
"apiVersion": "v2",
|
||||
"appVersion": "default",
|
||||
"description": "A chart used in molecule tests",
|
||||
"name": "test-chart",
|
||||
"type": "application",
|
||||
"version": "0.1.0",
|
||||
}
|
||||
|
||||
def _run_with_version(self, args, helm_version):
|
||||
set_module_args(args)
|
||||
helm.get_release_status = MagicMock(return_value=None)
|
||||
helm.fetch_chart_info = MagicMock(return_value=self.chart_info)
|
||||
with patch.object(
|
||||
helm.AnsibleHelmModule, "get_helm_version", return_value=helm_version
|
||||
):
|
||||
with patch.object(basic.AnsibleModule, "run_command") as mock_run_command:
|
||||
mock_run_command.return_value = (0, "configuration updated", "")
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
helm.main()
|
||||
return result.exception.args[0]["command"]
|
||||
|
||||
def test_atomic_uses_atomic_flag_on_helm_v3(self):
|
||||
command = self._run_with_version(
|
||||
{
|
||||
"release_name": "test",
|
||||
"release_namespace": "test",
|
||||
"chart_ref": "chart1",
|
||||
"atomic": True,
|
||||
},
|
||||
"3.17.0",
|
||||
)
|
||||
assert "--atomic" in command
|
||||
assert "--rollback-on-failure" not in command
|
||||
|
||||
def test_atomic_uses_rollback_on_failure_on_helm_v4(self):
|
||||
command = self._run_with_version(
|
||||
{
|
||||
"release_name": "test",
|
||||
"release_namespace": "test",
|
||||
"chart_ref": "chart1",
|
||||
"atomic": True,
|
||||
},
|
||||
"4.0.0",
|
||||
)
|
||||
assert "--rollback-on-failure" in command
|
||||
assert "--atomic" not in command
|
||||
|
||||
def test_atomic_with_replace_uses_rollback_on_failure_on_helm_v4(self):
|
||||
# 'replace' uses 'helm install', where '--atomic' is removed in v4.
|
||||
command = self._run_with_version(
|
||||
{
|
||||
"release_name": "test",
|
||||
"release_namespace": "test",
|
||||
"chart_ref": "chart1",
|
||||
"atomic": True,
|
||||
"replace": True,
|
||||
},
|
||||
"4.0.0",
|
||||
)
|
||||
assert " install " in command
|
||||
assert "--rollback-on-failure" in command
|
||||
assert "--atomic" not in command
|
||||
|
||||
Reference in New Issue
Block a user