Skip to content

Commit c06c836

Browse files
ocp_quay
Signed-off-by: Yashansh-Sharma15 <[email protected]>
1 parent e50ffec commit c06c836

File tree

11 files changed

+381
-0
lines changed

11 files changed

+381
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This repository consists of additional ansible playbooks for the following:
5353
1. Verify IPI day2 operations
5454
1. Deploy Openshift Data Foundation operator
5555
1. Enabling Kdump
56+
1. Deploy Quay Operator
5657

5758
## Assumptions:
5859

examples/all.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,15 @@ update_channel: ""
556556
odf_catalogsource_image: "" #Example - quay.io/rhceph-dev/ocs-registry:4.16.3
557557
test_pod_image: "quay.io/powercloud/nginx-unprivileged:latest"
558558

559+
# ocp-quay required vars
560+
quay_enabled: false #set to true for quay operator installation
561+
lso_index: "" # provide LSO index image
562+
cluster_upi: true #set to true if using UPI cluster
563+
quay_registry_namespace: "" #Nmaespace for quay-registry
564+
quay_catalogsource_name: "" # CatalogSource Name
565+
quay_catalogsource_image: "" # CatalogSource Image
566+
quay_operator_channel : # Version of Quay to be installed
567+
quay_registry_hostname: "" # Hostname for Quayconfig
568+
volume_path: "/dev/disk/by-id/......" #Get the volume path using "ls /dev/disk/by-id/......"
569+
odf_index: " " #Example - quay.io/rhceph-dev/ocs-registry:4.16.3
570+
odf_channel: #Define this to set subscription channel for ODF Operator

examples/ocp_quay_vars.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ocp-quay vars
2+
3+
quay_enabled: false #set to true for quay operator installation
4+
lso_index: "" # provide LSO index image
5+
cluster_upi: true #set to true if using UPI cluster
6+
quay_registry_namespace: "" #Nmaespace for quay-registry
7+
quay_catalogsource_name: "" # CatalogSource Name
8+
quay_catalogsource_image: "" # CatalogSource Image
9+
quay_operator_channel : # Version of Quay to be installed
10+
quay_registry_hostname: "" # Hostname for Quayconfig
11+
volume_path: "/dev/disk/by-id/......" #Get the volume path using "ls /dev/disk/by-id/......"
12+
odf_index: " " #Example - quay.io/rhceph-dev/ocs-registry:4.16.3
13+
odf_channel: #Define this to set subscription channel for ODF Operator

playbooks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,6 @@
159159
- import_playbook: ocp-odf-operator.yml
160160
when: odf_enabled is defined and odf_enabled
161161

162+
- import_playbook: ocp-quay.yml
163+
when: quay_enabled is defined and quay_enabled
164+

playbooks/ocp-quay.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: Automate Quay operator in OpenShift
3+
hosts: bastion
4+
roles:
5+
- ocp-quay

playbooks/roles/ocp-quay/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
Quay Automation
3+
=========
4+
5+
This playbook will:
6+
- Install Quay operator
7+
- Install LSO operator
8+
- Install ODF operator
9+
10+
Requirements
11+
------------
12+
13+
- Access to the cluster as a user with the cluster-admin role
14+
- The cluster is in a known good state, without any errors
15+
- OCP secret with name ***podman-secret*** in the default namespace which is used for global secret update and has following keys:
16+
***username***, ***password*** and ***registry***
17+
18+
19+
Role Variables
20+
--------------
21+
| Variable | Required | Default | Comments |
22+
|--------------------------------|----------|-------------|------------------------------------------------|
23+
| quay_enabled | no | false | Set it to true to run this playbook |
24+
| quay_registry_namespace | no | "quay-registry" | Quay registry namespace |
25+
| quay_catalogsource_name | no | | Quay Catalogsource Name |
26+
| quay_catalogsource_image | no | | Quay Catalogsource Image |
27+
| lso_index | no | " " | Index image for LSO operator |
28+
| odf_index | no | " " | Index image for ODF operator |
29+
| odf_channel | no | It uses default channel | It is used to set subscription channel for ODF Operator |
30+
| cluster_upi | no | false | #set to true if using UPI cluster |
31+
| volume_path | no | false | #Get the volume path using "ls /dev/disk/by-id/" |
32+
33+
Dependencies
34+
------------
35+
36+
- Import LSO role
37+
- Import ODF role
38+
39+
Example Playbook
40+
----------------
41+
42+
```
43+
- name: Deploy Quay operator in OpenShift
44+
include_role:
45+
name: ocp-quay
46+
```
47+
48+
License
49+
-------
50+
51+
See LICENCE.txt
52+
53+
Author Information
54+
------------------
55+
56+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ocp-quay vars
2+
3+
quay_enabled: false #set to true for quay operator installation
4+
lso_index: "" # provide LSO index image
5+
cluster_upi: true #set to true if using UPI cluster
6+
quay_registry_namespace: "quay-registry" #Nmaespace for quay-registry
7+
quay_catalogsource_name: "quay-catsrc-zyz" # CatalogSource Name
8+
quay_catalogsource_image: "brew.registry.redhat.io/rh-osbs/iib:1009805" # CatalogSource Image
9+
quay_operator_channel : # Version of Quay to be installed
10+
quay_registry_hostname: "quay-registry.apps.xyz.ibm.com" # Hostname for Quayconfig
11+
volume_path: "/dev/disk/by-id/......" #Get the volume path using "ls /dev/disk/by-id/......"
12+
odf_index: " " #Example - quay.io/rhceph-dev/ocs-registry:4.16.3
13+
odf_channel: #Define this to set subscription channel for ODF Operator
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: quay.redhat.com/v1
2+
kind: QuayRegistry
3+
metadata:
4+
name: quayreg1
5+
namespace: quay-registry
6+
spec:
7+
configBundleSecret: config-bundle-secret
8+
components:
9+
- kind: clair
10+
managed: true
11+
- kind: quay
12+
managed: true
13+
- kind: postgres
14+
managed: true
15+
overrides:
16+
env:
17+
- name: DEBUGLOG
18+
value: "true"
19+
- kind: redis
20+
managed: true
21+
- kind: horizontalpodautoscaler
22+
managed: true
23+
- kind: objectstorage
24+
managed: true
25+
- kind: route
26+
managed: true
27+
- kind: mirror
28+
managed: false
29+
- kind: monitoring
30+
managed: true
31+
- kind: tls
32+
managed: true
33+
- kind: clairpostgres
34+
managed: true
35+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: quay.redhat.com/v1
2+
kind: QuayRegistry
3+
metadata:
4+
name: quayreg1
5+
namespace: quay-registry
6+
spec:
7+
configBundleSecret: config-bundle-secret
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# check if Cluster Health is good
2+
- name: Check if cluster operators and nodes are healthy
3+
include_role:
4+
name: check-cluster-health
5+
6+
- name: Get worker names
7+
command: oc get nodes -l node-role.kubernetes.io/worker --no-headers -o custom-columns=NAME:.metadata.name
8+
register: worker_list
9+
10+
- name: Save to worker list
11+
set_fact:
12+
worker: "{{ worker_list.stdout_lines }}"
13+
14+
- name: Check if LSO (Local Storage Operator) is already installed
15+
shell: |
16+
oc get csv -n openshift-local-storage -o json | jq -r '.items[] | select(.metadata.name | test("local-storage-operator")) | .status.phase'
17+
register: lso_csv_status
18+
changed_when: false
19+
failed_when: false
20+
21+
- name: Set flag if LSO is installed
22+
set_fact:
23+
lso_install_req: "{{ lso_csv_status.stdout != 'Succeeded' }}"
24+
25+
# Install LSO
26+
- name: Install LSO - Local Storage operator
27+
include_role:
28+
name: ocp-lso
29+
when: lso_install_req
30+
vars:
31+
lso_catalogsource_image: "{{ lso_index }}"
32+
upi_cluster: "{{ cluster_upi }}"
33+
device_path: "{{ volume_path }}"
34+
lso_namespace: "openshift-local-storage"
35+
lso_channel: "stable"
36+
lso_catalogsource_name: "redhat-operators"
37+
busybox_image: "quay.io/powercloud/busybox:ubi"
38+
39+
- name: Check if ODF (OpenShift Data Foundation) is already installed
40+
shell: |
41+
oc get csv -n openshift-storage -o json | jq -r '.items[] | select(.metadata.name | test("odf-operator")) | .status.phase'
42+
register: odf_csv_status
43+
changed_when: false
44+
failed_when: false
45+
46+
- name: Set flag if ODF is installed
47+
set_fact:
48+
odf_install_req: "{{ odf_csv_status.stdout != 'Succeeded' }}"
49+
50+
# ODF installation
51+
- name: Install ODF - Openshift Data Foundation
52+
include_role:
53+
name: ocp-odf-operator
54+
when: odf_install_req
55+
vars:
56+
odf_catalogsource_image: "{{ odf_index }}"
57+
update_channel: "{{ odf_channel }}"
58+
test_pod_image: "quay.io/powercloud/nginx-unprivileged:latest"
59+
60+
# Creating Project for Quay
61+
- name: Create quay-registry project
62+
k8s:
63+
state: present
64+
definition:
65+
apiVersion: v1
66+
kind: Namespace
67+
metadata:
68+
name: "{{ quay_registry_namespace }}"
69+
annotations:
70+
openshift.io/node-selector: 'node-role.kubernetes.io/infra='
71+
openshift.io/description: "Red Hat Quay Enterprise Container Image Repository"
72+
openshift.io/display-name: "Quay"
73+
scheduler.alpha.kubernetes.io/defaultTolerations: >-
74+
[{"operator": "Exists", "effect": "NoSchedule", "key": "node-role.kubernetes.io/infra"}]
75+
76+
- name: Switch to quay-registry project
77+
command: oc project {{ quay_registry_namespace }}
78+
79+
# Custom ImageContentSourcePolicy and CatalogSource
80+
- name: Create ImageContentSourcePolicy and CatalogSource
81+
block:
82+
- name: Include the global-secret-update role
83+
include_role:
84+
name: global-secret-update
85+
86+
- name: Include role to create ImageContentSourcePolicy and CatalogSource
87+
include_role:
88+
name: set-custom-catalogsource
89+
vars:
90+
custom_catalogsource_name: "{{ quay_catalogsource_name }}"
91+
custom_catalogsource_display_name: "Custom Quay CatalogSource"
92+
custom_catalogsource_image: "{{ quay_catalogsource_image }}"
93+
when: quay_catalogsource_image is defined or quay_catalogsource_image != '' and quay_catalogsource_image != None
94+
95+
- name: Use default CatalogSource if no custom image is provided
96+
set_fact:
97+
quay_catalogsource_name: "redhat-operators"
98+
when: quay_catalogsource_image is undefined or quay_catalogsource_image == '' or quay_catalogsource_image == None
99+
100+
- name: Verify creation of Catsrc
101+
shell: oc get catsrc -A | grep "{{ quay_catalogsource_name }}"
102+
register: catsrc
103+
until: catsrc.stdout|int == 0 and catsrc.stderr == ""
104+
retries: 10
105+
delay: 30
106+
107+
- name: Check if Quay CatalogSource exists and is READY
108+
shell: >
109+
oc get catalogsource {{ quay_catalogsource_name }} -n openshift-marketplace -o jsonpath='{.status.connectionState.lastObservedState}'
110+
register: quay_catsrc_check
111+
retries: 10
112+
delay: 15
113+
until: quay_catsrc_check.rc == 0
114+
changed_when: false
115+
failed_when: quay_catsrc_check.rc != 0
116+
117+
- name: Debug output for Quay CatalogSource check
118+
debug:
119+
msg: "Quay CatalogSource '{{ quay_catalogsource_name }}' is present and in Ready state."
120+
121+
# Label and taint infra nodes
122+
- name: Label and taint infra nodes
123+
shell: |
124+
oc label node {{ worker[0] }} node-role.kubernetes.io/infra=
125+
oc adm taint nodes {{ worker[0] }} node-role.kubernetes.io/infra:NoSchedule --overwrite
126+
oc label node {{ worker[1] }} node-role.kubernetes.io/infra=
127+
oc adm taint nodes {{ worker[1] }} node-role.kubernetes.io/infra:NoSchedule --overwrite
128+
args:
129+
executable: /bin/bash
130+
131+
- name: Create OperatorGroup for Quay
132+
k8s:
133+
state: present
134+
definition:
135+
apiVersion: operators.coreos.com/v1
136+
kind: OperatorGroup
137+
metadata:
138+
name: quay-operator-group
139+
namespace: "{{ quay_registry_namespace }}"
140+
spec: {}
141+
142+
- name: Create Quay Operator Subscription
143+
k8s:
144+
state: present
145+
definition:
146+
apiVersion: operators.coreos.com/v1alpha1
147+
kind: Subscription
148+
metadata:
149+
name: quay-operator
150+
namespace: "{{ quay_registry_namespace }}"
151+
spec:
152+
channel: "{{ quay_operator_channel }}"
153+
name: quay-operator
154+
source: "{{ quay_catalogsource_name }}"
155+
sourceNamespace: openshift-marketplace
156+
installPlanApproval: Automatic
157+
158+
- name: Check if Quay Operator CSV is in 'Succeeded' phase
159+
shell: |
160+
oc get csv -n {{ quay_registry_namespace }} --no-headers | grep quay-operator | grep Succeeded
161+
register: csv_status
162+
retries: 10
163+
delay: 30
164+
until: csv_status.stdout != "" and csv_status.stderr == ""
165+
failed_when: csv_status.rc != 0
166+
167+
- name: Debug Quay operator CSV status
168+
debug:
169+
msg: "Quay operator CSV has successfully reached 'Succeeded' state."
170+
171+
- name: Generate config.yaml from template
172+
template:
173+
src: config.yaml.j2
174+
dest: /tmp/config.yaml
175+
176+
# Create config-bundle-secret from existing config.yaml file
177+
- name: Create config-bundle-secret from rendered config.yaml
178+
shell: |
179+
oc create secret generic config-bundle-secret \
180+
--from-file=config.yaml=/tmp/config.yaml \
181+
-n {{ quay_registry_namespace }} \
182+
--dry-run=client -o yaml | oc apply -f -
183+
args:
184+
executable: /bin/bash
185+
186+
# Apply QuayRegistry CR from quay-registry.yaml
187+
- name: Apply QuayRegistry CR from quay-registry.yaml
188+
shell: oc apply -f quay-registry.yaml -n {{ quay_registry_namespace }}
189+
args:
190+
chdir: "{{ role_path }}/files"
191+
register: create_quayregistry
192+
193+
- name: Debug QuayRegistry creation output
194+
debug:
195+
var: create_quayregistry.stdout
196+
197+
- name: Wait a bit for pods to be created
198+
pause:
199+
seconds: 30
200+
201+
- name: Wait until all pods are Running or Completed in {{ quay_registry_namespace }}
202+
shell: |
203+
set -eo pipefail
204+
oc get pods -n {{ quay_registry_namespace }} -o json | \
205+
jq -r '.items[] | [.metadata.name, .status.phase, (.status.containerStatuses[0].ready // false)] | @tsv' | \
206+
awk '
207+
{
208+
if ($2 != "Running" && $2 != "Succeeded") {
209+
print "WAITING: Pod", $1, "is in phase", $2;
210+
exit 1;
211+
}
212+
if ($2 == "Running" && $3 != "true") {
213+
print "WAITING: Pod", $1, "is Running but not Ready";
214+
exit 1;
215+
}
216+
}
217+
'
218+
register: quay_pods_check
219+
retries: 40 # 10 minutes max wait
220+
delay: 15
221+
until: quay_pods_check.rc == 0

0 commit comments

Comments
 (0)