Skip to content

Commit bda356e

Browse files
Use oc adm release extract --tools instead of unreliable file-cache for OCP binaries
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4caf935 commit bda356e

3 files changed

Lines changed: 70 additions & 30 deletions

File tree

collection/tools/roles/tools_get_openshift_release/defaults/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
# defaults file for tools_get_openshift_release
33
openshift_releasestream_url: "https://openshift-release.apps.ci.l2s4.p1.openshiftapps.com/api/v1/releasestream"
44
release_name: "{{ openshift_release_build_name | default('') }}"
5-
openshift_download_url: "{{ 'https://openshift-release-artifacts.apps.ci.l2s4.p1.openshiftapps.com' + '/' + release_name }}"
65
openshift_mirror_url: "https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp"
76
ocp_build_info_file: "{{ controller_home_dir }}/latest_build.json"
Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,61 @@
11
---
2+
# Extract OCP installer and/or client binaries directly from the release image
3+
# using `oc adm release extract --tools` instead of the release-controller's
4+
# file-cache (openshift-release-artifacts), which has no SLA and can get stuck
5+
# indefinitely during tool extraction.
26
- name: Get the OCP installer and/or client binaries
37
vars:
4-
installer_url: "{{ openshift_download_url }}/openshift-install-linux-{{ release_name }}.tar.gz"
5-
client_url: "{{ openshift_download_url }}/openshift-client-linux-{{ release_name }}.tar.gz"
8+
installer_tarball: "openshift-install-linux-{{ release_name }}.tar.gz"
9+
client_tarball: "openshift-client-linux-{{ release_name }}.tar.gz"
10+
pull_secret_file: "{{ home_dir }}/pull-secret.json"
611
block:
712
- name: Fail if release_name var is not defined
813
ansible.builtin.fail:
914
msg: "'release_name' variable must be defined and cannot be empty"
1015
when: release_name == ''
1116

12-
- name: Wait for content to come up on {{ openshift_download_url }}
13-
ansible.builtin.uri:
14-
url: "{{ openshift_download_url }}"
15-
method: GET
16-
return_content: yes
17-
status_code: 200
18-
body_format: json
19-
register: result
20-
until: result.content.find("openshift-install-linux") != -1
21-
retries: 20
22-
delay: 60
17+
- name: Fail if openshift_release_pull_spec is not defined
18+
ansible.builtin.fail:
19+
msg: "'openshift_release_pull_spec' must be set by get_openshift_release_build_name.yml"
20+
when: openshift_release_pull_spec is not defined or openshift_release_pull_spec == ''
21+
22+
- name: Extract pull secret from host cluster
23+
ansible.builtin.shell: >-
24+
set -o pipefail &&
25+
oc get secret pull-secret -n openshift-config
26+
--kubeconfig={{ rhoso_kubeconfig }}
27+
-o jsonpath='{.data.\.dockerconfigjson}'
28+
| base64 -d > {{ pull_secret_file }}
29+
changed_when: true
30+
no_log: true
2331

2432
- name: Create the installer directory
2533
ansible.builtin.file:
2634
path: "{{ home_dir }}/{{ release_name }}"
2735
state: directory
2836
mode: u=rwx,g=rw,o=r
2937

38+
- name: Extract OCP tools from release image {{ openshift_release_pull_spec }}
39+
ansible.builtin.command:
40+
cmd: >-
41+
oc adm release extract
42+
--tools
43+
--registry-config={{ pull_secret_file }}
44+
--to={{ home_dir }}/{{ release_name }}
45+
{{ openshift_release_pull_spec }}
46+
register: extract_result
47+
until: extract_result is not failed
48+
retries: 3
49+
delay: 30
50+
3051
- name: Get the installer binary and create a symlink
3152
when: "'installer' in binaries"
3253
block:
33-
- name: Download and unarchive the installer from {{ installer_url }}
54+
- name: Unarchive the installer from {{ installer_tarball }}
3455
ansible.builtin.unarchive:
35-
src: "{{ installer_url }}"
56+
src: "{{ home_dir }}/{{ release_name }}/{{ installer_tarball }}"
3657
dest: "{{ home_dir }}/{{ release_name }}"
3758
remote_src: yes
38-
register: result
39-
until: result is not failed
40-
retries: 3
41-
delay: 10
4259

4360
- name: Create a symlink to the openshift-install binary from /usr/local/bin
4461
ansible.builtin.file:
@@ -47,18 +64,14 @@
4764
state: link
4865
become: true
4966

50-
- name: Get the installer binary and create symlinks
67+
- name: Get the client binary and create symlinks
5168
when: "'client' in binaries"
5269
block:
53-
- name: Download and unarchive the client from {{ client_url }}
70+
- name: Unarchive the client from {{ client_tarball }}
5471
ansible.builtin.unarchive:
55-
src: "{{ client_url }}"
72+
src: "{{ home_dir }}/{{ release_name }}/{{ client_tarball }}"
5673
dest: "{{ home_dir }}/{{ release_name }}"
5774
remote_src: yes
58-
register: result
59-
until: result is not failed
60-
retries: 3
61-
delay: 10
6275

6376
- name: Create a symlink to the oc binary from /usr/local/bin
6477
ansible.builtin.file:
@@ -73,3 +86,9 @@
7386
dest: /usr/bin/kubectl
7487
state: link
7588
become: true
89+
90+
always:
91+
- name: Remove pull secret file
92+
ansible.builtin.file:
93+
path: "{{ pull_secret_file }}"
94+
state: absent

collection/tools/roles/tools_get_openshift_release/tasks/get_openshift_release_build_name.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,25 @@
3939
ansible.builtin.set_fact:
4040
openshift_release_build_name: "{{ latest_build_info.name }}"
4141

42-
- name: Set openshift_release_build_name when a specific build is given
43-
ansible.builtin.set_fact:
44-
openshift_release_build_name: "{{ build_name }}"
42+
- name: Set openshift_release_pull_spec from release stream API response
43+
ansible.builtin.set_fact:
44+
openshift_release_pull_spec: "{{ latest_build_info.pullSpec }}"
45+
46+
- name: Set build name and pull spec when a specific build is given
4547
when:
4648
- release is not match("4-stable")
4749
- build_name not in ['','candidate','fast','stable','eus']
50+
block:
51+
- name: Set openshift_release_build_name for specific build
52+
ansible.builtin.set_fact:
53+
openshift_release_build_name: "{{ build_name }}"
54+
55+
- name: Construct openshift_release_pull_spec for specific build
56+
ansible.builtin.set_fact:
57+
openshift_release_pull_spec: >-
58+
{{ 'registry.ci.openshift.org/ocp/release:' + build_name
59+
if build_name is search('nightly')
60+
else 'quay.io/openshift-release-dev/ocp-release:' + build_name + '-x86_64' }}
4861
4962
- name: Discover the release build name for the z-stream promoted to upgrade channel on {{ release }}
5063
# Ref: https://docs.openshift.com/container-platform/4.9/updating/understanding-upgrade-channels-release.html
@@ -68,3 +81,12 @@
6881
- name: Set openshift_release_build_name when openshift.build is set to a channel
6982
ansible.builtin.set_fact:
7083
openshift_release_build_name: "{{ result.stdout }}"
84+
85+
- name: Parse openshift_release_pull_spec from Pull From field in release.txt
86+
ansible.builtin.shell: set -o pipefail && grep '^Pull From:' {{ home_dir }}/release.txt | awk '{print $3}'
87+
changed_when: false
88+
register: pull_from_result
89+
90+
- name: Set openshift_release_pull_spec from channel release.txt
91+
ansible.builtin.set_fact:
92+
openshift_release_pull_spec: "{{ pull_from_result.stdout }}"

0 commit comments

Comments
 (0)