mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-11-23 15:40:20 +00:00
:fix(helm_repository): normalize both sides of the repo URL comparison (#1236)
helm stores repository URLs verbatim, so a repository registered with a trailing slash keeps it in repositories.yaml. Only the URL coming from the task was normalized, so a repository that already matched was reported as a name conflict. Fixes #1235
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- helm_repository - normalize both sides of the repository URL comparison, so that a repository already registered with a trailing slash is recognized as matching instead of failing with ``Repository already have a repository named <name>`` (https://github.com/ansible-collections/kubernetes.core/pull/1236).
|
||||||
@@ -331,7 +331,7 @@ def main():
|
|||||||
insecure_skip_tls_verify,
|
insecure_skip_tls_verify,
|
||||||
)
|
)
|
||||||
changed = True
|
changed = True
|
||||||
elif repository_status["url"] != repo_url:
|
elif repository_status["url"].rstrip("/") != repo_url:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg="Repository already have a repository named {0}".format(repo_name)
|
msg="Repository already have a repository named {0}".format(repo_name)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -103,3 +103,81 @@
|
|||||||
binary_path: "{{ helm_binary }}"
|
binary_path: "{{ helm_binary }}"
|
||||||
name: test_helm_repo
|
name: test_helm_repo
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
# https://github.com/ansible-collections/kubernetes.core/issues/1235
|
||||||
|
- name: Ensure the trailing slash test repositories don't exist
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop:
|
||||||
|
- test_helm_repo_slash
|
||||||
|
- test_helm_repo_noslash
|
||||||
|
|
||||||
|
- name: Register test_helm_repo_slash directly through helm, keeping the trailing slash
|
||||||
|
ansible.builtin.command: "{{ helm_binary }} repo add test_helm_repo_slash {{ chart_test_repo }}/"
|
||||||
|
changed_when: true
|
||||||
|
|
||||||
|
- name: Add test_helm_repo_noslash chart repository without a trailing slash
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo_noslash
|
||||||
|
repo_url: "{{ chart_test_repo }}"
|
||||||
|
|
||||||
|
- name: Check idempotency when the stored and the requested URL both have a trailing slash
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo_slash
|
||||||
|
repo_url: "{{ chart_test_repo }}/"
|
||||||
|
register: repository
|
||||||
|
|
||||||
|
- name: Assert idempotency when the stored and the requested URL both have a trailing slash
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository is not changed
|
||||||
|
|
||||||
|
- name: Check idempotency when only the stored URL has a trailing slash
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo_slash
|
||||||
|
repo_url: "{{ chart_test_repo }}"
|
||||||
|
register: repository
|
||||||
|
|
||||||
|
- name: Assert idempotency when only the stored URL has a trailing slash
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository is not changed
|
||||||
|
|
||||||
|
- name: Check idempotency when only the requested URL has a trailing slash
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo_noslash
|
||||||
|
repo_url: "{{ chart_test_repo }}/"
|
||||||
|
register: repository
|
||||||
|
|
||||||
|
- name: Assert idempotency when only the requested URL has a trailing slash
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository is not changed
|
||||||
|
|
||||||
|
- name: Failed to add repository with the same name and a different URL, trailing slash aside
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: test_helm_repo_slash
|
||||||
|
repo_url: "https://other-charts.url/"
|
||||||
|
register: repository_errors
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert that adding repository with the same name and a different URL failed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- repository_errors is failed
|
||||||
|
|
||||||
|
- name: Clean the trailing slash test repositories
|
||||||
|
helm_repository:
|
||||||
|
binary_path: "{{ helm_binary }}"
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop:
|
||||||
|
- test_helm_repo_slash
|
||||||
|
- test_helm_repo_noslash
|
||||||
|
|||||||
Reference in New Issue
Block a user