mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-28 10:24:45 +00:00
[helm] Add the force_update arg (#509)
[helm] Add the force_update arg Depends-On: ansible/ansible-zuul-jobs#1648 Depends-On: #522 SUMMARY Sometimes a Helm repo needs to be updated with a new URL. The helm repo add command allows for this with the --force-update flag: --force-update replace (overwrite) the repo if it already exists ISSUE TYPE Feature Pull Request - Closes #491 COMPONENT NAME kubernetes.core.helm_repository ADDITIONAL INFORMATION Reviewed-by: Mor Cohen <morcohen1201@gmail.com> Reviewed-by: Mike Graves <mgraves@redhat.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- helm_repository - Ability to replace (overwrite) the repo if it already exists by forcing (https://github.com/ansible-collections/kubernetes.core/issues/491).
|
||||||
@@ -112,6 +112,13 @@ options:
|
|||||||
type: raw
|
type: raw
|
||||||
aliases: [ kubeconfig_path ]
|
aliases: [ kubeconfig_path ]
|
||||||
version_added: "2.4.0"
|
version_added: "2.4.0"
|
||||||
|
force_update:
|
||||||
|
description:
|
||||||
|
- Whether or not to replace (overwrite) the repo if it already exists.
|
||||||
|
type: bool
|
||||||
|
aliases: [ force ]
|
||||||
|
default: False
|
||||||
|
version_added: "2.4.0"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = r"""
|
EXAMPLES = r"""
|
||||||
@@ -218,6 +225,7 @@ def install_repository(
|
|||||||
repository_username,
|
repository_username,
|
||||||
repository_password,
|
repository_password,
|
||||||
pass_credentials,
|
pass_credentials,
|
||||||
|
force_update,
|
||||||
):
|
):
|
||||||
install_command = command + " repo add " + repository_name + " " + repository_url
|
install_command = command + " repo add " + repository_name + " " + repository_url
|
||||||
|
|
||||||
@@ -228,6 +236,9 @@ def install_repository(
|
|||||||
if pass_credentials:
|
if pass_credentials:
|
||||||
install_command += " --pass-credentials"
|
install_command += " --pass-credentials"
|
||||||
|
|
||||||
|
if force_update:
|
||||||
|
install_command += " --force-update"
|
||||||
|
|
||||||
return install_command
|
return install_command
|
||||||
|
|
||||||
|
|
||||||
@@ -250,6 +261,7 @@ def argument_spec():
|
|||||||
default="present", choices=["present", "absent"], aliases=["state"]
|
default="present", choices=["present", "absent"], aliases=["state"]
|
||||||
),
|
),
|
||||||
pass_credentials=dict(type="bool", default=False, no_log=True),
|
pass_credentials=dict(type="bool", default=False, no_log=True),
|
||||||
|
force_update=dict(type="bool", default=False, aliases=["force"]),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return arg_spec
|
return arg_spec
|
||||||
@@ -277,6 +289,7 @@ def main():
|
|||||||
repo_password = module.params.get("repo_password")
|
repo_password = module.params.get("repo_password")
|
||||||
repo_state = module.params.get("repo_state")
|
repo_state = module.params.get("repo_state")
|
||||||
pass_credentials = module.params.get("pass_credentials")
|
pass_credentials = module.params.get("pass_credentials")
|
||||||
|
force_update = module.params.get("force_update")
|
||||||
|
|
||||||
helm_cmd = get_helm_binary(module)
|
helm_cmd = get_helm_binary(module)
|
||||||
|
|
||||||
@@ -286,7 +299,7 @@ def main():
|
|||||||
helm_cmd = delete_repository(helm_cmd, repo_name)
|
helm_cmd = delete_repository(helm_cmd, repo_name)
|
||||||
changed = True
|
changed = True
|
||||||
elif repo_state == "present":
|
elif repo_state == "present":
|
||||||
if repository_status is None:
|
if repository_status is None or force_update:
|
||||||
helm_cmd = install_repository(
|
helm_cmd = install_repository(
|
||||||
helm_cmd,
|
helm_cmd,
|
||||||
repo_name,
|
repo_name,
|
||||||
@@ -294,6 +307,7 @@ def main():
|
|||||||
repo_username,
|
repo_username,
|
||||||
repo_password,
|
repo_password,
|
||||||
pass_credentials,
|
pass_credentials,
|
||||||
|
force_update,
|
||||||
)
|
)
|
||||||
changed = True
|
changed = True
|
||||||
elif repository_status["url"] != repo_url:
|
elif repository_status["url"] != repo_url:
|
||||||
|
|||||||
@@ -42,6 +42,19 @@
|
|||||||
that:
|
that:
|
||||||
- repository_errors is failed
|
- 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
|
- name: Remove test_helm_repo chart repository
|
||||||
helm_repository:
|
helm_repository:
|
||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user