mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-03-26 21:33:02 +00:00
This is a backport of PR #1090 as merged into main (e6076e5).
SUMMARY
Ensure compatibility with Helm v4 for modules helm_plugin and helm_plugin_info
Partially addresses #1038
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
helm_plugin
helm_plugin_info
helm_info
helm_pull
helm_registry_auth
helm
helm_template
Reviewed-by: Bikouo Aubin
Reviewed-by: Matthew Johnson
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,6 +17,7 @@ tests/integration/cloud-config-*
|
|||||||
|
|
||||||
# Helm charts
|
# Helm charts
|
||||||
tests/integration/*-chart-*.tgz
|
tests/integration/*-chart-*.tgz
|
||||||
|
tests/integration/targets/*/*.tgz
|
||||||
|
|
||||||
# ansible-test generated file
|
# ansible-test generated file
|
||||||
tests/integration/inventory
|
tests/integration/inventory
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ PEP440 is the schema used to describe the versions of Ansible.
|
|||||||
|
|
||||||
### Helm Version Compatibility
|
### Helm Version Compatibility
|
||||||
|
|
||||||
Helm modules in this collection are compatible with Helm v3.x and are not yet compatible with Helm v4. Individual modules and their parameters may support a more specific range of Helm versions.
|
This collection supports Helm v3.x and newer. Please note that specific modules or certain parameters may have additional version requirements.
|
||||||
|
|
||||||
### Python Support
|
### Python Support
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- helm_plugin - Ensure compatibility with Helm v4 (https://github.com/ansible-collections/kubernetes.core/issues/1038).
|
||||||
|
- helm_plugin_info - Ensure compatibility with Helm v4 (https://github.com/ansible-collections/kubernetes.core/issues/1038).
|
||||||
|
- helm_info - Ensure compatibility with Helm v4 (https://github.com/ansible-collections/kubernetes.core/issues/1038).
|
||||||
|
- helm_pull - Ensure compatibility with Helm v4 (https://github.com/ansible-collections/kubernetes.core/issues/1038).
|
||||||
|
- helm_registry_auth - Ensure compatibility with Helm v4 (https://github.com/ansible-collections/kubernetes.core/issues/1038).
|
||||||
|
- helm_registry_auth - add new option plain_http to allow insecure http connection when running ``helm registry login`` (https://github.com/ansible-collections/kubernetes.core/pull/1090).
|
||||||
|
- helm_repository - Ensure compatibility with Helm v4 (https://github.com/ansible-collections/kubernetes.core/issues/1038).
|
||||||
@@ -40,16 +40,20 @@ def parse_helm_plugin_list(output=None):
|
|||||||
if not output:
|
if not output:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
parsing_grammar = None
|
||||||
for line in output:
|
for line in output:
|
||||||
if line.startswith("NAME"):
|
if line.startswith("NAME"):
|
||||||
|
parsing_grammar = [s.strip().lower() for s in line.split("\t")]
|
||||||
continue
|
continue
|
||||||
name, version, description = line.split("\t", 3)
|
if parsing_grammar is None:
|
||||||
name = name.strip()
|
|
||||||
version = version.strip()
|
|
||||||
description = description.strip()
|
|
||||||
if name == "":
|
|
||||||
continue
|
continue
|
||||||
ret.append((name, version, description))
|
plugin = {
|
||||||
|
parsing_grammar[i]: v.strip()
|
||||||
|
for i, v in enumerate(line.split("\t", len(parsing_grammar)))
|
||||||
|
}
|
||||||
|
if plugin["name"] == "":
|
||||||
|
continue
|
||||||
|
ret.append(plugin)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@@ -202,21 +206,35 @@ class AnsibleHelmModule(object):
|
|||||||
return m.group(1)
|
return m.group(1)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def validate_helm_version(self):
|
def is_helm_v4(self):
|
||||||
|
helm_version = self.get_helm_version()
|
||||||
|
if helm_version is None:
|
||||||
|
return False
|
||||||
|
return LooseVersion(helm_version) >= LooseVersion("4.0.0")
|
||||||
|
|
||||||
|
def is_helm_version_compatible_with_helm_diff(self, helm_diff_version):
|
||||||
"""
|
"""
|
||||||
Validate that Helm version is >=3.0.0 and <4.0.0.
|
Return true if the helm version is compatible with the helm diff version
|
||||||
Helm 4 is not yet supported.
|
Helm v4 requires helm diff v3.14.0
|
||||||
|
"""
|
||||||
|
if not helm_diff_version:
|
||||||
|
return False
|
||||||
|
if self.is_helm_v4():
|
||||||
|
return LooseVersion(helm_diff_version) >= LooseVersion("3.14.0")
|
||||||
|
return True
|
||||||
|
|
||||||
|
def validate_helm_version(self, version="3.0.0"):
|
||||||
|
"""
|
||||||
|
Validate that Helm version is >= version (default version=3.0.0).
|
||||||
"""
|
"""
|
||||||
helm_version = self.get_helm_version()
|
helm_version = self.get_helm_version()
|
||||||
if helm_version is None:
|
if helm_version is None:
|
||||||
self.fail_json(msg="Unable to determine Helm version")
|
self.fail_json(msg="Unable to determine Helm version")
|
||||||
|
|
||||||
if (LooseVersion(helm_version) < LooseVersion("3.0.0")) or (
|
if LooseVersion(helm_version) < LooseVersion(version):
|
||||||
LooseVersion(helm_version) >= LooseVersion("4.0.0")
|
|
||||||
):
|
|
||||||
self.fail_json(
|
self.fail_json(
|
||||||
msg="Helm version must be >=3.0.0,<4.0.0, current version is {0}".format(
|
msg="Helm version must be >= {0}, current version is {1}".format(
|
||||||
helm_version
|
version, helm_version
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ author:
|
|||||||
- Matthieu Diehr (@d-matt)
|
- Matthieu Diehr (@d-matt)
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "helm (https://github.com/helm/helm/releases)"
|
- "helm >= 3.0.0 (https://github.com/helm/helm/releases)"
|
||||||
- "yaml (https://pypi.org/project/PyYAML/)"
|
- "yaml (https://pypi.org/project/PyYAML/)"
|
||||||
|
|
||||||
description:
|
description:
|
||||||
@@ -500,9 +500,13 @@ def get_release_status(module, release_name, all_status=False):
|
|||||||
"--filter",
|
"--filter",
|
||||||
release_name,
|
release_name,
|
||||||
]
|
]
|
||||||
if all_status:
|
if all_status and not module.is_helm_v4():
|
||||||
|
# --all has been removed from `helm list` command on helm v4
|
||||||
list_command.append("--all")
|
list_command.append("--all")
|
||||||
|
elif not all_status:
|
||||||
|
# The default behavior to display only deployed releases has been removed from
|
||||||
|
# Helm v4
|
||||||
|
list_command.append("--deployed")
|
||||||
rc, out, err = module.run_helm_command(list_command)
|
rc, out, err = module.run_helm_command(list_command)
|
||||||
|
|
||||||
release = get_release(yaml.safe_load(out), release_name)
|
release = get_release(yaml.safe_load(out), release_name)
|
||||||
@@ -739,8 +743,8 @@ def get_plugin_version(plugin):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
for line in out:
|
for line in out:
|
||||||
if line[0] == plugin:
|
if line["name"] == plugin:
|
||||||
return line[1]
|
return line["version"]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -928,7 +932,7 @@ def main():
|
|||||||
if not IMP_YAML:
|
if not IMP_YAML:
|
||||||
module.fail_json(msg=missing_required_lib("yaml"), exception=IMP_YAML_ERR)
|
module.fail_json(msg=missing_required_lib("yaml"), exception=IMP_YAML_ERR)
|
||||||
|
|
||||||
# Validate Helm version >=3.0.0,<4.0.0
|
# Validate Helm version >=3.0.0
|
||||||
module.validate_helm_version()
|
module.validate_helm_version()
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
@@ -1010,8 +1014,7 @@ def main():
|
|||||||
if wait:
|
if wait:
|
||||||
helm_version = module.get_helm_version()
|
helm_version = module.get_helm_version()
|
||||||
if LooseVersion(helm_version) < LooseVersion("3.7.0"):
|
if LooseVersion(helm_version) < LooseVersion("3.7.0"):
|
||||||
opt_result["warnings"] = []
|
module.warn(
|
||||||
opt_result["warnings"].append(
|
|
||||||
"helm uninstall support option --wait for helm release >= 3.7.0"
|
"helm uninstall support option --wait for helm release >= 3.7.0"
|
||||||
)
|
)
|
||||||
wait = False
|
wait = False
|
||||||
@@ -1099,14 +1102,21 @@ def main():
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
helm_diff_version = get_plugin_version("diff")
|
helm_diff_version = get_plugin_version("diff")
|
||||||
if helm_diff_version and (
|
helm_version_compatible = module.is_helm_version_compatible_with_helm_diff(
|
||||||
|
helm_diff_version
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
helm_diff_version
|
||||||
|
and helm_version_compatible
|
||||||
|
and (
|
||||||
not chart_repo_url
|
not chart_repo_url
|
||||||
or (
|
or (
|
||||||
chart_repo_url
|
chart_repo_url
|
||||||
and LooseVersion(helm_diff_version) >= LooseVersion("3.4.1")
|
and LooseVersion(helm_diff_version) >= LooseVersion("3.4.1")
|
||||||
)
|
)
|
||||||
|
)
|
||||||
):
|
):
|
||||||
(would_change, prepared) = helmdiff_check(
|
would_change, prepared = helmdiff_check(
|
||||||
module,
|
module,
|
||||||
release_name,
|
release_name,
|
||||||
chart_ref,
|
chart_ref,
|
||||||
@@ -1126,6 +1136,14 @@ def main():
|
|||||||
)
|
)
|
||||||
if would_change and module._diff:
|
if would_change and module._diff:
|
||||||
opt_result["diff"] = {"prepared": prepared}
|
opt_result["diff"] = {"prepared": prepared}
|
||||||
|
else:
|
||||||
|
if helm_diff_version and not helm_version_compatible:
|
||||||
|
module.warn(
|
||||||
|
"Idempotency checks are currently disabled due to a version mismatch."
|
||||||
|
f" Helm version {module.get_helm_version()} requires helm-diff >= 3.14.0,"
|
||||||
|
f" but the environment is currently running {helm_diff_version}."
|
||||||
|
" Please align the plugin versions to restore standard behavior."
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
module.warn(
|
module.warn(
|
||||||
"The default idempotency check can fail to report changes in certain cases. "
|
"The default idempotency check can fail to report changes in certain cases. "
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ author:
|
|||||||
- Lucas Boisserie (@LucasBoisserie)
|
- Lucas Boisserie (@LucasBoisserie)
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "helm (https://github.com/helm/helm/releases)"
|
- "helm >= 3.0.0 (https://github.com/helm/helm/releases)"
|
||||||
- "yaml (https://pypi.org/project/PyYAML/)"
|
- "yaml (https://pypi.org/project/PyYAML/)"
|
||||||
|
|
||||||
description:
|
description:
|
||||||
@@ -245,7 +245,7 @@ def main():
|
|||||||
if not IMP_YAML:
|
if not IMP_YAML:
|
||||||
module.fail_json(msg=missing_required_lib("yaml"), exception=IMP_YAML_ERR)
|
module.fail_json(msg=missing_required_lib("yaml"), exception=IMP_YAML_ERR)
|
||||||
|
|
||||||
# Validate Helm version >=3.0.0,<4.0.0
|
# Validate Helm version >=3.0.0
|
||||||
module.validate_helm_version()
|
module.validate_helm_version()
|
||||||
|
|
||||||
release_name = module.params.get("release_name")
|
release_name = module.params.get("release_name")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ version_added: 1.0.0
|
|||||||
author:
|
author:
|
||||||
- Abhijeet Kasurde (@Akasurde)
|
- Abhijeet Kasurde (@Akasurde)
|
||||||
requirements:
|
requirements:
|
||||||
- "helm (https://github.com/helm/helm/releases)"
|
- "helm >= 3.0.0 (https://github.com/helm/helm/releases)"
|
||||||
description:
|
description:
|
||||||
- Manages Helm plugins.
|
- Manages Helm plugins.
|
||||||
options:
|
options:
|
||||||
@@ -48,6 +48,14 @@ options:
|
|||||||
required: false
|
required: false
|
||||||
type: str
|
type: str
|
||||||
version_added: 2.3.0
|
version_added: 2.3.0
|
||||||
|
verify:
|
||||||
|
description:
|
||||||
|
- Verify the plugin signature before installing.
|
||||||
|
- This option requires helm version >= 4.0.0
|
||||||
|
- Used with I(state=present).
|
||||||
|
type: bool
|
||||||
|
default: true
|
||||||
|
version_added: 6.4.0
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- kubernetes.core.helm_common_options
|
- kubernetes.core.helm_common_options
|
||||||
"""
|
"""
|
||||||
@@ -118,6 +126,9 @@ from ansible_collections.kubernetes.core.plugins.module_utils.helm_args_common i
|
|||||||
HELM_AUTH_ARG_SPEC,
|
HELM_AUTH_ARG_SPEC,
|
||||||
HELM_AUTH_MUTUALLY_EXCLUSIVE,
|
HELM_AUTH_MUTUALLY_EXCLUSIVE,
|
||||||
)
|
)
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.version import (
|
||||||
|
LooseVersion,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def argument_spec():
|
def argument_spec():
|
||||||
@@ -138,6 +149,10 @@ def argument_spec():
|
|||||||
default="present",
|
default="present",
|
||||||
choices=["present", "absent", "latest"],
|
choices=["present", "absent", "latest"],
|
||||||
),
|
),
|
||||||
|
verify=dict(
|
||||||
|
type="bool",
|
||||||
|
default=True,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return arg_spec
|
return arg_spec
|
||||||
@@ -161,7 +176,7 @@ def main():
|
|||||||
mutually_exclusive=mutually_exclusive(),
|
mutually_exclusive=mutually_exclusive(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate Helm version >=3.0.0,<4.0.0
|
# Validate helm version >= 3.0.0
|
||||||
module.validate_helm_version()
|
module.validate_helm_version()
|
||||||
|
|
||||||
state = module.params.get("state")
|
state = module.params.get("state")
|
||||||
@@ -171,8 +186,19 @@ def main():
|
|||||||
if state == "present":
|
if state == "present":
|
||||||
helm_cmd_common += " install %s" % module.params.get("plugin_path")
|
helm_cmd_common += " install %s" % module.params.get("plugin_path")
|
||||||
plugin_version = module.params.get("plugin_version")
|
plugin_version = module.params.get("plugin_version")
|
||||||
|
verify = module.params.get("verify")
|
||||||
if plugin_version is not None:
|
if plugin_version is not None:
|
||||||
helm_cmd_common += " --version=%s" % plugin_version
|
helm_cmd_common += " --version=%s" % plugin_version
|
||||||
|
if not verify:
|
||||||
|
helm_version = module.get_helm_version()
|
||||||
|
if LooseVersion(helm_version) < LooseVersion("4.0.0"):
|
||||||
|
module.warn(
|
||||||
|
"verify parameter requires helm >= 4.0.0, current version is {0}".format(
|
||||||
|
helm_version
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
helm_cmd_common += " --verify=false"
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
rc, out, err = module.run_helm_command(
|
rc, out, err = module.run_helm_command(
|
||||||
helm_cmd_common, fails_on_error=False
|
helm_cmd_common, fails_on_error=False
|
||||||
@@ -211,9 +237,9 @@ def main():
|
|||||||
elif state == "absent":
|
elif state == "absent":
|
||||||
plugin_name = module.params.get("plugin_name")
|
plugin_name = module.params.get("plugin_name")
|
||||||
rc, output, err, command = module.get_helm_plugin_list()
|
rc, output, err, command = module.get_helm_plugin_list()
|
||||||
out = parse_helm_plugin_list(output=output.splitlines())
|
plugins = parse_helm_plugin_list(output=output.splitlines())
|
||||||
|
|
||||||
if not out:
|
if not plugins:
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
failed=False,
|
failed=False,
|
||||||
changed=False,
|
changed=False,
|
||||||
@@ -224,12 +250,7 @@ def main():
|
|||||||
rc=rc,
|
rc=rc,
|
||||||
)
|
)
|
||||||
|
|
||||||
found = False
|
if all(plugin["name"] != plugin_name for plugin in plugins):
|
||||||
for line in out:
|
|
||||||
if line[0] == plugin_name:
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
failed=False,
|
failed=False,
|
||||||
changed=False,
|
changed=False,
|
||||||
@@ -267,9 +288,9 @@ def main():
|
|||||||
elif state == "latest":
|
elif state == "latest":
|
||||||
plugin_name = module.params.get("plugin_name")
|
plugin_name = module.params.get("plugin_name")
|
||||||
rc, output, err, command = module.get_helm_plugin_list()
|
rc, output, err, command = module.get_helm_plugin_list()
|
||||||
out = parse_helm_plugin_list(output=output.splitlines())
|
plugins = parse_helm_plugin_list(output=output.splitlines())
|
||||||
|
|
||||||
if not out:
|
if not plugins:
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
failed=False,
|
failed=False,
|
||||||
changed=False,
|
changed=False,
|
||||||
@@ -280,12 +301,7 @@ def main():
|
|||||||
rc=rc,
|
rc=rc,
|
||||||
)
|
)
|
||||||
|
|
||||||
found = False
|
if all(plugin["name"] != plugin_name for plugin in plugins):
|
||||||
for line in out:
|
|
||||||
if line[0] == plugin_name:
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
failed=False,
|
failed=False,
|
||||||
changed=False,
|
changed=False,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ version_added: 1.0.0
|
|||||||
author:
|
author:
|
||||||
- Abhijeet Kasurde (@Akasurde)
|
- Abhijeet Kasurde (@Akasurde)
|
||||||
requirements:
|
requirements:
|
||||||
- "helm (https://github.com/helm/helm/releases)"
|
- "helm >= 3.0.0 (https://github.com/helm/helm/releases)"
|
||||||
description:
|
description:
|
||||||
- Gather information about Helm plugins installed in namespace.
|
- Gather information about Helm plugins installed in namespace.
|
||||||
options:
|
options:
|
||||||
@@ -98,29 +98,16 @@ def main():
|
|||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate Helm version >=3.0.0,<4.0.0
|
# Validate helm version >= 3.0.0
|
||||||
module.validate_helm_version()
|
module.validate_helm_version()
|
||||||
|
|
||||||
plugin_name = module.params.get("plugin_name")
|
plugin_name = module.params.get("plugin_name")
|
||||||
|
|
||||||
plugin_list = []
|
|
||||||
|
|
||||||
rc, output, err, command = module.get_helm_plugin_list()
|
rc, output, err, command = module.get_helm_plugin_list()
|
||||||
|
|
||||||
out = parse_helm_plugin_list(output=output.splitlines())
|
plugins = parse_helm_plugin_list(output=output.splitlines())
|
||||||
|
if plugin_name is not None:
|
||||||
for line in out:
|
plugins = [plugin for plugin in plugins if plugin.get("name") == plugin_name]
|
||||||
if plugin_name is None:
|
|
||||||
plugin_list.append(
|
|
||||||
{"name": line[0], "version": line[1], "description": line[2]}
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if plugin_name == line[0]:
|
|
||||||
plugin_list.append(
|
|
||||||
{"name": line[0], "version": line[1], "description": line[2]}
|
|
||||||
)
|
|
||||||
break
|
|
||||||
|
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
changed=True,
|
changed=True,
|
||||||
@@ -128,7 +115,7 @@ def main():
|
|||||||
stdout=output,
|
stdout=output,
|
||||||
stderr=err,
|
stderr=err,
|
||||||
rc=rc,
|
rc=rc,
|
||||||
plugin_list=plugin_list,
|
plugin_list=plugins,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ description:
|
|||||||
- There are options for unpacking the chart after download.
|
- There are options for unpacking the chart after download.
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "helm >= 3.0, <4.0.0 (https://github.com/helm/helm/releases)"
|
- "helm >= 3.0.0 (https://github.com/helm/helm/releases)"
|
||||||
|
|
||||||
options:
|
options:
|
||||||
chart_ref:
|
chart_ref:
|
||||||
@@ -372,7 +372,7 @@ def main():
|
|||||||
mutually_exclusive=[("chart_version", "chart_devel")],
|
mutually_exclusive=[("chart_version", "chart_devel")],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate Helm version >=3.0.0,<4.0.0
|
# Validate Helm version >=3.0.0
|
||||||
module.validate_helm_version()
|
module.validate_helm_version()
|
||||||
|
|
||||||
helm_version = module.get_helm_version()
|
helm_version = module.get_helm_version()
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ author:
|
|||||||
- Yuriy Novostavskiy (@yurnov)
|
- Yuriy Novostavskiy (@yurnov)
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "helm (https://github.com/helm/helm/releases) >= 3.8.0, <4.0.0"
|
- "helm (https://github.com/helm/helm/releases) >= 3.8.0"
|
||||||
|
|
||||||
description:
|
description:
|
||||||
- Helm registry authentication module allows you to login C(helm registry login) and logout C(helm registry logout) from a Helm registry.
|
- Helm registry authentication module allows you to login C(helm registry login) and logout C(helm registry logout) from a Helm registry.
|
||||||
@@ -75,6 +75,14 @@ options:
|
|||||||
- Path to the CA certificate SSL file for verify registry server certificate.
|
- Path to the CA certificate SSL file for verify registry server certificate.
|
||||||
required: false
|
required: false
|
||||||
type: path
|
type: path
|
||||||
|
plain_http:
|
||||||
|
description:
|
||||||
|
- Use insecure HTTP connections for C(helm registry login).
|
||||||
|
- Requires Helm >= 3.18.0
|
||||||
|
required: false
|
||||||
|
type: bool
|
||||||
|
default: False
|
||||||
|
version_added: 6.4.0
|
||||||
binary_path:
|
binary_path:
|
||||||
description:
|
description:
|
||||||
- The path of a helm binary to use.
|
- The path of a helm binary to use.
|
||||||
@@ -148,6 +156,7 @@ def arg_spec():
|
|||||||
key_file=dict(type="path", required=False),
|
key_file=dict(type="path", required=False),
|
||||||
cert_file=dict(type="path", required=False),
|
cert_file=dict(type="path", required=False),
|
||||||
ca_file=dict(type="path", required=False),
|
ca_file=dict(type="path", required=False),
|
||||||
|
plain_http=dict(type="bool", default=False),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -160,6 +169,7 @@ def login(
|
|||||||
key_file,
|
key_file,
|
||||||
cert_file,
|
cert_file,
|
||||||
ca_file,
|
ca_file,
|
||||||
|
plain_http,
|
||||||
):
|
):
|
||||||
login_command = command + " registry login " + host
|
login_command = command + " registry login " + host
|
||||||
|
|
||||||
@@ -177,6 +187,8 @@ def login(
|
|||||||
|
|
||||||
if ca_file is not None:
|
if ca_file is not None:
|
||||||
login_command += " --ca-file=" + ca_file
|
login_command += " --ca-file=" + ca_file
|
||||||
|
if plain_http:
|
||||||
|
login_command += " --plain-http"
|
||||||
|
|
||||||
return login_command
|
return login_command
|
||||||
|
|
||||||
@@ -194,8 +206,8 @@ def main():
|
|||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate Helm version >=3.0.0,<4.0.0
|
# Validate Helm version >=3.8.0
|
||||||
module.validate_helm_version()
|
module.validate_helm_version(version="3.8.0")
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
@@ -207,6 +219,19 @@ def main():
|
|||||||
key_file = module.params.get("key_file")
|
key_file = module.params.get("key_file")
|
||||||
cert_file = module.params.get("cert_file")
|
cert_file = module.params.get("cert_file")
|
||||||
ca_file = module.params.get("ca_file")
|
ca_file = module.params.get("ca_file")
|
||||||
|
plain_http = module.params.get("plain_http")
|
||||||
|
|
||||||
|
helm_version = module.get_helm_version()
|
||||||
|
|
||||||
|
if plain_http:
|
||||||
|
if LooseVersion(helm_version) < LooseVersion("3.18.0"):
|
||||||
|
module.warn(
|
||||||
|
"plain_http option requires helm >= 3.18.0, current version is {0}".format(
|
||||||
|
helm_version
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# reset option
|
||||||
|
plain_http = False
|
||||||
|
|
||||||
helm_cmd = module.get_helm_binary()
|
helm_cmd = module.get_helm_binary()
|
||||||
|
|
||||||
@@ -215,7 +240,15 @@ def main():
|
|||||||
changed = True
|
changed = True
|
||||||
elif state == "present":
|
elif state == "present":
|
||||||
helm_cmd = login(
|
helm_cmd = login(
|
||||||
helm_cmd, host, insecure, username, password, key_file, cert_file, ca_file
|
helm_cmd,
|
||||||
|
host,
|
||||||
|
insecure,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
key_file,
|
||||||
|
cert_file,
|
||||||
|
ca_file,
|
||||||
|
plain_http,
|
||||||
)
|
)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
@@ -238,7 +271,6 @@ def main():
|
|||||||
command=helm_cmd,
|
command=helm_cmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
helm_version = module.get_helm_version()
|
|
||||||
if LooseVersion(helm_version) >= LooseVersion("3.18.0") and state == "absent":
|
if LooseVersion(helm_version) >= LooseVersion("3.18.0") and state == "absent":
|
||||||
# https://github.com/ansible-collections/kubernetes.core/issues/944
|
# https://github.com/ansible-collections/kubernetes.core/issues/944
|
||||||
module.warn(
|
module.warn(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ author:
|
|||||||
- Lucas Boisserie (@LucasBoisserie)
|
- Lucas Boisserie (@LucasBoisserie)
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "helm (https://github.com/helm/helm/releases)"
|
- "helm >= 3.0.0 (https://github.com/helm/helm/releases)"
|
||||||
- "yaml (https://pypi.org/project/PyYAML/)"
|
- "yaml (https://pypi.org/project/PyYAML/)"
|
||||||
|
|
||||||
description:
|
description:
|
||||||
@@ -295,7 +295,7 @@ def main():
|
|||||||
if not IMP_YAML:
|
if not IMP_YAML:
|
||||||
module.fail_json(msg=missing_required_lib("yaml"), exception=IMP_YAML_ERR)
|
module.fail_json(msg=missing_required_lib("yaml"), exception=IMP_YAML_ERR)
|
||||||
|
|
||||||
# Validate Helm version >=3.0.0,<4.0.0
|
# Validate Helm version >= 3.0.0
|
||||||
module.validate_helm_version()
|
module.validate_helm_version()
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ author:
|
|||||||
description:
|
description:
|
||||||
- Render chart templates to an output directory or as text of concatenated yaml documents.
|
- Render chart templates to an output directory or as text of concatenated yaml documents.
|
||||||
|
|
||||||
|
requirements:
|
||||||
|
- "helm >= 3.0.0 (https://github.com/helm/helm/releases)"
|
||||||
|
- "yaml (https://pypi.org/project/PyYAML/)"
|
||||||
|
|
||||||
options:
|
options:
|
||||||
binary_path:
|
binary_path:
|
||||||
description:
|
description:
|
||||||
@@ -347,7 +351,7 @@ def main():
|
|||||||
if not IMP_YAML:
|
if not IMP_YAML:
|
||||||
module.fail_json(msg=missing_required_lib("yaml"), exception=IMP_YAML_ERR)
|
module.fail_json(msg=missing_required_lib("yaml"), exception=IMP_YAML_ERR)
|
||||||
|
|
||||||
# Validate Helm version >=3.0.0,<4.0.0
|
# Validate Helm version >=3.0.0
|
||||||
module.validate_helm_version()
|
module.validate_helm_version()
|
||||||
|
|
||||||
helm_cmd = module.get_helm_binary()
|
helm_cmd = module.get_helm_binary()
|
||||||
|
|||||||
@@ -1,4 +1 @@
|
|||||||
time=100
|
disabled # used by test targets helm_vX_XX_XX
|
||||||
helm_info
|
|
||||||
helm_repository
|
|
||||||
helm_template
|
|
||||||
|
|||||||
@@ -9,25 +9,25 @@ chart_test_version: 4.2.4
|
|||||||
chart_test_version_local_path: 1.32.0
|
chart_test_version_local_path: 1.32.0
|
||||||
chart_test_version_upgrade: 4.2.5
|
chart_test_version_upgrade: 4.2.5
|
||||||
chart_test_version_upgrade_local_path: 1.33.0
|
chart_test_version_upgrade_local_path: 1.33.0
|
||||||
chart_test_repo: "https://kubernetes.github.io/ingress-nginx"
|
chart_test_repo: "https://stenic.github.io/k8status/"
|
||||||
chart_test_git_repo: "http://github.com/helm/charts.git"
|
chart_test_git_repo: "http://github.com/helm/charts.git"
|
||||||
chart_test_values:
|
chart_test_values:
|
||||||
revisionHistoryLimit: 0
|
revisionHistoryLimit: 0
|
||||||
myValue: "changed"
|
myValue: "changed"
|
||||||
|
|
||||||
test_namespace:
|
test_namespace:
|
||||||
- "helm-test-crds"
|
- "helm-test-crds-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-uninstall"
|
- "helm-uninstall-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-read-envvars"
|
- "helm-read-envvars-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-dep-update"
|
- "helm-dep-update-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-local-path-001"
|
- "helm-local-path-001-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-local-path-002"
|
- "helm-local-path-002-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-local-path-003"
|
- "helm-local-path-003-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-from-repository"
|
- "helm-from-repository-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-from-url"
|
- "helm-from-url-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-reuse-values"
|
- "helm-reuse-values-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-chart-with-space-into-name"
|
- "helm-chart-with-space-into-name-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-reset-then-reuse-values"
|
- "helm-reset-then-reuse-values-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-insecure"
|
- "helm-insecure-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-test-take-ownership"
|
- "helm-test-take-ownership-{{ helm_version | replace('.', '-') }}"
|
||||||
- "helm-skip-schema-validation"
|
- "helm-skip-schema-validation-{{ helm_version | replace('.', '-') }}"
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ import json
|
|||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible_collections.kubernetes.core.plugins.module_utils.helm import (
|
||||||
|
AnsibleHelmModule,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class HelmReleaseNotFoundError(Exception):
|
class HelmReleaseNotFoundError(Exception):
|
||||||
@@ -60,7 +62,9 @@ class HelmReleaseNotFoundError(Exception):
|
|||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
def create_pending_install_release(helm_binary, chart_ref, chart_release, namespace):
|
def create_pending_install_release(
|
||||||
|
module, helm_binary, chart_ref, chart_release, namespace
|
||||||
|
):
|
||||||
# create pending-install release
|
# create pending-install release
|
||||||
command = [
|
command = [
|
||||||
helm_binary,
|
helm_binary,
|
||||||
@@ -78,13 +82,14 @@ def create_pending_install_release(helm_binary, chart_ref, chart_release, namesp
|
|||||||
command = [
|
command = [
|
||||||
helm_binary,
|
helm_binary,
|
||||||
"list",
|
"list",
|
||||||
"--all",
|
|
||||||
"--output=json",
|
"--output=json",
|
||||||
"--namespace",
|
"--namespace",
|
||||||
namespace,
|
namespace,
|
||||||
"--filter",
|
"--filter",
|
||||||
chart_release,
|
chart_release,
|
||||||
]
|
]
|
||||||
|
if not module.is_helm_v4():
|
||||||
|
command.append("--all")
|
||||||
cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
out, err = cmd.communicate()
|
out, err = cmd.communicate()
|
||||||
|
|
||||||
@@ -92,11 +97,11 @@ def create_pending_install_release(helm_binary, chart_ref, chart_release, namesp
|
|||||||
if not data:
|
if not data:
|
||||||
error = "Release %s not found." % chart_release
|
error = "Release %s not found." % chart_release
|
||||||
raise HelmReleaseNotFoundError(message=error)
|
raise HelmReleaseNotFoundError(message=error)
|
||||||
return data[0]["status"] == "pending-install", data[0]["status"]
|
return data[0]["status"] in ("pending-install", "failed"), data[0]["status"]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleHelmModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
binary_path=dict(type="path", required=True),
|
binary_path=dict(type="path", required=True),
|
||||||
chart_ref=dict(type="str", required=True),
|
chart_ref=dict(type="str", required=True),
|
||||||
@@ -106,6 +111,7 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
params = dict(
|
params = dict(
|
||||||
|
module=module,
|
||||||
helm_binary=module.params.get("binary_path"),
|
helm_binary=module.params.get("binary_path"),
|
||||||
chart_release=module.params.get("chart_release"),
|
chart_release=module.params.get("chart_release"),
|
||||||
chart_ref=module.params.get("chart_ref"),
|
chart_ref=module.params.get("chart_ref"),
|
||||||
@@ -116,7 +122,7 @@ def main():
|
|||||||
result, status = create_pending_install_release(**params)
|
result, status = create_pending_install_release(**params)
|
||||||
if not result:
|
if not result:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg="unable to create pending-install release, current status is %s"
|
msg="unable to create pending-install/failed release, current status is %s"
|
||||||
% status
|
% status
|
||||||
)
|
)
|
||||||
module.exit_json(changed=True, msg="Release created with status '%s'" % status)
|
module.exit_json(changed=True, msg="Release created with status '%s'" % status)
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
---
|
---
|
||||||
collections:
|
collections:
|
||||||
- kubernetes.core
|
- kubernetes.core
|
||||||
dependencies:
|
|
||||||
- remove_namespace
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
- connection: local
|
|
||||||
gather_facts: true
|
|
||||||
hosts: localhost
|
|
||||||
|
|
||||||
roles:
|
|
||||||
- helm
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -eux
|
|
||||||
export ANSIBLE_CALLBACKS_ENABLED=profile_tasks
|
|
||||||
export ANSIBLE_ROLES_PATH=../
|
|
||||||
ansible-playbook playbook.yaml "$@"
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Init Helm folders
|
|
||||||
file:
|
|
||||||
path: /tmp/helm/
|
|
||||||
state: directory
|
|
||||||
|
|
||||||
- name: Unarchive Helm binary
|
|
||||||
unarchive:
|
|
||||||
src: 'https://get.helm.sh/{{ helm_archive_name | default(helm_default_archive_name) }}'
|
|
||||||
dest: /tmp/helm/
|
|
||||||
remote_src: yes
|
|
||||||
retries: 10
|
|
||||||
delay: 5
|
|
||||||
register: result
|
|
||||||
until: result is not failed
|
|
||||||
@@ -1,10 +1,22 @@
|
|||||||
---
|
---
|
||||||
|
- name: Ensure helm is not installed
|
||||||
|
file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
with_items:
|
||||||
|
- "/tmp/helm"
|
||||||
|
|
||||||
|
- name: Check failed if helm is not installed
|
||||||
|
include_tasks: test_helm_not_installed.yml
|
||||||
|
|
||||||
|
- name: Install Helm v4
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: install_helm
|
||||||
|
vars:
|
||||||
|
helm_version: v3.6.0
|
||||||
|
|
||||||
|
- name: Test helm uninstall
|
||||||
|
ansible.builtin.include_tasks: test_helm_uninstall.yml
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
include_tasks: run_test.yml
|
include_tasks: run_test.yml
|
||||||
loop_control:
|
|
||||||
loop_var: helm_version
|
|
||||||
with_items:
|
|
||||||
- "v3.15.4"
|
|
||||||
- "v3.16.0"
|
|
||||||
- "v3.17.0"
|
|
||||||
- "v4.0.0"
|
|
||||||
|
|||||||
@@ -1,25 +1,19 @@
|
|||||||
---
|
---
|
||||||
- name: Ensure helm is not installed
|
|
||||||
file:
|
|
||||||
path: "{{ item }}"
|
|
||||||
state: absent
|
|
||||||
with_items:
|
|
||||||
- "/tmp/helm"
|
|
||||||
|
|
||||||
- name: Check failed if helm is not installed
|
|
||||||
include_tasks: test_helm_not_installed.yml
|
|
||||||
|
|
||||||
- name: "Install {{ helm_version }}"
|
- name: "Install {{ helm_version }}"
|
||||||
include_role:
|
include_role:
|
||||||
name: install_helm
|
name: install_helm
|
||||||
|
|
||||||
- name: Main helm tests with Helm v3
|
- name: Main helm tests
|
||||||
when: helm_version != "v4.0.0"
|
|
||||||
block:
|
block:
|
||||||
|
- name: Install helm-diff plugin
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
plugin_path: https://github.com/databus23/helm-diff
|
||||||
|
plugin_version: "{{ helm_version is version('v4.0.0', '>=') | ternary('v3.14.0', 'v3.10.0') }}"
|
||||||
|
verify: false
|
||||||
|
|
||||||
- name: "Ensure we honor the environment variables"
|
- name: "Ensure we honor the environment variables"
|
||||||
include_tasks: test_read_envvars.yml
|
include_tasks: test_read_envvars.yml
|
||||||
when: helm_version != "v4.0.0"
|
|
||||||
|
|
||||||
- name: Deploy charts
|
- name: Deploy charts
|
||||||
include_tasks: "tests_chart/{{ test_chart_type }}.yml"
|
include_tasks: "tests_chart/{{ test_chart_type }}.yml"
|
||||||
@@ -39,9 +33,6 @@
|
|||||||
- name: test helm dependency update
|
- name: test helm dependency update
|
||||||
include_tasks: test_up_dep.yml
|
include_tasks: test_up_dep.yml
|
||||||
|
|
||||||
- name: Test helm uninstall
|
|
||||||
include_tasks: test_helm_uninstall.yml
|
|
||||||
|
|
||||||
- name: Test helm install with chart name containing space
|
- name: Test helm install with chart name containing space
|
||||||
include_tasks: test_helm_with_space_into_chart_name.yml
|
include_tasks: test_helm_with_space_into_chart_name.yml
|
||||||
|
|
||||||
@@ -58,12 +49,15 @@
|
|||||||
- name: Test helm skip_schema_validation
|
- name: Test helm skip_schema_validation
|
||||||
include_tasks: test_skip_schema_validation.yml
|
include_tasks: test_skip_schema_validation.yml
|
||||||
|
|
||||||
- name: Test helm version
|
always:
|
||||||
include_tasks: test_helm_version.yml
|
- name: Remove helm-diff plugin
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
plugin_name: diff
|
||||||
|
state: absent
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Clean helm install
|
- name: Clean helm install
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ item }}"
|
path: "/tmp/helm/"
|
||||||
state: absent
|
state: absent
|
||||||
with_items:
|
|
||||||
- "/tmp/helm/"
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
name: test
|
name: test
|
||||||
chart_ref: "{{ chart_test }}"
|
chart_ref: "{{ chart_test }}"
|
||||||
namespace: "helm-test"
|
namespace: "helm-test"
|
||||||
ignore_errors: yes
|
ignore_errors: true
|
||||||
register: helm_missing_binary
|
register: helm_missing_binary
|
||||||
|
|
||||||
- name: Assert that helm is not installed
|
- name: Assert that helm is not installed
|
||||||
|
|||||||
@@ -38,6 +38,28 @@
|
|||||||
- '"--reset-then-reuse-values" not in install.command'
|
- '"--reset-then-reuse-values" not in install.command'
|
||||||
- release_value["status"]["release_values"] == chart_release_values
|
- release_value["status"]["release_values"] == chart_release_values
|
||||||
|
|
||||||
|
# We need to provide the actual redis password otherwise the update command
|
||||||
|
# will fail with the following:
|
||||||
|
# Error: execution error at (redis/templates/replicas/application.yaml:55:35):
|
||||||
|
# PASSWORDS ERROR: You must provide your current passwords when upgrading the release.
|
||||||
|
# Note that even after reinstallation, old credentials may be needed as they may be kept in persistent volume claims.
|
||||||
|
# Further information can be obtained at https://docs.bitnami.com/general/how-to/troubleshoot-helm-chart-issues/#credential-errors-while-upgrading-chart-releases
|
||||||
|
# 'global.redis.password' must not be empty, please add '--set global.redis.password=$REDIS_PASSWORD' to the command. To get the current value:
|
||||||
|
- name: Retrieve release password
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
namespace: "{{ helm_namespace }}"
|
||||||
|
kind: Secret
|
||||||
|
name: test-redis
|
||||||
|
register: redis_secret
|
||||||
|
|
||||||
|
- ansible.builtin.set_fact:
|
||||||
|
chart_reset_then_reuse_values: "{{ chart_reset_then_reuse_values | combine(redis_global_password) }}"
|
||||||
|
vars:
|
||||||
|
redis_global_password:
|
||||||
|
global:
|
||||||
|
redis:
|
||||||
|
password: "{{ redis_secret.resources.0.data['redis-password'] | b64decode }}"
|
||||||
|
|
||||||
- name: Upgrade chart using reset_then_reuse_values=true
|
- name: Upgrade chart using reset_then_reuse_values=true
|
||||||
helm:
|
helm:
|
||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
@@ -73,3 +95,4 @@
|
|||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: "{{ helm_namespace }}"
|
name: "{{ helm_namespace }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
wait: false
|
||||||
|
|||||||
@@ -38,6 +38,21 @@
|
|||||||
- '"--reuse-values=True" not in install.command'
|
- '"--reuse-values=True" not in install.command'
|
||||||
- release_value["status"]["release_values"] == chart_release_values
|
- release_value["status"]["release_values"] == chart_release_values
|
||||||
|
|
||||||
|
- name: Retrieve release password
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
namespace: "{{ helm_namespace }}"
|
||||||
|
kind: Secret
|
||||||
|
name: test-redis
|
||||||
|
register: redis_secret
|
||||||
|
|
||||||
|
- ansible.builtin.set_fact:
|
||||||
|
chart_reuse_values: "{{ chart_reuse_values | combine(redis_global_password) }}"
|
||||||
|
vars:
|
||||||
|
redis_global_password:
|
||||||
|
global:
|
||||||
|
redis:
|
||||||
|
password: "{{ redis_secret.resources.0.data['redis-password'] | b64decode }}"
|
||||||
|
|
||||||
- name: Upgrade chart using reuse_values=true
|
- name: Upgrade chart using reuse_values=true
|
||||||
helm:
|
helm:
|
||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
|
|||||||
@@ -19,6 +19,20 @@
|
|||||||
- install is changed
|
- install is changed
|
||||||
- '"--take-ownership" not in install.command'
|
- '"--take-ownership" not in install.command'
|
||||||
|
|
||||||
|
# We need to provide the actual redis password otherwise the update command
|
||||||
|
# will fail with the following:
|
||||||
|
# Error: execution error at (redis/templates/replicas/application.yaml:55:35):
|
||||||
|
# PASSWORDS ERROR: You must provide your current passwords when upgrading the release.
|
||||||
|
# Note that even after reinstallation, old credentials may be needed as they may be kept in persistent volume claims.
|
||||||
|
# Further information can be obtained at https://docs.bitnami.com/general/how-to/troubleshoot-helm-chart-issues/#credential-errors-while-upgrading-chart-releases
|
||||||
|
# 'global.redis.password' must not be empty, please add '--set global.redis.password=$REDIS_PASSWORD' to the command. To get the current value:
|
||||||
|
- name: Retrieve release password
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
namespace: "{{ helm_namespace }}"
|
||||||
|
kind: Secret
|
||||||
|
name: test-take-ownership-redis
|
||||||
|
register: redis_secret
|
||||||
|
|
||||||
- name: Upgrade chart (take-onwership flag set)
|
- name: Upgrade chart (take-onwership flag set)
|
||||||
helm:
|
helm:
|
||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
@@ -29,6 +43,9 @@
|
|||||||
values:
|
values:
|
||||||
commonLabels:
|
commonLabels:
|
||||||
take-onwership: "set"
|
take-onwership: "set"
|
||||||
|
global:
|
||||||
|
redis:
|
||||||
|
password: "{{ redis_secret.resources.0.data['redis-password'] | b64decode }}"
|
||||||
register: upgrade
|
register: upgrade
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
@@ -55,6 +72,9 @@
|
|||||||
values:
|
values:
|
||||||
commonLabels:
|
commonLabels:
|
||||||
take-onwership: "not-set"
|
take-onwership: "not-set"
|
||||||
|
global:
|
||||||
|
redis:
|
||||||
|
password: "{{ redis_secret.resources.0.data['redis-password'] | b64decode }}"
|
||||||
register: upgrade
|
register: upgrade
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
|
|||||||
@@ -31,26 +31,18 @@
|
|||||||
- name: assert warning has been raised
|
- name: assert warning has been raised
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- uninstall.warnings
|
- uninstall.warnings is defined
|
||||||
|
- '"helm uninstall support option --wait for helm release >= 3.7.0" in uninstall.warnings'
|
||||||
|
|
||||||
- name: Create temp directory
|
- name: Install Helm v4
|
||||||
tempfile:
|
ansible.builtin.include_role:
|
||||||
state: directory
|
name: install_helm
|
||||||
suffix: .test
|
vars:
|
||||||
register: _result
|
helm_version: v4.0.0
|
||||||
|
|
||||||
- set_fact:
|
|
||||||
helm_tmp_dir: "{{ _result.path }}"
|
|
||||||
|
|
||||||
- name: Unarchive Helm binary
|
|
||||||
unarchive:
|
|
||||||
src: 'https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz'
|
|
||||||
dest: "{{ helm_tmp_dir }}"
|
|
||||||
remote_src: yes
|
|
||||||
|
|
||||||
- name: Install chart
|
- name: Install chart
|
||||||
helm:
|
helm:
|
||||||
binary_path: "{{ helm_tmp_dir }}/linux-amd64/helm"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_name }}"
|
name: "{{ chart_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
@@ -59,7 +51,7 @@
|
|||||||
- name: uninstall chart again using recent version
|
- name: uninstall chart again using recent version
|
||||||
helm:
|
helm:
|
||||||
state: absent
|
state: absent
|
||||||
binary_path: "{{ helm_tmp_dir }}/linux-amd64/helm"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_name }}"
|
name: "{{ chart_name }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
wait: yes
|
wait: yes
|
||||||
@@ -96,12 +88,6 @@
|
|||||||
- _info.status is undefined
|
- _info.status is undefined
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete temp directory
|
|
||||||
file:
|
|
||||||
path: "{{ helm_tmp_dir }}"
|
|
||||||
state: absent
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Remove namespace
|
- name: Remove namespace
|
||||||
k8s:
|
k8s:
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Test helm reuse_values
|
|
||||||
vars:
|
|
||||||
helm_namespace: "{{ test_namespace[14] }}"
|
|
||||||
chart_release_values:
|
|
||||||
replica:
|
|
||||||
replicaCount: 3
|
|
||||||
master:
|
|
||||||
count: 1
|
|
||||||
kind: Deployment
|
|
||||||
chart_reuse_values:
|
|
||||||
replica:
|
|
||||||
replicaCount: 1
|
|
||||||
master:
|
|
||||||
count: 3
|
|
||||||
block:
|
|
||||||
- name: Initial chart installation
|
|
||||||
helm:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
chart_ref: oci://registry-1.docker.io/bitnamicharts/redis
|
|
||||||
release_name: test-redis
|
|
||||||
release_namespace: "{{ helm_namespace }}"
|
|
||||||
create_namespace: true
|
|
||||||
release_values: "{{ chart_release_values }}"
|
|
||||||
register: install
|
|
||||||
ignore_errors: true
|
|
||||||
when: helm_version == "v4.0.0"
|
|
||||||
|
|
||||||
- name: Debug install result
|
|
||||||
debug:
|
|
||||||
var: install
|
|
||||||
when: helm_version == "v4.0.0"
|
|
||||||
|
|
||||||
- name: Ensure helm installation was failed for v4.0.0
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- install is failed
|
|
||||||
- "'Helm version must be >=3.0.0,<4.0.0' in install.msg"
|
|
||||||
when: helm_version == "v4.0.0"
|
|
||||||
|
|
||||||
always:
|
|
||||||
- name: Remove helm namespace
|
|
||||||
k8s:
|
|
||||||
api_version: v1
|
|
||||||
kind: Namespace
|
|
||||||
name: "{{ helm_namespace }}"
|
|
||||||
state: absent
|
|
||||||
@@ -30,9 +30,9 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
ignore_errors: yes
|
ignore_errors: true
|
||||||
register: install_fail
|
register: install_fail
|
||||||
|
|
||||||
- name: "Assert that Install fail {{ chart_test }} from {{ source }}"
|
- name: "Assert that Install fail {{ chart_test }} from {{ source }}"
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
create_namespace: true
|
create_namespace: true
|
||||||
register: install_check_mode
|
register: install_check_mode
|
||||||
@@ -64,17 +64,18 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
create_namespace: true
|
create_namespace: true
|
||||||
register: install
|
register: install
|
||||||
|
|
||||||
- name: "Assert that {{ chart_test }} chart is installed from {{ source }}"
|
- name: "Assert that {{ chart_test }} chart version {{ chart_test_version }} is installed from {{ source }}"
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- install is changed
|
- install is changed
|
||||||
- install.status.chart == chart_test+"-"+chart_test_version
|
- install.status.chart == chart_test+"-"+chart_test_version
|
||||||
- install.status.status | lower == 'deployed'
|
- install.status.status | lower == 'deployed'
|
||||||
|
- install.status.release_values == {}
|
||||||
|
|
||||||
- name: Check helm_info content
|
- name: Check helm_info content
|
||||||
helm_info:
|
helm_info:
|
||||||
@@ -92,7 +93,7 @@
|
|||||||
- deployed
|
- deployed
|
||||||
register: release_state_content_info
|
register: release_state_content_info
|
||||||
|
|
||||||
- name: "Assert that {{ chart_test }} is installed from {{ source }} with helm_info"
|
- name: "Assert that {{ chart_test }} chart version {{ chart_test_version }} is installed from {{ source }} with helm_info"
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- content_info.status.chart == chart_test+"-"+chart_test_version
|
- content_info.status.chart == chart_test+"-"+chart_test_version
|
||||||
@@ -104,9 +105,10 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
register: install
|
register: install
|
||||||
|
diff: true
|
||||||
|
|
||||||
- name: Assert idempotency
|
- name: Assert idempotency
|
||||||
assert:
|
assert:
|
||||||
@@ -120,7 +122,7 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
values: "{{ chart_test_values }}"
|
values: "{{ chart_test_values }}"
|
||||||
register: install
|
register: install
|
||||||
@@ -131,17 +133,18 @@
|
|||||||
- install is changed
|
- install is changed
|
||||||
- install.status.status | lower == 'deployed'
|
- install.status.status | lower == 'deployed'
|
||||||
- install.status.chart == chart_test+"-"+chart_test_version
|
- install.status.chart == chart_test+"-"+chart_test_version
|
||||||
- "install.status['release_values'].revisionHistoryLimit == 0"
|
- install.status['release_values'] == chart_test_values
|
||||||
|
|
||||||
- name: Check idempotency after adding vars
|
- name: Check idempotency after adding vars
|
||||||
helm:
|
helm:
|
||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
values: "{{ chart_test_values }}"
|
values: "{{ chart_test_values }}"
|
||||||
register: install
|
register: install
|
||||||
|
diff: true
|
||||||
|
|
||||||
- name: Assert idempotency after add vars
|
- name: Assert idempotency after add vars
|
||||||
assert:
|
assert:
|
||||||
@@ -149,14 +152,14 @@
|
|||||||
- install is not changed
|
- install is not changed
|
||||||
- install.status.status | lower == 'deployed'
|
- install.status.status | lower == 'deployed'
|
||||||
- install.status.chart == chart_test+"-"+chart_test_version
|
- install.status.chart == chart_test+"-"+chart_test_version
|
||||||
- "install.status['release_values'].revisionHistoryLimit == 0"
|
- install.status['release_values'] == chart_test_values
|
||||||
|
|
||||||
- name: "Remove Vars to {{ chart_test }} from {{ source }}"
|
- name: "Remove Vars to {{ chart_test }} from {{ source }}"
|
||||||
helm:
|
helm:
|
||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
register: install
|
register: install
|
||||||
|
|
||||||
@@ -173,9 +176,10 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
register: install
|
register: install
|
||||||
|
diff: true
|
||||||
|
|
||||||
- name: Assert idempotency after removing vars
|
- name: Assert idempotency after removing vars
|
||||||
assert:
|
assert:
|
||||||
@@ -190,7 +194,7 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source_upgrade | default(chart_source) }}"
|
chart_ref: "{{ chart_source_upgrade | default(chart_source) }}"
|
||||||
chart_version: "{{ chart_source_version_upgrade | default(omit) }}"
|
chart_version: "{{ chart_test_version_upgrade }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
register: install
|
register: install
|
||||||
|
|
||||||
@@ -206,9 +210,10 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source_upgrade | default(chart_source) }}"
|
chart_ref: "{{ chart_source_upgrade | default(chart_source) }}"
|
||||||
chart_version: "{{ chart_source_version_upgrade | default(omit) }}"
|
chart_version: "{{ chart_test_version_upgrade }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
register: install
|
register: install
|
||||||
|
diff: true
|
||||||
|
|
||||||
- name: Assert idempotency after upgrade
|
- name: Assert idempotency after upgrade
|
||||||
assert:
|
assert:
|
||||||
@@ -237,6 +242,7 @@
|
|||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
register: install
|
register: install
|
||||||
|
diff: true
|
||||||
|
|
||||||
- name: Assert idempotency
|
- name: Assert idempotency
|
||||||
assert:
|
assert:
|
||||||
@@ -249,7 +255,7 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_replaced_name }}"
|
name: "{{ chart_release_replaced_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
register: install
|
register: install
|
||||||
|
|
||||||
@@ -277,7 +283,7 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_replaced_name }}"
|
name: "{{ chart_release_replaced_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
replace: True
|
replace: True
|
||||||
register: install
|
register: install
|
||||||
@@ -305,7 +311,7 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
values_files:
|
values_files:
|
||||||
- "{{ role_path }}/files/values.yaml"
|
- "{{ role_path }}/files/values.yaml"
|
||||||
@@ -324,7 +330,7 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
values_files:
|
values_files:
|
||||||
- "{{ role_path }}/files/values.yaml"
|
- "{{ role_path }}/files/values.yaml"
|
||||||
@@ -346,7 +352,7 @@
|
|||||||
helm_template:
|
helm_template:
|
||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
output_dir: "{{ temp_dir }}"
|
output_dir: "{{ temp_dir }}"
|
||||||
values_files:
|
values_files:
|
||||||
- "{{ role_path }}/files/values.yaml"
|
- "{{ role_path }}/files/values.yaml"
|
||||||
@@ -372,7 +378,7 @@
|
|||||||
helm_template:
|
helm_template:
|
||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
disable_hook: True
|
disable_hook: True
|
||||||
release_name: "myrelease"
|
release_name: "myrelease"
|
||||||
release_namespace: "myreleasenamespace"
|
release_namespace: "myreleasenamespace"
|
||||||
@@ -398,7 +404,7 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: "{{ chart_release_name }}"
|
name: "{{ chart_release_name }}"
|
||||||
chart_ref: "{{ chart_source }}"
|
chart_ref: "{{ chart_source }}"
|
||||||
chart_version: "{{ chart_source_version | default(omit) }}"
|
chart_version: "{{ chart_test_version }}"
|
||||||
namespace: "{{ helm_namespace }}"
|
namespace: "{{ helm_namespace }}"
|
||||||
create_namespace: true
|
create_namespace: true
|
||||||
context: does-not-exist
|
context: does-not-exist
|
||||||
@@ -417,6 +423,7 @@
|
|||||||
state: absent
|
state: absent
|
||||||
path: "{{ temp_dir }}"
|
path: "{{ temp_dir }}"
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
when: temp_dir is defined
|
||||||
|
|
||||||
- name: Remove helm namespace
|
- name: Remove helm namespace
|
||||||
k8s:
|
k8s:
|
||||||
|
|||||||
@@ -5,14 +5,34 @@
|
|||||||
name: test_helm
|
name: test_helm
|
||||||
repo_url: "{{ chart_test_repo }}"
|
repo_url: "{{ chart_test_repo }}"
|
||||||
|
|
||||||
- name: Install Chart from repository
|
- name: Create temporary file to save values in
|
||||||
include_tasks: "../tests_chart.yml"
|
ansible.builtin.tempfile:
|
||||||
vars:
|
suffix: .helm_values
|
||||||
|
register: value_file
|
||||||
|
|
||||||
|
- vars:
|
||||||
source: repository
|
source: repository
|
||||||
chart_source: "test_helm/{{ chart_test }}"
|
chart_test: k8status
|
||||||
chart_source_version: "{{ chart_test_version }}"
|
chart_source: "test_helm/k8status"
|
||||||
chart_source_version_upgrade: "{{ chart_test_version_upgrade }}"
|
chart_test_version: "0.16.1"
|
||||||
|
chart_test_version_upgrade: "0.16.2"
|
||||||
helm_namespace: "{{ test_namespace[7] }}"
|
helm_namespace: "{{ test_namespace[7] }}"
|
||||||
|
chart_test_values:
|
||||||
|
replicaCount: 3
|
||||||
|
block:
|
||||||
|
- name: Save values into file
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: "{{ chart_test_values }}"
|
||||||
|
dest: "{{ value_file.path }}"
|
||||||
|
|
||||||
|
- name: Install Chart from repository
|
||||||
|
ansible.builtin.include_tasks: "../tests_chart.yml"
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Remove temporary file
|
||||||
|
ansible.builtin.file:
|
||||||
|
state: absent
|
||||||
|
path: "{{ value_file.path }}"
|
||||||
|
|
||||||
- name: Remove chart repo
|
- name: Remove chart repo
|
||||||
helm_repository:
|
helm_repository:
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
include_tasks: "../tests_chart.yml"
|
include_tasks: "../tests_chart.yml"
|
||||||
vars:
|
vars:
|
||||||
source: url
|
source: url
|
||||||
chart_source: "https://github.com/kubernetes/ingress-nginx/releases/download/helm-chart-{{ chart_test_version }}/{{ chart_test }}-{{ chart_test_version }}.tgz"
|
chart_test: "k8status"
|
||||||
chart_source_upgrade: "https://github.com/kubernetes/ingress-nginx/releases/download/helm-chart-{{ chart_test_version_upgrade }}/{{ chart_test }}-{{ chart_test_version_upgrade }}.tgz"
|
chart_test_values:
|
||||||
|
replicaCount: 3
|
||||||
|
chart_test_version: "0.16.1"
|
||||||
|
chart_test_version_upgrade: "0.16.2"
|
||||||
|
chart_source: https://github.com/stenic/k8status/releases/download/k8status-0.16.1/k8status-0.16.1.tgz
|
||||||
|
chart_source_upgrade: https://github.com/stenic/k8status/releases/download/k8status-0.16.2/k8status-0.16.2.tgz
|
||||||
helm_namespace: "{{ test_namespace[8] }}"
|
helm_namespace: "{{ test_namespace[8] }}"
|
||||||
|
|||||||
@@ -239,6 +239,7 @@
|
|||||||
vars:
|
vars:
|
||||||
chart_local_path: '{{ _tmpd.path }}/test-chart-deployment-time'
|
chart_local_path: '{{ _tmpd.path }}/test-chart-deployment-time'
|
||||||
chart_repo_path: 'testing'
|
chart_repo_path: 'testing'
|
||||||
|
helm_binary_path: "{{ helm_binary }}"
|
||||||
always:
|
always:
|
||||||
- name: Delete temporary directory
|
- name: Delete temporary directory
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
|
|||||||
@@ -92,25 +92,11 @@
|
|||||||
path: /tmp/helm/
|
path: /tmp/helm/
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Init Helm folders
|
- name: Install old version of helm
|
||||||
file:
|
ansible.builtin.include_role:
|
||||||
path: /tmp/helm
|
name: install_helm
|
||||||
state: directory
|
vars:
|
||||||
|
helm_version: "v3.8.0"
|
||||||
- name: Set Helm old version
|
|
||||||
set_fact:
|
|
||||||
helm_archive_name: "helm-v3.8.0-linux-amd64.tar.gz"
|
|
||||||
helm_diff_old_version: "3.8.0"
|
|
||||||
|
|
||||||
- name: Unarchive Helm binary
|
|
||||||
unarchive:
|
|
||||||
src: "https://get.helm.sh/{{ helm_archive_name | default(helm_default_archive_name) }}"
|
|
||||||
dest: /tmp/helm/
|
|
||||||
remote_src: yes
|
|
||||||
retries: 10
|
|
||||||
delay: 5
|
|
||||||
register: result
|
|
||||||
until: result is not failed
|
|
||||||
|
|
||||||
- name: Upgrade helm release (with reset_then_reuse_values=true)
|
- name: Upgrade helm release (with reset_then_reuse_values=true)
|
||||||
kubernetes.core.helm:
|
kubernetes.core.helm:
|
||||||
@@ -140,7 +126,7 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
state: present
|
state: present
|
||||||
plugin_path: https://github.com/databus23/helm-diff
|
plugin_path: https://github.com/databus23/helm-diff
|
||||||
plugin_version: "{{ helm_diff_old_version }}"
|
plugin_version: "3.8.0"
|
||||||
|
|
||||||
- name: Upgrade helm release (with reset_then_reuse_values=true)
|
- name: Upgrade helm release (with reset_then_reuse_values=true)
|
||||||
kubernetes.core.helm:
|
kubernetes.core.helm:
|
||||||
@@ -166,6 +152,11 @@
|
|||||||
- '"reset_then_reuse_values requires helm diff >= 3.9.12, current version is" in helm_upgrade.msg'
|
- '"reset_then_reuse_values requires helm diff >= 3.9.12, current version is" in helm_upgrade.msg'
|
||||||
|
|
||||||
always:
|
always:
|
||||||
|
- name: Delete Helm folders
|
||||||
|
file:
|
||||||
|
path: /tmp/helm/
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Remove temporary directory
|
- name: Remove temporary directory
|
||||||
file:
|
file:
|
||||||
path: "{{ helm_dir.path }}"
|
path: "{{ helm_dir.path }}"
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
---
|
---
|
||||||
helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm"
|
|
||||||
default_kubeconfig_path: "~/.kube/config"
|
default_kubeconfig_path: "~/.kube/config"
|
||||||
test_namespace:
|
test_namespace:
|
||||||
- "helm-in-memory-kubeconfig"
|
- "helm-in-memory-kubeconfig"
|
||||||
- "helm-kubeconfig-with-ca-cert"
|
- "helm-kubeconfig-with-ca-cert"
|
||||||
- "helm-kubeconfig-with-insecure-skip-tls-verify"
|
- "helm-kubeconfig-with-insecure-skip-tls-verify"
|
||||||
|
helm_versions:
|
||||||
|
- v3.10.3
|
||||||
|
- v3.16.4
|
||||||
|
- v4.0.0
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
---
|
|
||||||
dependencies:
|
|
||||||
- remove_namespace
|
|
||||||
- install_helm
|
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- _install is failed
|
- _install is failed
|
||||||
- '"Error: Kubernetes cluster unreachable" in _install.msg'
|
- '"error: kubernetes cluster unreachable" in _install.msg | lower()'
|
||||||
|
|
||||||
- name: Test helm modules using in-memory kubeconfig
|
- name: Test helm modules using in-memory kubeconfig
|
||||||
include_tasks: "tests_helm_auth.yml"
|
include_tasks: "tests_helm_auth.yml"
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- _install is failed
|
- _install is failed
|
||||||
- '"Error: Kubernetes cluster unreachable" in _install.msg'
|
- '"error: kubernetes cluster unreachable" in _install.msg | lower()'
|
||||||
|
|
||||||
- name: Test helm modules using in-memory kubeconfig
|
- name: Test helm modules using in-memory kubeconfig
|
||||||
include_tasks: "tests_helm_auth.yml"
|
include_tasks: "tests_helm_auth.yml"
|
||||||
|
|||||||
@@ -1,21 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: Test helm with in-memory kubeconfig
|
- ansible.builtin.include_tasks: run_tests.yml
|
||||||
include_tasks: "from_in_memory_kubeconfig.yml"
|
loop: "{{ helm_versions }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: test_helm_version
|
loop_var: helm_version
|
||||||
with_items:
|
|
||||||
- "v3.10.3"
|
|
||||||
|
|
||||||
- name: Test helm with custom kubeconfig and validate_certs=false
|
|
||||||
include_tasks: "from_kubeconfig_with_validate_certs.yml"
|
|
||||||
loop_control:
|
|
||||||
loop_var: test_helm_version
|
|
||||||
with_items:
|
|
||||||
- "v3.10.3"
|
|
||||||
|
|
||||||
- name: Test helm with custom kubeconfig and ca_cert
|
|
||||||
include_tasks: "from_kubeconfig_with_cacert.yml"
|
|
||||||
loop_control:
|
|
||||||
loop_var: test_helm_version
|
|
||||||
with_items:
|
|
||||||
- "v3.10.3"
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
- name: Run tests with helm version "{{ helm_version }}"
|
||||||
|
block:
|
||||||
|
- name: "Install Helm"
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: install_helm
|
||||||
|
|
||||||
|
- name: Test helm with in-memory kubeconfig
|
||||||
|
ansible.builtin.include_tasks: "from_in_memory_kubeconfig.yml"
|
||||||
|
|
||||||
|
- name: Test helm with custom kubeconfig and validate_certs=false
|
||||||
|
include_tasks: "from_kubeconfig_with_validate_certs.yml"
|
||||||
|
|
||||||
|
- name: Test helm with custom kubeconfig and ca_cert
|
||||||
|
include_tasks: "from_kubeconfig_with_cacert.yml"
|
||||||
@@ -5,16 +5,6 @@
|
|||||||
suffix: .helm
|
suffix: .helm
|
||||||
register: _dir
|
register: _dir
|
||||||
|
|
||||||
- name: Install helm binary
|
|
||||||
block:
|
|
||||||
- name: "Install {{ test_helm_version }}"
|
|
||||||
include_role:
|
|
||||||
name: install_helm
|
|
||||||
vars:
|
|
||||||
helm_version: "{{ test_helm_version }}"
|
|
||||||
|
|
||||||
when: test_helm_version is defined
|
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
saved_kubeconfig_path: "{{ _dir.path }}/config"
|
saved_kubeconfig_path: "{{ _dir.path }}/config"
|
||||||
|
|
||||||
@@ -44,6 +34,7 @@
|
|||||||
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
ca_cert: "{{ test_ca_cert | default(omit) }}"
|
||||||
state: present
|
state: present
|
||||||
plugin_path: https://github.com/hydeenoble/helm-subenv
|
plugin_path: https://github.com/hydeenoble/helm-subenv
|
||||||
|
verify: false
|
||||||
register: plugin
|
register: plugin
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
|
|||||||
1
tests/integration/targets/helm_plain_http/.gitignore
vendored
Normal file
1
tests/integration/targets/helm_plain_http/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
redis*
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
[all]
|
[all]
|
||||||
helm-3.12.3 helm_version=v3.12.3 test_namespace=helm-plain-http-v3-12-3 tests_should_failed=true
|
helm-3.12.3 helm_version=v3.12.3 test_namespace=helm-plain-http-v3-12-3 tests_should_failed=true
|
||||||
helm-3.18.2 helm_version=v3.18.2 test_namespace=helm-plain-http-v3-18-2 tests_should_failed=false
|
helm-3.18.2 helm_version=v3.18.2 test_namespace=helm-plain-http-v3-18-2 tests_should_failed=false
|
||||||
|
helm-4.0.0 helm_version=v4.0.0 test_namespace=helm-plain-http-v4-0-0 tests_should_failed=false
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
- name: Run test for helm plain http option
|
- name: Run test for helm plain http option
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: true
|
gather_facts: true
|
||||||
|
strategy: free
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
ansible_connection: local
|
ansible_connection: local
|
||||||
@@ -8,7 +9,7 @@
|
|||||||
chart_test_oci: "oci://registry-1.docker.io/bitnamicharts/redis"
|
chart_test_oci: "oci://registry-1.docker.io/bitnamicharts/redis"
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
- setup_namespace
|
- role: setup_namespace
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- ansible.builtin.include_tasks: tasks/test.yaml
|
- ansible.builtin.include_tasks: tasks/test.yaml
|
||||||
|
|||||||
@@ -13,10 +13,6 @@
|
|||||||
vars:
|
vars:
|
||||||
helm_install_path: "{{ install_path.path }}"
|
helm_install_path: "{{ install_path.path }}"
|
||||||
|
|
||||||
- name: Set helm binary path
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
helm_binary: "{{ install_path.path }}/{{ ansible_system | lower }}-amd64/helm"
|
|
||||||
|
|
||||||
# helm
|
# helm
|
||||||
- name: Run helm with plain_http
|
- name: Run helm with plain_http
|
||||||
kubernetes.core.helm:
|
kubernetes.core.helm:
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
dependencies:
|
|
||||||
- install_helm
|
|
||||||
@@ -1,165 +1,8 @@
|
|||||||
---
|
---
|
||||||
- name: Install env plugin in check mode
|
- name: Run tests
|
||||||
helm_plugin:
|
include_tasks: run_tests.yml
|
||||||
binary_path: "{{ helm_binary }}"
|
loop_control:
|
||||||
state: present
|
loop_var: helm_version
|
||||||
plugin_path: https://github.com/adamreese/helm-env
|
with_items:
|
||||||
register: check_install_env
|
- "v3.17.0"
|
||||||
check_mode: true
|
- "v4.0.0"
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- check_install_env.changed
|
|
||||||
|
|
||||||
- name: Install env plugin
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
state: present
|
|
||||||
plugin_path: https://github.com/adamreese/helm-env
|
|
||||||
register: install_env
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- install_env.changed
|
|
||||||
|
|
||||||
- name: Gather info about all plugin
|
|
||||||
helm_plugin_info:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
register: plugin_info
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- plugin_info.plugin_list is defined
|
|
||||||
|
|
||||||
- name: Install env plugin again
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
state: present
|
|
||||||
plugin_path: https://github.com/adamreese/helm-env
|
|
||||||
register: install_env
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- not install_env.changed
|
|
||||||
|
|
||||||
- name: Uninstall env plugin in check mode
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
state: absent
|
|
||||||
plugin_name: env
|
|
||||||
register: check_uninstall_env
|
|
||||||
check_mode: true
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- check_uninstall_env.changed
|
|
||||||
|
|
||||||
- name: Uninstall env plugin
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
state: absent
|
|
||||||
plugin_name: env
|
|
||||||
register: uninstall_env
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- uninstall_env.changed
|
|
||||||
|
|
||||||
- name: Uninstall env plugin again
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
state: absent
|
|
||||||
plugin_name: env
|
|
||||||
register: uninstall_env
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- not uninstall_env.changed
|
|
||||||
|
|
||||||
# https://github.com/ansible-collections/community.kubernetes/issues/399
|
|
||||||
- block:
|
|
||||||
- name: Copy required plugin files
|
|
||||||
copy:
|
|
||||||
src: "files/sample_plugin"
|
|
||||||
dest: "/tmp/helm_plugin_test/"
|
|
||||||
|
|
||||||
- name: Install sample_plugin from the directory
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
state: present
|
|
||||||
plugin_path: "/tmp/helm_plugin_test/sample_plugin"
|
|
||||||
register: sample_plugin_output
|
|
||||||
|
|
||||||
- name: Assert that sample_plugin is installed or not
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- sample_plugin_output.changed
|
|
||||||
|
|
||||||
- name: Gather Helm plugin info
|
|
||||||
helm_plugin_info:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
register: r
|
|
||||||
|
|
||||||
- name: Set sample_plugin version
|
|
||||||
set_fact:
|
|
||||||
plugin_version: "{{ ( r.plugin_list | selectattr('name', 'equalto', plugin_name) | list )[0].version }}"
|
|
||||||
vars:
|
|
||||||
plugin_name: "sample_plugin"
|
|
||||||
|
|
||||||
- name: Assert if sample_plugin with multiline comment is installed
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- plugin_version == "0.0.1"
|
|
||||||
always:
|
|
||||||
- name: Uninstall sample_plugin
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
state: absent
|
|
||||||
plugin_name: sample_plugin
|
|
||||||
ignore_errors: yes
|
|
||||||
|
|
||||||
- block:
|
|
||||||
- name: uninstall helm plugin secrets
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
plugin_name: secrets
|
|
||||||
state: absent
|
|
||||||
|
|
||||||
- name: install helm-secrets on a specific version
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
plugin_path: https://github.com/jkroepke/helm-secrets
|
|
||||||
plugin_version: 3.4.1
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: list helm plugin
|
|
||||||
helm_plugin_info:
|
|
||||||
plugin_name: secrets
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
register: plugin_list
|
|
||||||
|
|
||||||
- name: assert that secrets has been installed with specified version
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- plugin_list.plugin_list[0].version == "3.4.1"
|
|
||||||
|
|
||||||
- name: Update helm plugin version to latest
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
plugin_name: secrets
|
|
||||||
state: latest
|
|
||||||
register: _update
|
|
||||||
|
|
||||||
- name: assert update was performed
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- _update.changed
|
|
||||||
- '"Updated plugin: secrets" in _update.stdout'
|
|
||||||
|
|
||||||
always:
|
|
||||||
- name: Uninstall sample_plugin
|
|
||||||
helm_plugin:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
state: absent
|
|
||||||
plugin_name: secrets
|
|
||||||
ignore_errors: yes
|
|
||||||
|
|||||||
195
tests/integration/targets/helm_plugin/tasks/run_tests.yml
Normal file
195
tests/integration/targets/helm_plugin/tasks/run_tests.yml
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
---
|
||||||
|
- name: "Install {{ helm_version }}"
|
||||||
|
include_role:
|
||||||
|
name: install_helm
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: Install env plugin in check mode
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: present
|
||||||
|
plugin_path: https://github.com/adamreese/helm-env
|
||||||
|
verify: false
|
||||||
|
register: check_install_env
|
||||||
|
check_mode: true
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- check_install_env.changed
|
||||||
|
|
||||||
|
- name: Install env plugin
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: present
|
||||||
|
plugin_path: https://github.com/adamreese/helm-env
|
||||||
|
verify: false
|
||||||
|
register: install_env
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- install_env.changed
|
||||||
|
|
||||||
|
- name: Gather info about all plugin
|
||||||
|
helm_plugin_info:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
register: plugin_info
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- plugin_info.plugin_list is defined
|
||||||
|
|
||||||
|
- name: Install env plugin again
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: present
|
||||||
|
plugin_path: https://github.com/adamreese/helm-env
|
||||||
|
verify: false
|
||||||
|
register: install_env
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- not install_env.changed
|
||||||
|
|
||||||
|
- name: Uninstall env plugin in check mode
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: absent
|
||||||
|
plugin_name: env
|
||||||
|
verify: false
|
||||||
|
register: check_uninstall_env
|
||||||
|
check_mode: true
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- check_uninstall_env.changed
|
||||||
|
|
||||||
|
- name: Uninstall env plugin
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: absent
|
||||||
|
plugin_name: env
|
||||||
|
register: uninstall_env
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- uninstall_env.changed
|
||||||
|
|
||||||
|
- name: Uninstall env plugin again
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: absent
|
||||||
|
plugin_name: env
|
||||||
|
register: uninstall_env
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- not uninstall_env.changed
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Uninstall env plugin
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: absent
|
||||||
|
plugin_name: env
|
||||||
|
|
||||||
|
# https://github.com/ansible-collections/community.kubernetes/issues/399
|
||||||
|
- block:
|
||||||
|
- name: Copy required plugin files
|
||||||
|
copy:
|
||||||
|
src: "files/sample_plugin"
|
||||||
|
dest: "/tmp/helm_plugin_test/"
|
||||||
|
|
||||||
|
- name: Install sample_plugin from the directory
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: present
|
||||||
|
plugin_path: "/tmp/helm_plugin_test/sample_plugin"
|
||||||
|
register: sample_plugin_output
|
||||||
|
|
||||||
|
- name: Assert that sample_plugin is installed or not
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- sample_plugin_output.changed
|
||||||
|
|
||||||
|
- name: Gather Helm plugin info
|
||||||
|
helm_plugin_info:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
register: r
|
||||||
|
|
||||||
|
- name: Set sample_plugin version
|
||||||
|
set_fact:
|
||||||
|
plugin_version: "{{ ( r.plugin_list | selectattr('name', 'equalto', plugin_name) | list )[0].version }}"
|
||||||
|
vars:
|
||||||
|
plugin_name: "sample_plugin"
|
||||||
|
|
||||||
|
- name: Assert if sample_plugin with multiline comment is installed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- plugin_version == "0.0.1"
|
||||||
|
always:
|
||||||
|
- name: Uninstall sample_plugin
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: absent
|
||||||
|
plugin_name: sample_plugin
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: uninstall helm plugin unittest
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
plugin_name: unittest
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: install helm-unittest on a specific version
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
plugin_path: https://github.com/helm-unittest/helm-unittest
|
||||||
|
plugin_version: v1.0.1
|
||||||
|
verify: false
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: list helm plugin
|
||||||
|
helm_plugin_info:
|
||||||
|
plugin_name: unittest
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
register: plugin_list
|
||||||
|
|
||||||
|
- name: assert that unittest has been installed with specified version
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- plugin_list.plugin_list[0].version == "1.0.1"
|
||||||
|
|
||||||
|
- name: Update helm plugin version to latest (check mode)
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
plugin_name: unittest
|
||||||
|
state: latest
|
||||||
|
register: _update_checkmode
|
||||||
|
check_mode: true
|
||||||
|
|
||||||
|
- name: Assert that module reported change while running in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- _update_checkmode.changed
|
||||||
|
- '"Updated plugin: unittest" not in _update_checkmode.stdout'
|
||||||
|
|
||||||
|
- name: Update helm plugin version to latest
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
plugin_name: unittest
|
||||||
|
state: latest
|
||||||
|
register: _update
|
||||||
|
|
||||||
|
- name: assert update was performed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- _update.changed
|
||||||
|
- '"Updated plugin: unittest" in _update.stdout'
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Uninstall sample_plugin
|
||||||
|
helm_plugin:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
state: absent
|
||||||
|
plugin_name: unittest
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
- 3.8.0
|
- 3.8.0
|
||||||
- 3.1.0
|
- 3.1.0
|
||||||
- 3.0.0
|
- 3.0.0
|
||||||
- 2.3.0
|
- 4.0.0
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Create temp directory for helm tests
|
- name: Create temp directory for helm tests
|
||||||
@@ -20,37 +20,13 @@
|
|||||||
- set_fact:
|
- set_fact:
|
||||||
destination: "{{ temp_dir }}"
|
destination: "{{ temp_dir }}"
|
||||||
|
|
||||||
- name: Create Helm directories
|
- name: Install Helm versions
|
||||||
file:
|
ansible.builtin.include_role:
|
||||||
state: directory
|
name: install_helm
|
||||||
path: "{{ temp_dir }}/{{ item }}"
|
loop: "{{ helm_versions }}"
|
||||||
with_items: "{{ helm_versions }}"
|
|
||||||
|
|
||||||
- name: Unarchive Helm binary
|
|
||||||
unarchive:
|
|
||||||
src: "https://get.helm.sh/helm-v{{ item }}-linux-amd64.tar.gz"
|
|
||||||
dest: "{{ temp_dir }}/{{ item }}"
|
|
||||||
remote_src: yes
|
|
||||||
with_items: "{{ helm_versions }}"
|
|
||||||
|
|
||||||
# Testing helm pull with helm version == 2.3.0
|
|
||||||
- block:
|
|
||||||
- name: Assert that helm pull failed with helm <= 3.0.0
|
|
||||||
helm_pull:
|
|
||||||
binary_path: "{{ helm_path }}"
|
|
||||||
chart_ref: https://github.com/grafana/helm-charts/releases/download/grafana-5.6.0/grafana-5.6.0.tgz
|
|
||||||
destination: "{{ destination }}"
|
|
||||||
ignore_errors: true
|
|
||||||
register: _result
|
|
||||||
|
|
||||||
- name: assert that module failed with proper message
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- _result is failed
|
|
||||||
- _result.msg == "Helm version must be >=3.0.0,<4.0.0, current version is 2.3.0"
|
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
helm_path: "{{ temp_dir }}/2.3.0/linux-amd64/helm"
|
helm_version: "v{{ item }}"
|
||||||
|
helm_install_path: "{{ temp_dir }}/{{ item }}"
|
||||||
|
|
||||||
# Testing helm pull with helm version == 3.0.0
|
# Testing helm pull with helm version == 3.0.0
|
||||||
- block:
|
- block:
|
||||||
@@ -103,7 +79,7 @@
|
|||||||
- _result.msg == "Parameter chart_ca_cert requires helm >= 3.1.0, current version is 3.0.0"
|
- _result.msg == "Parameter chart_ca_cert requires helm >= 3.1.0, current version is 3.0.0"
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
helm_path: "{{ temp_dir }}/3.0.0/linux-amd64/helm"
|
helm_path: "{{ temp_dir }}/3.0.0/helm"
|
||||||
|
|
||||||
# Testing helm pull with helm version == 3.1.0
|
# Testing helm pull with helm version == 3.1.0
|
||||||
- block:
|
- block:
|
||||||
@@ -143,7 +119,7 @@
|
|||||||
- _result.msg == "Parameter skip_tls_certs_check requires helm >= 3.3.0, current version is 3.1.0"
|
- _result.msg == "Parameter skip_tls_certs_check requires helm >= 3.3.0, current version is 3.1.0"
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
helm_path: "{{ temp_dir }}/3.1.0/linux-amd64/helm"
|
helm_path: "{{ temp_dir }}/3.1.0/helm"
|
||||||
|
|
||||||
# Testing helm pull with helm version == 3.8.0
|
# Testing helm pull with helm version == 3.8.0
|
||||||
- block:
|
- block:
|
||||||
@@ -317,7 +293,7 @@
|
|||||||
- _chart_after_force.stat.isdir
|
- _chart_after_force.stat.isdir
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
helm_path: "{{ temp_dir }}/3.8.0/linux-amd64/helm"
|
helm_path: "{{ temp_dir }}/3.8.0/helm"
|
||||||
|
|
||||||
|
|
||||||
always:
|
always:
|
||||||
|
|||||||
@@ -5,5 +5,9 @@ username: testuser
|
|||||||
password: testpassword
|
password: testpassword
|
||||||
wrong_password: 'WrongPassword'
|
wrong_password: 'WrongPassword'
|
||||||
registry_name: oci_registry
|
registry_name: oci_registry
|
||||||
registry_port: 5000
|
registry_port: 5002
|
||||||
test_chart: https://github.com/grafana/helm-charts/releases/download/k8s-monitoring-1.6.8/k8s-monitoring-1.6.8.tgz
|
test_chart: https://github.com/grafana/helm-charts/releases/download/k8s-monitoring-1.6.8/k8s-monitoring-1.6.8.tgz
|
||||||
|
helm_versions:
|
||||||
|
- v3.17.0
|
||||||
|
- v3.20.0
|
||||||
|
- v4.0.0
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
dependencies:
|
|
||||||
- install_helm
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Run module test
|
|
||||||
# using a shell and command module to run the test as test can be non-idempotent
|
|
||||||
# and it allow to not install any additional dependencies
|
|
||||||
block:
|
|
||||||
- name: Ensure that helm is installed
|
|
||||||
ansible.builtin.shell: helm version --client --short | grep v3
|
|
||||||
register: _helm_version
|
|
||||||
failed_when: _helm_version.rc != 0
|
|
||||||
|
|
||||||
- name: Ensure that Docker demon is running
|
|
||||||
ansible.builtin.command: "docker info"
|
|
||||||
register: _docker_info
|
|
||||||
failed_when: _docker_info.rc != 0
|
|
||||||
|
|
||||||
- name: Create a tmpfile htpasswd directory
|
|
||||||
ansible.builtin.tempfile:
|
|
||||||
state: directory
|
|
||||||
suffix: .httppasswd
|
|
||||||
register: _tmpfile
|
|
||||||
|
|
||||||
- name: Copy htpasswd to the tmpfile directory
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: registry.password
|
|
||||||
dest: "{{ _tmpfile.path }}/registry.password"
|
|
||||||
|
|
||||||
- name: Setup the registry
|
|
||||||
ansible.builtin.command: >-
|
|
||||||
docker run -d --rm
|
|
||||||
-p {{ registry_port }}:5000
|
|
||||||
--name "{{ registry_name }}"
|
|
||||||
-v "{{ _tmpfile.path }}:/auth"
|
|
||||||
-e "REGISTRY_AUTH=htpasswd"
|
|
||||||
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm"
|
|
||||||
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/registry.password
|
|
||||||
registry:2
|
|
||||||
register: _setup_registry
|
|
||||||
failed_when: _setup_registry.rc != 0
|
|
||||||
|
|
||||||
- name: Ensure that the registry is running and rechable
|
|
||||||
ansible.builtin.wait_for:
|
|
||||||
host: localhost
|
|
||||||
port: "{{ registry_port }}"
|
|
||||||
|
|
||||||
- name: Test the registry with correct credentials to ensure that the registry is running
|
|
||||||
ansible.builtin.shell: >-
|
|
||||||
echo {{ password | quote }} | helm registry login localhost:{{ registry_port }}
|
|
||||||
-u {{ username }} --password-stdin
|
|
||||||
register: _login_correct
|
|
||||||
failed_when: _login_correct.rc != 0
|
|
||||||
|
|
||||||
- name: Clean up credentials to run test on clean environment
|
|
||||||
ansible.builtin.shell: >-
|
|
||||||
helm registry logout localhost:{{ registry_port }}
|
|
||||||
register: _logout
|
|
||||||
failed_when: _logout.rc != 0
|
|
||||||
|
|
||||||
- name: Create directory for helm chart
|
|
||||||
ansible.builtin.tempfile:
|
|
||||||
state: directory
|
|
||||||
suffix: ".helm"
|
|
||||||
register: _destination
|
|
||||||
|
|
||||||
- name: Pull test helm chart
|
|
||||||
ansible.builtin.uri:
|
|
||||||
url: "{{ test_chart }}"
|
|
||||||
dest: "{{ _destination.path }}/k8s-monitoring-1.6.8.tgz"
|
|
||||||
return_content: no
|
|
||||||
status_code: 200
|
|
||||||
|
|
||||||
- name: Test module helm_registry_auth with correct credentials
|
|
||||||
helm_registry_auth:
|
|
||||||
username: "{{ username }}"
|
|
||||||
password: "{{ password }}"
|
|
||||||
host: localhost:{{ registry_port }}
|
|
||||||
state: present
|
|
||||||
register: _helm_registry_auth_correct
|
|
||||||
|
|
||||||
- name: Assert that the registry is logged in
|
|
||||||
# Helm binary prints the message to stderr, refence: https://github.com/helm/helm/issues/13464
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- "'Login Succeeded' in _helm_registry_auth_correct.stderr"
|
|
||||||
- "'{{ password }}' not in _helm_registry_auth_correct.command"
|
|
||||||
- "'{{ password }}' not in _helm_registry_auth_correct.stdout"
|
|
||||||
- "'{{ password }}' not in _helm_registry_auth_correct.stderr"
|
|
||||||
|
|
||||||
- name: Ensure that push to the registry is working
|
|
||||||
ansible.builtin.shell: >-
|
|
||||||
helm push "{{ _destination.path }}/k8s-monitoring-1.6.8.tgz" oci://localhost:{{ registry_port }}/test/
|
|
||||||
register: _save_chart
|
|
||||||
failed_when: _save_chart.rc != 0
|
|
||||||
|
|
||||||
- name: Assert that the chart is saved
|
|
||||||
# Helm binary prints the message to stderr, refence: https://github.com/helm/helm/issues/13464
|
|
||||||
assert:
|
|
||||||
that: "'Pushed: localhost:{{ registry_port }}/test/k8s-monitoring' in _save_chart.stderr"
|
|
||||||
|
|
||||||
|
|
||||||
- name: Test logout
|
|
||||||
helm_registry_auth:
|
|
||||||
host: localhost:{{ registry_port }}
|
|
||||||
state: absent
|
|
||||||
register: _helm_registry_auth_logout
|
|
||||||
|
|
||||||
- name: Assert logout
|
|
||||||
# Helm binary prints the message to stderr
|
|
||||||
assert:
|
|
||||||
that: "'Removing login credentials' in _helm_registry_auth_logout.stderr"
|
|
||||||
|
|
||||||
- name: Test idempotency of logout with helm < 3.18.0
|
|
||||||
when: _helm_version.stdout is ansible.builtin.version('v3.18.0', '<')
|
|
||||||
block:
|
|
||||||
|
|
||||||
- name: Test logout idempotency
|
|
||||||
helm_registry_auth:
|
|
||||||
host: localhost:{{ registry_port }}
|
|
||||||
state: absent
|
|
||||||
register: _helm_registry_auth_logout_idempotency
|
|
||||||
|
|
||||||
- name: Assert logout operation did not report change
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that: _helm_registry_auth_logout_idempotency is not changed
|
|
||||||
|
|
||||||
- name: Ensure that not able to push to the registry
|
|
||||||
ansible.builtin.shell: >-
|
|
||||||
helm push "{{ _destination.path }}/k8s-monitoring-1.6.8.tgz" oci://localhost:{{ registry_port }}/test/
|
|
||||||
register: _save_chart
|
|
||||||
failed_when: _save_chart.rc == 0
|
|
||||||
|
|
||||||
- name: Read content of ~/.config/helm/registry/config.json
|
|
||||||
ansible.builtin.slurp:
|
|
||||||
src: ~/.config/helm/registry/config.json
|
|
||||||
register: _config_json
|
|
||||||
|
|
||||||
- name: Assert that auth data is remove and the chart is not saved
|
|
||||||
# Helm binary prints the message to stderr
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- "'push access denied' in _save_chart.stderr or 'basic credential not found' in _save_chart.stderr"
|
|
||||||
- "_save_chart.rc != 0"
|
|
||||||
- "'localhost:{{ registry_port }}' not in _config_json.content | b64decode"
|
|
||||||
|
|
||||||
- name: Test module helm_registry_auth with wrong credentials
|
|
||||||
helm_registry_auth:
|
|
||||||
username: "{{ username }}"
|
|
||||||
password: "{{ wrong_password }}"
|
|
||||||
host: localhost:{{ registry_port }}
|
|
||||||
state: present
|
|
||||||
register: _helm_registry_auth_wrong
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Read content of ~/.config/helm/registry/config.json
|
|
||||||
ansible.builtin.slurp:
|
|
||||||
src: ~/.config/helm/registry/config.json
|
|
||||||
register: _config_json
|
|
||||||
|
|
||||||
- name: Assert that the registry is not logged in and auth data is not saved
|
|
||||||
ansible.builtin.assert:
|
|
||||||
that:
|
|
||||||
- "'401' in _helm_registry_auth_wrong.stderr"
|
|
||||||
- "'unauthorized' in _helm_registry_auth_wrong.stderr | lower"
|
|
||||||
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.command"
|
|
||||||
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stdout"
|
|
||||||
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stderr"
|
|
||||||
- "'localhost:{{ registry_port }}' not in _config_json.content | b64decode"
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
always:
|
|
||||||
- name: Stop and remove the registry
|
|
||||||
ansible.builtin.command: docker stop {{ registry_name }}
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Remove the tmpfile
|
|
||||||
ansible.builtin.file:
|
|
||||||
state: absent
|
|
||||||
path: "{{ item }}"
|
|
||||||
force: true
|
|
||||||
loop:
|
|
||||||
- "{{ _tmpfile.path }}"
|
|
||||||
- "{{ _destination.path }}"
|
|
||||||
ignore_errors: true
|
|
||||||
60
tests/integration/targets/helm_registry_auth/tasks/main.yml
Normal file
60
tests/integration/targets/helm_registry_auth/tasks/main.yml
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
- name: Run tests for helm_registry_auth with different helm versions
|
||||||
|
block:
|
||||||
|
- name: Create temporary directory to install helm binaries
|
||||||
|
ansible.builtin.tempfile:
|
||||||
|
state: directory
|
||||||
|
suffix: .helm
|
||||||
|
register: _tmpdir
|
||||||
|
|
||||||
|
- name: Ensure that Docker demon is running
|
||||||
|
ansible.builtin.command: "docker info"
|
||||||
|
register: _docker_info
|
||||||
|
failed_when: _docker_info.rc != 0
|
||||||
|
|
||||||
|
- name: Copy htpasswd to the tmpfile directory
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: registry.password
|
||||||
|
dest: "{{ _tmpdir.path }}/registry.password"
|
||||||
|
|
||||||
|
- name: Pull test helm chart
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ test_chart }}"
|
||||||
|
dest: "{{ _tmpdir.path }}/k8s-monitoring-1.6.8.tgz"
|
||||||
|
return_content: no
|
||||||
|
status_code: 200
|
||||||
|
|
||||||
|
- name: Setup the registry
|
||||||
|
ansible.builtin.command: >-
|
||||||
|
docker run -d --rm
|
||||||
|
-p {{ registry_port }}:5000
|
||||||
|
--name "{{ registry_name }}"
|
||||||
|
-v "{{ _tmpdir.path }}:/auth"
|
||||||
|
-e "REGISTRY_AUTH=htpasswd"
|
||||||
|
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm"
|
||||||
|
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/registry.password
|
||||||
|
registry:2
|
||||||
|
register: _setup_registry
|
||||||
|
failed_when: _setup_registry.rc != 0
|
||||||
|
|
||||||
|
- name: Ensure that the registry is running and rechable
|
||||||
|
ansible.builtin.wait_for:
|
||||||
|
host: localhost
|
||||||
|
port: "{{ registry_port }}"
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
ansible.builtin.include_tasks: run_tests.yml
|
||||||
|
loop: "{{ helm_versions }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: helm_version
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Stop and remove the registry
|
||||||
|
ansible.builtin.command: docker stop {{ registry_name }}
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Delete temporary directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
state: absent
|
||||||
|
path: "{{ _tmpdir.path }}"
|
||||||
|
ignore_errors: true
|
||||||
108
tests/integration/targets/helm_registry_auth/tasks/run_tests.yml
Normal file
108
tests/integration/targets/helm_registry_auth/tasks/run_tests.yml
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
---
|
||||||
|
- block:
|
||||||
|
- name: Install helm versions
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: install_helm
|
||||||
|
|
||||||
|
# - name: Test the registry with correct credentials to ensure that the registry is running
|
||||||
|
# ansible.builtin.shell: >-
|
||||||
|
# echo {{ password | quote }} | {{ helm_binary }} registry login localhost:{{ registry_port }}
|
||||||
|
# -u {{ username }} --password-stdin --plain-http
|
||||||
|
# register: _login_correct
|
||||||
|
# failed_when: _login_correct.rc != 0
|
||||||
|
|
||||||
|
# - name: Clean up credentials to run test on clean environment
|
||||||
|
# ansible.builtin.shell: >-
|
||||||
|
# {{ helm_binary }} registry logout localhost:{{ registry_port }}
|
||||||
|
# register: _logout
|
||||||
|
# failed_when: _logout.rc != 0
|
||||||
|
|
||||||
|
- name: Test module helm_registry_auth with correct credentials
|
||||||
|
helm_registry_auth:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
username: "{{ username }}"
|
||||||
|
password: "{{ password }}"
|
||||||
|
host: localhost:{{ registry_port }}
|
||||||
|
plain_http: true
|
||||||
|
state: present
|
||||||
|
register: _helm_registry_auth_correct
|
||||||
|
|
||||||
|
- name: Assert that the registry is logged in
|
||||||
|
# Helm binary prints the message to stderr, refence: https://github.com/helm/helm/issues/13464
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "'Login Succeeded' in _helm_registry_auth_correct.stdout_lines + _helm_registry_auth_correct.stderr_lines"
|
||||||
|
- password not in _helm_registry_auth_correct.command
|
||||||
|
- password not in _helm_registry_auth_correct.stdout
|
||||||
|
- password not in _helm_registry_auth_correct.stderr
|
||||||
|
|
||||||
|
- name: Ensure that push to the registry is working
|
||||||
|
ansible.builtin.shell: >-
|
||||||
|
{{ helm_binary }} push --plain-http "{{ _tmpdir.path }}/k8s-monitoring-1.6.8.tgz" oci://localhost:{{ registry_port }}/test/
|
||||||
|
register: _save_chart
|
||||||
|
failed_when: _save_chart.rc != 0
|
||||||
|
|
||||||
|
- name: Assert that the chart is saved
|
||||||
|
# Helm binary prints the message to stderr, refence: https://github.com/helm/helm/issues/13464
|
||||||
|
assert:
|
||||||
|
that: "'Pushed: localhost:' + registry_port | string + '/test/k8s-monitoring' in _save_chart.stderr"
|
||||||
|
|
||||||
|
- name: Test logout
|
||||||
|
helm_registry_auth:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
host: localhost:{{ registry_port }}
|
||||||
|
state: absent
|
||||||
|
register: _helm_registry_auth_logout
|
||||||
|
|
||||||
|
- name: Assert logout
|
||||||
|
# Helm binary prints the message to stderr
|
||||||
|
assert:
|
||||||
|
that: "'Removing login credentials' in _helm_registry_auth_logout.stderr"
|
||||||
|
|
||||||
|
- name: Ensure that not able to push to the registry
|
||||||
|
ansible.builtin.shell: >-
|
||||||
|
{{ helm_binary }} push --plain-http "{{ _tmpdir.path }}/k8s-monitoring-1.6.8.tgz" oci://localhost:{{ registry_port }}/test/
|
||||||
|
register: _save_chart
|
||||||
|
failed_when: _save_chart.rc == 0
|
||||||
|
|
||||||
|
- name: Assert that auth data is remove and the chart is not saved
|
||||||
|
# Helm binary prints the message to stderr
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- "'push access denied' in _save_chart.stderr or 'basic credential not found' in _save_chart.stderr"
|
||||||
|
- "_save_chart.rc != 0"
|
||||||
|
|
||||||
|
- name: Test idempotency of logout with helm < 3.18.0
|
||||||
|
when: helm_version is ansible.builtin.version('v3.18.0', '<')
|
||||||
|
block:
|
||||||
|
|
||||||
|
- name: Test logout idempotency
|
||||||
|
helm_registry_auth:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
host: localhost:{{ registry_port }}
|
||||||
|
state: absent
|
||||||
|
register: _helm_registry_auth_logout_idempotency
|
||||||
|
|
||||||
|
- name: Assert logout operation did not report change
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: _helm_registry_auth_logout_idempotency is not changed
|
||||||
|
|
||||||
|
- name: Test module helm_registry_auth with wrong credentials
|
||||||
|
helm_registry_auth:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
username: "{{ username }}"
|
||||||
|
password: "{{ wrong_password }}"
|
||||||
|
host: localhost:{{ registry_port }}
|
||||||
|
state: present
|
||||||
|
plain_http: true
|
||||||
|
register: _helm_registry_auth_wrong
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert that the registry is not logged in and auth data is not saved
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- "'401' in _helm_registry_auth_wrong.stderr"
|
||||||
|
- "'unauthorized' in _helm_registry_auth_wrong.stderr | lower"
|
||||||
|
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.command"
|
||||||
|
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stdout"
|
||||||
|
- "'{{ wrong_password }}' not in _helm_registry_auth_correct.stderr"
|
||||||
@@ -1,5 +1,2 @@
|
|||||||
time=20
|
time=1
|
||||||
helm_repository
|
helm_repository
|
||||||
helm_info
|
|
||||||
helm
|
|
||||||
helm_template
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
---
|
---
|
||||||
chart_test_repo: "https://kubernetes.github.io/ingress-nginx"
|
chart_test_repo: "https://kubernetes.github.io/ingress-nginx"
|
||||||
helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm"
|
helm_versions:
|
||||||
|
- v3.20.0
|
||||||
|
- v4.0.0
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
collections:
|
|
||||||
- kubernetes.core
|
|
||||||
dependencies:
|
|
||||||
- install_helm
|
|
||||||
@@ -1,101 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: "Ensure test_helm_repo doesn't exist"
|
- name: Run test for helm_repository module
|
||||||
helm_repository:
|
ansible.builtin.include_tasks: run_tests.yml
|
||||||
binary_path: "{{ helm_binary }}"
|
loop: "{{ helm_versions }}"
|
||||||
name: test_helm_repo
|
loop_control:
|
||||||
state: absent
|
loop_var: helm_version
|
||||||
|
|
||||||
- name: Add test_helm_repo chart repository
|
|
||||||
helm_repository:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
name: test_helm_repo
|
|
||||||
repo_url: "{{ chart_test_repo }}"
|
|
||||||
register: repository
|
|
||||||
|
|
||||||
- name: Assert that test_helm_repo repository is added
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- repository is changed
|
|
||||||
- '"--insecure-skip-tls-verify" not in repository.command'
|
|
||||||
|
|
||||||
- name: Check idempotency
|
|
||||||
helm_repository:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
name: test_helm_repo
|
|
||||||
repo_url: "{{ chart_test_repo }}"
|
|
||||||
register: repository
|
|
||||||
|
|
||||||
- name: Assert idempotency
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- repository is not changed
|
|
||||||
|
|
||||||
- name: Failed to add repository with the same name
|
|
||||||
helm_repository:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
name: test_helm_repo
|
|
||||||
repo_url: "https://other-charts.url"
|
|
||||||
register: repository_errors
|
|
||||||
ignore_errors: yes
|
|
||||||
|
|
||||||
- name: Assert that adding repository with the same name failed
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- repository_errors is failed
|
|
||||||
|
|
||||||
- name: Succesfully add repository with the same name when forcing
|
|
||||||
helm_repository:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
name: test_helm_repo
|
|
||||||
repo_url: "{{ chart_test_repo }}"
|
|
||||||
force: true
|
|
||||||
register: repository
|
|
||||||
|
|
||||||
- name: Assert that test_helm_repo repository is changed
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- repository is changed
|
|
||||||
|
|
||||||
- name: Remove test_helm_repo chart repository
|
|
||||||
helm_repository:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
name: test_helm_repo
|
|
||||||
state: absent
|
|
||||||
register: repository
|
|
||||||
|
|
||||||
- name: Assert that test_helm_repo repository is removed
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- repository is changed
|
|
||||||
|
|
||||||
- name: Check idempotency after remove
|
|
||||||
helm_repository:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
name: test_helm_repo
|
|
||||||
state: absent
|
|
||||||
register: repository
|
|
||||||
|
|
||||||
- name: Assert idempotency
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- repository is not changed
|
|
||||||
|
|
||||||
- name: Add test_helm_repo chart repository as insecure
|
|
||||||
helm_repository:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
name: test_helm_repo
|
|
||||||
repo_url: "{{ chart_test_repo }}"
|
|
||||||
insecure_skip_tls_verify: true
|
|
||||||
register: repository
|
|
||||||
|
|
||||||
- name: Assert that repository added and flag set
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- repository is changed
|
|
||||||
- '"--insecure-skip-tls-verify" in repository.command'
|
|
||||||
|
|
||||||
- name: Clean test_helm_repo chart repository
|
|
||||||
helm_repository:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
name: test_helm_repo
|
|
||||||
state: absent
|
|
||||||
|
|||||||
105
tests/integration/targets/helm_repository/tasks/run_tests.yml
Normal file
105
tests/integration/targets/helm_repository/tasks/run_tests.yml
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
---
|
||||||
|
- name: "Install helm version {{ helm_version }}"
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: install_helm
|
||||||
|
|
||||||
|
- name: "Ensure test_helm_repo doesn't exist"
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Add test_helm_repo chart repository
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo
|
||||||
|
repo_url: "{{ chart_test_repo }}"
|
||||||
|
register: repository
|
||||||
|
|
||||||
|
- name: Assert that test_helm_repo repository is added
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository is changed
|
||||||
|
- '"--insecure-skip-tls-verify" not in repository.command'
|
||||||
|
|
||||||
|
- name: Check idempotency
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo
|
||||||
|
repo_url: "{{ chart_test_repo }}"
|
||||||
|
register: repository
|
||||||
|
|
||||||
|
- name: Assert idempotency
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository is not changed
|
||||||
|
|
||||||
|
- name: Failed to add repository with the same name
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo
|
||||||
|
repo_url: "https://other-charts.url"
|
||||||
|
register: repository_errors
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert that adding repository with the same name failed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository_errors is failed
|
||||||
|
|
||||||
|
- name: Succesfully add repository with the same name when forcing
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo
|
||||||
|
repo_url: "{{ chart_test_repo }}"
|
||||||
|
force: true
|
||||||
|
register: repository
|
||||||
|
|
||||||
|
- name: Assert that test_helm_repo repository is changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository is changed
|
||||||
|
|
||||||
|
- name: Remove test_helm_repo chart repository
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo
|
||||||
|
state: absent
|
||||||
|
register: repository
|
||||||
|
|
||||||
|
- name: Assert that test_helm_repo repository is removed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository is changed
|
||||||
|
|
||||||
|
- name: Check idempotency after remove
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo
|
||||||
|
state: absent
|
||||||
|
register: repository
|
||||||
|
|
||||||
|
- name: Assert idempotency
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository is not changed
|
||||||
|
|
||||||
|
- name: Add test_helm_repo chart repository as insecure
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo
|
||||||
|
repo_url: "{{ chart_test_repo }}"
|
||||||
|
insecure_skip_tls_verify: true
|
||||||
|
register: repository
|
||||||
|
|
||||||
|
- name: Assert that repository added and flag set
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository is changed
|
||||||
|
- '"--insecure-skip-tls-verify" in repository.command'
|
||||||
|
|
||||||
|
- name: Clean test_helm_repo chart repository
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo
|
||||||
|
state: absent
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
---
|
---
|
||||||
helm_binary: "/tmp/helm/{{ ansible_system | lower }}-amd64/helm"
|
|
||||||
helm_namespace: helm-set-values
|
helm_namespace: helm-set-values
|
||||||
|
helm_versions:
|
||||||
|
- v3.10.3
|
||||||
|
- v4.0.0
|
||||||
|
|||||||
@@ -25,79 +25,14 @@
|
|||||||
- user_values.status["release_values"]["phase"] == "integration"
|
- user_values.status["release_values"]["phase"] == "integration"
|
||||||
- user_values.status["release_values"]["versioned"] is false
|
- user_values.status["release_values"]["versioned"] is false
|
||||||
|
|
||||||
# install chart using set_values and release_values
|
- block:
|
||||||
- name: Install helm binary (> 3.10.0) requires to use set-json
|
|
||||||
include_role:
|
|
||||||
name: install_helm
|
|
||||||
vars:
|
|
||||||
helm_version: "v3.10.3"
|
|
||||||
|
|
||||||
- name: Install helm using set_values parameters
|
|
||||||
helm:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
chart_ref: oci://registry-1.docker.io/bitnamicharts/apache
|
|
||||||
release_name: test-apache
|
|
||||||
release_namespace: "{{ helm_namespace }}"
|
|
||||||
create_namespace: true
|
|
||||||
set_values:
|
|
||||||
- value: 'master.image={"registry": "docker.io", "repository": "bitnami/apache", "tag": "2.4.54-debian-11-r74"}'
|
|
||||||
value_type: json
|
|
||||||
release_values:
|
|
||||||
replicaCount: 3
|
|
||||||
|
|
||||||
- name: Get release info
|
|
||||||
helm_info:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
release_name: test-apache
|
|
||||||
release_namespace: "{{ helm_namespace }}"
|
|
||||||
register: values
|
|
||||||
|
|
||||||
- name: Assert that release was created with user-defined variables
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- values.status["release_values"].replicaCount == 3
|
|
||||||
- values.status["release_values"].master.image.registry == "docker.io"
|
|
||||||
- values.status["release_values"].master.image.repository == "bitnami/apache"
|
|
||||||
- values.status["release_values"].master.image.tag == "2.4.54-debian-11-r74"
|
|
||||||
|
|
||||||
# install chart using set_values and values_files
|
|
||||||
- name: create temporary file to save values in
|
- name: create temporary file to save values in
|
||||||
tempfile:
|
tempfile:
|
||||||
suffix: .yml
|
suffix: .yml
|
||||||
register: ymlfile
|
register: ymlfile
|
||||||
|
|
||||||
- block:
|
- ansible.builtin.include_tasks: run_tests.yml
|
||||||
- name: copy content into values file
|
loop: "{{ helm_versions }}"
|
||||||
copy:
|
|
||||||
content: |
|
|
||||||
---
|
|
||||||
mode: distributed
|
|
||||||
dest: "{{ ymlfile.path }}"
|
|
||||||
|
|
||||||
- name: Install helm using set_values parameters
|
|
||||||
helm:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
chart_ref: oci://registry-1.docker.io/bitnamicharts/minio
|
|
||||||
release_name: test-minio
|
|
||||||
release_namespace: "{{ helm_namespace }}"
|
|
||||||
create_namespace: true
|
|
||||||
set_values:
|
|
||||||
- value: 'disableWebUI=true'
|
|
||||||
values_files:
|
|
||||||
- "{{ ymlfile.path }}"
|
|
||||||
|
|
||||||
- name: Get release info
|
|
||||||
helm_info:
|
|
||||||
binary_path: "{{ helm_binary }}"
|
|
||||||
release_name: test-minio
|
|
||||||
release_namespace: "{{ helm_namespace }}"
|
|
||||||
register: values
|
|
||||||
|
|
||||||
- name: Assert that release was created with user-defined variables
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- values.status["release_values"].mode == "distributed"
|
|
||||||
- values.status["release_values"].disableWebUI is true
|
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete temporary file
|
- name: Delete temporary file
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
---
|
||||||
|
# install chart using set_values and release_values
|
||||||
|
- name: 'Install helm binary (> 3.10.0) requires to use set-json (helm_version={{ item }})'
|
||||||
|
include_role:
|
||||||
|
name: install_helm
|
||||||
|
vars:
|
||||||
|
helm_version: "{{ item }}"
|
||||||
|
|
||||||
|
- name: Install helm using set_values parameters
|
||||||
|
helm:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
chart_ref: oci://registry-1.docker.io/bitnamicharts/apache
|
||||||
|
release_name: 'test-apache-{{ item }}'
|
||||||
|
release_namespace: "{{ helm_namespace }}"
|
||||||
|
create_namespace: true
|
||||||
|
set_values:
|
||||||
|
- value: 'master.image={"registry": "docker.io", "repository": "bitnami/apache", "tag": "2.4.54-debian-11-r74"}'
|
||||||
|
value_type: json
|
||||||
|
release_values:
|
||||||
|
replicaCount: 3
|
||||||
|
|
||||||
|
- name: Get release info
|
||||||
|
helm_info:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
release_name: 'test-apache-{{ item }}'
|
||||||
|
release_namespace: "{{ helm_namespace }}"
|
||||||
|
register: values
|
||||||
|
|
||||||
|
- name: Assert that release was created with user-defined variables
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- values.status["release_values"].replicaCount == 3
|
||||||
|
- values.status["release_values"].master.image.registry == "docker.io"
|
||||||
|
- values.status["release_values"].master.image.repository == "bitnami/apache"
|
||||||
|
- values.status["release_values"].master.image.tag == "2.4.54-debian-11-r74"
|
||||||
|
|
||||||
|
# install chart using set_values and values_files
|
||||||
|
- name: copy content into values file
|
||||||
|
copy:
|
||||||
|
content: |
|
||||||
|
---
|
||||||
|
mode: distributed
|
||||||
|
dest: "{{ ymlfile.path }}"
|
||||||
|
|
||||||
|
- name: Install helm using set_values parameters
|
||||||
|
helm:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
chart_ref: oci://registry-1.docker.io/bitnamicharts/minio
|
||||||
|
release_name: 'test-minio-{{ item }}'
|
||||||
|
release_namespace: "{{ helm_namespace }}"
|
||||||
|
create_namespace: true
|
||||||
|
set_values:
|
||||||
|
- value: 'disableWebUI=true'
|
||||||
|
values_files:
|
||||||
|
- "{{ ymlfile.path }}"
|
||||||
|
|
||||||
|
- name: Get release info
|
||||||
|
helm_info:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
release_name: 'test-minio-{{ item }}'
|
||||||
|
release_namespace: "{{ helm_namespace }}"
|
||||||
|
register: values
|
||||||
|
|
||||||
|
- name: Assert that release was created with user-defined variables
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- values.status["release_values"].mode == "distributed"
|
||||||
|
- values.status["release_values"].disableWebUI is true
|
||||||
4
tests/integration/targets/helm_v3_15_4/aliases
Normal file
4
tests/integration/targets/helm_v3_15_4/aliases
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
helm
|
||||||
|
helm_template
|
||||||
|
helm_info
|
||||||
|
helm_repository
|
||||||
2
tests/integration/targets/helm_v3_15_4/inventory.ini
Normal file
2
tests/integration/targets/helm_v3_15_4/inventory.ini
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[all]
|
||||||
|
v3.15.4
|
||||||
11
tests/integration/targets/helm_v3_15_4/play.yaml
Normal file
11
tests/integration/targets/helm_v3_15_4/play.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
- name: Run tests for Helm v4.0.0
|
||||||
|
hosts: all
|
||||||
|
connection: local
|
||||||
|
gather_facts: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
ansible_python_interpreter: "{{ ansible_playbook_python }}"
|
||||||
|
helm_version: "{{ inventory_hostname }}"
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: helm
|
||||||
4
tests/integration/targets/helm_v3_15_4/runme.sh
Executable file
4
tests/integration/targets/helm_v3_15_4/runme.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eux
|
||||||
|
export ANSIBLE_ROLES_PATH=../
|
||||||
|
ansible-playbook play.yaml -i inventory.ini "$@"
|
||||||
4
tests/integration/targets/helm_v3_16_0/aliases
Normal file
4
tests/integration/targets/helm_v3_16_0/aliases
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
helm
|
||||||
|
helm_template
|
||||||
|
helm_info
|
||||||
|
helm_repository
|
||||||
2
tests/integration/targets/helm_v3_16_0/inventory.ini
Normal file
2
tests/integration/targets/helm_v3_16_0/inventory.ini
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[all]
|
||||||
|
v3.16.0
|
||||||
11
tests/integration/targets/helm_v3_16_0/play.yaml
Normal file
11
tests/integration/targets/helm_v3_16_0/play.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
- name: Run tests for Helm v4.0.0
|
||||||
|
hosts: all
|
||||||
|
connection: local
|
||||||
|
gather_facts: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
ansible_python_interpreter: "{{ ansible_playbook_python }}"
|
||||||
|
helm_version: "{{ inventory_hostname }}"
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: helm
|
||||||
4
tests/integration/targets/helm_v3_16_0/runme.sh
Executable file
4
tests/integration/targets/helm_v3_16_0/runme.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eux
|
||||||
|
export ANSIBLE_ROLES_PATH=../
|
||||||
|
ansible-playbook play.yaml -i inventory.ini "$@"
|
||||||
4
tests/integration/targets/helm_v3_17_0/aliases
Normal file
4
tests/integration/targets/helm_v3_17_0/aliases
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
helm
|
||||||
|
helm_template
|
||||||
|
helm_info
|
||||||
|
helm_repository
|
||||||
2
tests/integration/targets/helm_v3_17_0/inventory.ini
Normal file
2
tests/integration/targets/helm_v3_17_0/inventory.ini
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[all]
|
||||||
|
v3.17.0
|
||||||
11
tests/integration/targets/helm_v3_17_0/play.yaml
Normal file
11
tests/integration/targets/helm_v3_17_0/play.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
- name: Run tests for Helm v4.0.0
|
||||||
|
hosts: all
|
||||||
|
connection: local
|
||||||
|
gather_facts: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
ansible_python_interpreter: "{{ ansible_playbook_python }}"
|
||||||
|
helm_version: "{{ inventory_hostname }}"
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: helm
|
||||||
4
tests/integration/targets/helm_v3_17_0/runme.sh
Executable file
4
tests/integration/targets/helm_v3_17_0/runme.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eux
|
||||||
|
export ANSIBLE_ROLES_PATH=../
|
||||||
|
ansible-playbook play.yaml -i inventory.ini "$@"
|
||||||
4
tests/integration/targets/helm_v4_0_0/aliases
Normal file
4
tests/integration/targets/helm_v4_0_0/aliases
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
helm
|
||||||
|
helm_template
|
||||||
|
helm_info
|
||||||
|
helm_repository
|
||||||
2
tests/integration/targets/helm_v4_0_0/inventory.ini
Normal file
2
tests/integration/targets/helm_v4_0_0/inventory.ini
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[all]
|
||||||
|
v4.0.0
|
||||||
11
tests/integration/targets/helm_v4_0_0/play.yaml
Normal file
11
tests/integration/targets/helm_v4_0_0/play.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
- name: Run tests for Helm v4.0.0
|
||||||
|
hosts: all
|
||||||
|
connection: local
|
||||||
|
gather_facts: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
ansible_python_interpreter: "{{ ansible_playbook_python }}"
|
||||||
|
helm_version: "{{ inventory_hostname }}"
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: helm
|
||||||
4
tests/integration/targets/helm_v4_0_0/runme.sh
Executable file
4
tests/integration/targets/helm_v4_0_0/runme.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eux
|
||||||
|
export ANSIBLE_ROLES_PATH=../
|
||||||
|
ansible-playbook play.yaml -i inventory.ini "$@"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
---
|
---
|
||||||
helm_version: v3.16.4
|
helm_version: v3.16.4
|
||||||
helm_install_path: /tmp/helm
|
helm_install_path: /tmp/helm
|
||||||
helm_default_archive_name: "helm-{{ helm_version }}-{{ ansible_system | lower }}-amd64.tar.gz"
|
helm_default_archive_name: "https://get.helm.sh/helm-{{ helm_version }}-{{ ansible_system | lower }}-{{ ansible_architecture | lower }}.tar.gz"
|
||||||
|
|||||||
@@ -4,12 +4,27 @@
|
|||||||
path: "{{ helm_install_path }}"
|
path: "{{ helm_install_path }}"
|
||||||
state: directory
|
state: directory
|
||||||
|
|
||||||
- name: Unarchive Helm binary
|
- ansible.builtin.set_fact:
|
||||||
unarchive:
|
os_path: "{{ lookup('env', 'PATH') }}"
|
||||||
src: "https://get.helm.sh/{{ helm_archive_name | default(helm_default_archive_name) }}"
|
|
||||||
dest: "{{ helm_install_path }}"
|
- name: Download the Helm install script
|
||||||
remote_src: yes
|
ansible.builtin.get_url:
|
||||||
retries: 10
|
url: "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-{{ major_version }}"
|
||||||
delay: 5
|
dest: /tmp/get_helm.sh
|
||||||
register: result
|
mode: '0700'
|
||||||
until: result is not failed
|
vars:
|
||||||
|
major_version: "{{ helm_version | split('.') | first | replace('v', '') }}"
|
||||||
|
|
||||||
|
- name: Run the install script (helm version = {{ helm_version }})
|
||||||
|
ansible.builtin.command: /tmp/get_helm.sh
|
||||||
|
environment:
|
||||||
|
DESIRED_VERSION: "{{ helm_version }}"
|
||||||
|
HELM_INSTALL_DIR: "{{ helm_install_path }}"
|
||||||
|
PATH: "{{ os_path }}:{{ helm_install_path }}"
|
||||||
|
VERIFY_CHECKSUM: "false"
|
||||||
|
register: helm_install_result
|
||||||
|
changed_when: "'is already at the latest version' not in helm_install_result.stdout"
|
||||||
|
|
||||||
|
- name: Save Helm binary path for later use
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
helm_binary: "{{ helm_install_path }}/helm"
|
||||||
|
|||||||
@@ -30,5 +30,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
|
|||||||
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
||||||
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
||||||
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
||||||
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
||||||
|
|||||||
@@ -30,5 +30,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
|
|||||||
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
||||||
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
||||||
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
||||||
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
||||||
|
|||||||
@@ -27,5 +27,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
|
|||||||
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
||||||
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
||||||
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
||||||
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
||||||
|
|||||||
@@ -27,5 +27,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
|
|||||||
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
||||||
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
||||||
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
||||||
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
||||||
|
|||||||
@@ -30,5 +30,4 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
|
|||||||
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
||||||
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
||||||
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
||||||
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ plugins/modules/k8s_scale.py validate-modules:return-syntax-error
|
|||||||
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
||||||
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
||||||
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-reuse-values/templates/configmap.yaml yamllint!skip
|
||||||
tests/integration/targets/helm_registry_auth/tasks/main.yaml yamllint!skip
|
|
||||||
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
tests/integration/targets/helm_diff/files/test-chart-deployment-time/templates/configmap.yaml yamllint!skip
|
||||||
plugins/modules/helm.py validate-modules:bad-return-value-key
|
plugins/modules/helm.py validate-modules:bad-return-value-key
|
||||||
plugins/modules/helm_info.py validate-modules:bad-return-value-key
|
plugins/modules/helm_info.py validate-modules:bad-return-value-key
|
||||||
|
|||||||
@@ -455,9 +455,9 @@ def test_module_get_helm_set_values_args(set_values, expected):
|
|||||||
("3.17.0", False),
|
("3.17.0", False),
|
||||||
("2.9.0", True),
|
("2.9.0", True),
|
||||||
("2.17.0", True),
|
("2.17.0", True),
|
||||||
("4.0.0", True),
|
("4.0.0", False),
|
||||||
("4.1.0", True),
|
("4.1.0", False),
|
||||||
("5.0.0", True),
|
("5.0.0", False),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_module_validate_helm_version(_ansible_helm_module, helm_version, should_fail):
|
def test_module_validate_helm_version(_ansible_helm_module, helm_version, should_fail):
|
||||||
@@ -469,8 +469,10 @@ def test_module_validate_helm_version(_ansible_helm_module, helm_version, should
|
|||||||
_ansible_helm_module.validate_helm_version()
|
_ansible_helm_module.validate_helm_version()
|
||||||
_ansible_helm_module.fail_json.assert_called_once()
|
_ansible_helm_module.fail_json.assert_called_once()
|
||||||
call_args = _ansible_helm_module.fail_json.call_args
|
call_args = _ansible_helm_module.fail_json.call_args
|
||||||
assert "Helm version must be >=3.0.0,<4.0.0" in call_args[1]["msg"]
|
assert (
|
||||||
assert helm_version in call_args[1]["msg"]
|
f"Helm version must be >= 3.0.0, current version is {helm_version}"
|
||||||
|
== call_args[1]["msg"]
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
_ansible_helm_module.validate_helm_version()
|
_ansible_helm_module.validate_helm_version()
|
||||||
_ansible_helm_module.fail_json.assert_not_called()
|
_ansible_helm_module.fail_json.assert_not_called()
|
||||||
55
tests/unit/module_utils/helm/test_helm_plugin_list.py
Normal file
55
tests/unit/module_utils/helm/test_helm_plugin_list.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright: (c) 2026, Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.helm import (
|
||||||
|
parse_helm_plugin_list,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_helm_plugin_list_empty():
|
||||||
|
assert parse_helm_plugin_list() == []
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"output,expected",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"""
|
||||||
|
NAME VERSION TYPE APIVERSION PROVENANCE SOURCE
|
||||||
|
diff 3.4.1 cli/v1 legacy unknown unknown
|
||||||
|
|
||||||
|
""",
|
||||||
|
[
|
||||||
|
dict(
|
||||||
|
name="diff",
|
||||||
|
version="3.4.1",
|
||||||
|
type="cli/v1",
|
||||||
|
apiversion="legacy",
|
||||||
|
provenance="unknown",
|
||||||
|
source="unknown",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"""
|
||||||
|
NAME VERSION DESCRIPTION
|
||||||
|
diff 3.4.1 Preview helm upgrade changes as a diff
|
||||||
|
""",
|
||||||
|
[
|
||||||
|
dict(
|
||||||
|
name="diff",
|
||||||
|
version="3.4.1",
|
||||||
|
description="Preview helm upgrade changes as a diff",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_parse_helm_plugin_list_values(output, expected):
|
||||||
|
assert parse_helm_plugin_list(output.split("\n")) == expected
|
||||||
Reference in New Issue
Block a user