Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[helm] Add the force_update arg #509

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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).
16 changes: 15 additions & 1 deletion plugins/modules/helm_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@
type: raw
aliases: [ kubeconfig_path ]
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"""
Expand Down Expand Up @@ -218,6 +225,7 @@ def install_repository(
repository_username,
repository_password,
pass_credentials,
force_update,
):
install_command = command + " repo add " + repository_name + " " + repository_url

Expand All @@ -228,6 +236,9 @@ def install_repository(
if pass_credentials:
install_command += " --pass-credentials"

if force_update:
install_command += " --force-update"

return install_command


Expand All @@ -250,6 +261,7 @@ def argument_spec():
default="present", choices=["present", "absent"], aliases=["state"]
),
pass_credentials=dict(type="bool", default=False, no_log=True),
force_update=dict(type="bool", default=False, aliases=["force"]),
)
)
return arg_spec
Expand Down Expand Up @@ -277,6 +289,7 @@ def main():
repo_password = module.params.get("repo_password")
repo_state = module.params.get("repo_state")
pass_credentials = module.params.get("pass_credentials")
force_update = module.params.get("force_update")

helm_cmd = get_helm_binary(module)

Expand All @@ -286,14 +299,15 @@ def main():
helm_cmd = delete_repository(helm_cmd, repo_name)
changed = True
elif repo_state == "present":
if repository_status is None:
if repository_status is None or force_update:
mor120 marked this conversation as resolved.
Show resolved Hide resolved
helm_cmd = install_repository(
helm_cmd,
repo_name,
repo_url,
repo_username,
repo_password,
pass_credentials,
force_update,
)
changed = True
elif repository_status["url"] != repo_url:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/helm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
loop_control:
loop_var: helm_version
with_items:
- "v3.2.4"
- "v3.7.0"
mor120 marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions tests/integration/targets/helm/tasks/tests_repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
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 }}"
Expand Down