Skip to content

Commit

Permalink
Merge pull request #332 from redhatci/idms_on_mor
Browse files Browse the repository at this point in the history
Produce IDMS for 4.14+
  • Loading branch information
tonyskapunk authored Jun 17, 2024
2 parents 6a22ac5 + dddee70 commit f45a601
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 57 deletions.
5 changes: 4 additions & 1 deletion ansible-collection-redhatci-ocp.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%global forgeurl https://github.com/%{org}/%{repo}

Name: %{repo}
Version: 0.10.EPOCH
Version: 0.11.EPOCH
Release: VERS%{?dist}
Summary: Red Hat OCP CI Collection for Ansible

Expand Down Expand Up @@ -51,6 +51,9 @@ find -type f ! -executable -name '*.py' -print -exec sed -i -e '1{\@^#!.*@d}' '{


%changelog
* Fri Jun 14 2024 Tony Garcia <[email protected]> - 0.11.EPOCH-VERS
- Version bump due to mirror_ocp_release role

* Thu May 9 2024 Tony Garcia <[email protected]> - 0.10.EPOCH-VERS
- Version bump in the collection due to baremetal installer 4.16+

Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: ocp
# Always leave patch version as .0
# Patch version is replaced from commit date in UNIX epoch format
# example: 0.3.2147483647
version: 0.10.0
version: 0.11.0

# The path to the Markdown (.md) readme file.
readme: README.md
Expand Down
9 changes: 6 additions & 3 deletions roles/mirror_ocp_release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ If enabled, the role requires an container registry to mirror the OCP container
| mor_force | false | No | If passed as true, the role will re-download all the OCP release resources |
| mor_install_type | "ipi" | No | Mirrors image required for the install type (ipi, acm, assisted, sno, upi, vsphere) |
| mor_installer | \<See Description\> | No | Depending on the OCP 4.16+:openshift-install, 4.16-:openshift-baremetal-install |
| mor_is_type | \<See Description\> | No | Image Source file type. Default: `icsp` for 4.13 and below, `idms` for 4.14 and above |
| mor_mirror_container_images | true | No | Mirror all container images from upstream container registries to the provided registry |
| mor_mirror_disk_images | true | No | Download all disk images depending on which install type |
| mor_oc | undefined | Yes | Path to the oc binary (stable is recommended). |
Expand All @@ -37,7 +38,7 @@ See below for some examples of how to use the mirror_ocp_release role.
ansible.builtin.include_role:
name: redhatci.ocp.mirror_ocp_release
vars:
mor_version: "4.13.0-ec.1"
mor_version: "4.15.0-ec.1"
mor_pull_url: "quay.io/openshift-release-dev/ocp-release@sha256:bb0d79219a876d87e994149c835033f8dcbf3433505a44a9e7e871b1b816b760"
mor_cache_dir: "/opt/cache"
mor_webserver_url: "https://<mywebserver>"
Expand All @@ -46,6 +47,7 @@ See below for some examples of how to use the mirror_ocp_release role.
mor_auths_file: "/var/<pull_secret>"
mor_force: true
mor_install_type: "ipi"
mor_is_type: "idms"
mor_mirror_disk_images: true
mor_mirror_container_images: true
mor_write_custom_config: true
Expand All @@ -57,10 +59,11 @@ See below for some examples of how to use the mirror_ocp_release role.
ansible.builtin.include_role:
name: redhatci.ocp.mirror_ocp_release
vars:
mor_version: "4.12.0-0.nightly-2023-01-10-062211"
mor_version: "4.14.0-0.nightly-2024-01-10-123456"
mor_pull_url: "registry.ci.openshift.org/ocp/release@sha256:86b4185571e403a9bfcf82c4b363c4aaa41751976e60c1c10d1961e4b67ed9ab"
mor_auths_file: "{{ dci_pullsecret_file }}"
mor_is_type: "icsp"
mor_webserver_url: "{{ webserver_url }}"
mor_registry_url: "{{ dci_local_registry }}"
mor_registry_path: "ocp-4.10/4.10.0-0.nightly-2023-02-16-193851"
mor_registry_path: "ocp-4.14/4.14.0-0.nightly-2024-01-10-123456"
```
3 changes: 3 additions & 0 deletions roles/mirror_ocp_release/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ mor_install_type: "ipi"
mor_installer: >-
{{ mor_version is version('4.16', '>=') |
ternary('openshift-install', 'openshift-baremetal-install') }}
mor_is_type: >-
{{ mor_version is version('4.14', '>=') |
ternary('idms', 'icsp') }}
mor_owner: "{{ ansible_user_uid }}"
mor_group: "{{ ansible_user_gid }}"
mor_force: false
Expand Down
1 change: 1 addition & 0 deletions roles/mirror_ocp_release/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- mor_version | string
- mor_pull_url | string
- mor_oc | string
- mor_is_type | lower in mor_is_types

- name: "Check if authentication file exists"
ansible.builtin.stat:
Expand Down
103 changes: 51 additions & 52 deletions roles/mirror_ocp_release/tasks/registry.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
---
- name: "OCP release mirror"
block:
- name: "Check if the release image is pullable from the local registry"
ansible.builtin.command: >
skopeo inspect
--no-tags
--authfile {{ mor_auths_file }}
docker://{{ mor_registry_url }}/{{ mor_registry_path }}:{{ mor_version }}
- name: Check if the release image is pullable from the local registry
ansible.builtin.command: >
skopeo inspect
--no-tags
--authfile {{ mor_auths_file }}
docker://{{ mor_registry_url }}/{{ mor_registry_path }}:{{ mor_version }}
register: _mor_release_image
failed_when: false
when: not mor_force | bool

- name: "Check for cached Image Source file"
ansible.builtin.stat:
path: "{{ mor_cache_dir }}/{{ mor_version }}/imagesource.yaml"
get_checksum: false
register: target
- name: Mirror release images to local registry
ansible.builtin.command: >-
{{ mor_cache_dir }}/{{ mor_version }}/oc adm release mirror
--registry-config={{ mor_auths_file }}
--from={{ ocp_release_data['container_image'] | quote }}
--to-release-image={{ mor_registry_url }}/{{ mor_registry_path }}:{{ mor_version }}
--to={{ mor_registry_url }}/{{ mor_registry_path }}
retries: 3
delay: 10
register: _mor_result
until: _mor_result.rc == 0
changed_when: _mor_result.rc == 0
when: _mor_release_image.rc != 0 or mor_force | bool

- name: "Force mirroring if image source does not exist"
ansible.builtin.fail:
msg: "Cached image contents does not exits, forcing mirroring"
when: not target.stat.exists
- name: Generate Image Source manifest
ansible.builtin.command: >-
{{ mor_cache_dir }}/{{ mor_version }}/oc adm release mirror
--registry-config={{ mor_auths_file }}
--from={{ ocp_release_data['container_image'] | quote }}
--to-release-image={{ mor_registry_url }}/{{ mor_registry_path }}:{{ mor_version }}
--to={{ mor_registry_url }}/{{ mor_registry_path }}
--print-mirror-instructions={{ mor_is_type | lower }}
retries: 3
delay: 10
register: _mor_result
until: _mor_result.rc == 0
changed_when: _mor_result.rc == 0

- name: "Force mirroring is enabled"
ansible.builtin.fail:
msg: "Forcing the release mirroring"
when:
- mor_force | bool
- name: Grab generated Image Source manifest
ansible.builtin.shell: >
set -o pipefail;
echo -e "{{ _mor_result.stdout }}" |
sed -n '/apiVersion/,$p' |
sed -e 's/name:.*/name: release-{{ mor_version }}/'
register: is_release

rescue:
- name: "Mirror release images to local registry"
ansible.builtin.command: >
{{ mor_cache_dir }}/{{ mor_version }}/oc adm release mirror
--registry-config={{ mor_auths_file }}
--from={{ ocp_release_data['container_image'] | quote }}
--to-release-image={{ mor_registry_url }}/{{ mor_registry_path }}:{{ mor_version }}
--to={{ mor_registry_url }}/{{ mor_registry_path }}
retries: 3
delay: 10
register: result
until: result.rc == 0

- name: Generate Image Source manifest
ansible.builtin.shell: >
set -o pipefail;
echo -e "{{ result.stdout }}" |
sed -n '/apiVersion/,$p' |
sed -e 's/name:.*/name: release-{{ mor_version }}/'
register: is_release

- name: Write Image Source manifest
ansible.builtin.copy:
dest: "{{ mor_cache_dir }}/{{ mor_version }}/imagesource.yaml"
owner: "{{ mor_owner }}"
group: "{{ mor_group }}"
mode: "0644"
setype: httpd_sys_content_t
content: "{{ is_release.stdout }}"
become: true
- name: Write Image Source manifest
ansible.builtin.copy:
dest: "{{ mor_cache_dir }}/{{ mor_version }}/imagesource.yaml"
owner: "{{ mor_owner }}"
group: "{{ mor_group }}"
mode: "0644"
setype: httpd_sys_content_t
content: "{{ is_release.stdout }}"
become: true
...
4 changes: 4 additions & 0 deletions roles/mirror_ocp_release/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
mor_is_types:
- "idms"
- "icsp"

0 comments on commit f45a601

Please sign in to comment.