From 0058b0ee7ddc319d03f59fc49f52edd8e88593bb Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 25 Apr 2023 16:16:54 -0700 Subject: [PATCH] Use consistent registry type var name across roles This updates the remote-registry-tag role to use container_registry_credentials[registry].type to specify quay or docker API types. This aligns this roles' behavior with ensure-quay-repo's behavior. Change-Id: I098dfbfd7d7a744ad6a66d9d8abc109b0fb6254a --- roles/remove-registry-tag/README.rst | 15 +++++-------- roles/remove-registry-tag/tasks/main.yaml | 26 ++++++++++++++++++----- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/roles/remove-registry-tag/README.rst b/roles/remove-registry-tag/README.rst index c862d86c2..8c0bcc571 100644 --- a/roles/remove-registry-tag/README.rst +++ b/roles/remove-registry-tag/README.rst @@ -39,14 +39,19 @@ communicate to using arguments below. ``__ * **docker.io** : Username and password + You can specify the registry type explicitly via the ``type`` + attribute, but it will be inferred for quay.io and docker.io. + Example: .. code-block:: yaml container_registry_credentials: quay.io: + type: 'quay' api_token: 'abcd1234' docker.io: + type: 'docker' username: 'username' password: 'password' @@ -74,16 +79,6 @@ communicate to using arguments below. :zuul:rolevar:`remove-registry-tag.remove_registry_tag_regex` last-modified timestamp must exceed to be removed. -.. zuul:rolevar:: remove_registry_tag_api_type - :type: string - - Optional. By default the role will guess the API type from the - repository name. However, if you need to override this choice - specify one of: - - * quay - * docker - .. zuul:rolevar:: remove_registry_tag_api_url :type: string diff --git a/roles/remove-registry-tag/tasks/main.yaml b/roles/remove-registry-tag/tasks/main.yaml index c76dec095..bc3dc93aa 100644 --- a/roles/remove-registry-tag/tasks/main.yaml +++ b/roles/remove-registry-tag/tasks/main.yaml @@ -13,15 +13,31 @@ _registry: "{{ (remove_registry_tag_repository | split('/', 1)).0 }}" _repopath: "{{ (remove_registry_tag_repository | split('/', 1)).1 }}" +- name: Verify registry names + when: | + container_registry_credentials is defined + and _registry not in container_registry_credentials + fail: + msg: "{{ _registry }} credentials not found" + - name: Autoprobe for quay.io - when: remove_registry_tag_api_type is not defined and "quay.io" in _registry + when: + - container_registry_credentials[_registry].type is not defined + - '"quay.io" in _registry' set_fact: - remove_registry_tag_api_type: "quay" + registry_type: "quay" - name: Autoprobe for docker - when: remove_registry_tag_api_type is not defined and "docker.io" in _registry + when: + - container_registry_credentials[_registry].type is not defined + - '"docker.io" in _registry' set_fact: - remove_registry_tag_api_type: "docker" + registry_type: "docker" + +- name: Use explicit registry type if set + when: container_registry_credentials[_registry].type is defined + set_fact: + registry_type: container_registry_credentials[_registry].type - name: Remove tags - include_tasks: '{{ remove_registry_tag_api_type }}.yaml' + include_tasks: '{{ registry_type }}.yaml'