Skip to content

Commit 6699156

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

File tree

11 files changed

+374
-0
lines changed

11 files changed

+374
-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: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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: Check if Quay CatalogSource exists and is READY
101+
shell: >
102+
oc get catalogsource {{ quay_catalogsource_name }} -n openshift-marketplace -o jsonpath='{.status.connectionState.lastObservedState}'
103+
register: quay_catsrc_check
104+
retries: 10
105+
delay: 15
106+
until: quay_catsrc_check.rc == 0
107+
changed_when: false
108+
failed_when: quay_catsrc_check.rc != 0
109+
110+
- name: Debug output for Quay CatalogSource check
111+
debug:
112+
msg: "Quay CatalogSource '{{ quay_catalogsource_name }}' is present and in Ready state."
113+
114+
# Label and taint infra nodes
115+
- name: Label and taint infra nodes
116+
shell: |
117+
oc label node {{ worker[0] }} node-role.kubernetes.io/infra=
118+
oc adm taint nodes {{ worker[0] }} node-role.kubernetes.io/infra:NoSchedule --overwrite
119+
oc label node {{ worker[1] }} node-role.kubernetes.io/infra=
120+
oc adm taint nodes {{ worker[1] }} node-role.kubernetes.io/infra:NoSchedule --overwrite
121+
args:
122+
executable: /bin/bash
123+
124+
- name: Create OperatorGroup for Quay
125+
k8s:
126+
state: present
127+
definition:
128+
apiVersion: operators.coreos.com/v1
129+
kind: OperatorGroup
130+
metadata:
131+
name: quay-operator-group
132+
namespace: "{{ quay_registry_namespace }}"
133+
spec: {}
134+
135+
- name: Create Quay Operator Subscription
136+
k8s:
137+
state: present
138+
definition:
139+
apiVersion: operators.coreos.com/v1alpha1
140+
kind: Subscription
141+
metadata:
142+
name: quay-operator
143+
namespace: "{{ quay_registry_namespace }}"
144+
spec:
145+
channel: "{{ quay_operator_channel }}"
146+
name: quay-operator
147+
source: "{{ quay_catalogsource_name }}"
148+
sourceNamespace: openshift-marketplace
149+
installPlanApproval: Automatic
150+
151+
- name: Check if Quay Operator CSV is in 'Succeeded' phase
152+
shell: |
153+
oc get csv -n {{ quay_registry_namespace }} --no-headers | grep quay-operator | grep Succeeded
154+
register: csv_status
155+
retries: 10
156+
delay: 30
157+
until: csv_status.stdout != "" and csv_status.stderr == ""
158+
failed_when: csv_status.rc != 0
159+
160+
- name: Debug Quay operator CSV status
161+
debug:
162+
msg: "Quay operator CSV has successfully reached 'Succeeded' state."
163+
164+
- name: Generate config.yaml from template
165+
template:
166+
src: config.yaml.j2
167+
dest: /tmp/config.yaml
168+
169+
# Create config-bundle-secret from existing config.yaml file
170+
- name: Create config-bundle-secret from rendered config.yaml
171+
shell: |
172+
oc create secret generic config-bundle-secret \
173+
--from-file=config.yaml=/tmp/config.yaml \
174+
-n {{ quay_registry_namespace }} \
175+
--dry-run=client -o yaml | oc apply -f -
176+
args:
177+
executable: /bin/bash
178+
179+
# Apply QuayRegistry CR from quay-registry.yaml
180+
- name: Apply QuayRegistry CR from quay-registry.yaml
181+
shell: oc apply -f quay-registry.yaml -n {{ quay_registry_namespace }}
182+
args:
183+
chdir: "{{ role_path }}/files"
184+
register: create_quayregistry
185+
186+
- name: Debug QuayRegistry creation output
187+
debug:
188+
var: create_quayregistry.stdout
189+
190+
- name: Wait a bit for pods to be created
191+
pause:
192+
seconds: 30
193+
194+
- name: Wait until all pods are Running or Completed in {{ quay_registry_namespace }}
195+
shell: |
196+
set -eo pipefail
197+
oc get pods -n {{ quay_registry_namespace }} -o json | \
198+
jq -r '.items[] | [.metadata.name, .status.phase, (.status.containerStatuses[0].ready // false)] | @tsv' | \
199+
awk '
200+
{
201+
if ($2 != "Running" && $2 != "Succeeded") {
202+
print "WAITING: Pod", $1, "is in phase", $2;
203+
exit 1;
204+
}
205+
if ($2 == "Running" && $3 != "true") {
206+
print "WAITING: Pod", $1, "is Running but not Ready";
207+
exit 1;
208+
}
209+
}
210+
'
211+
register: quay_pods_check
212+
retries: 40 # 10 minutes max wait
213+
delay: 15
214+
until: quay_pods_check.rc == 0

0 commit comments

Comments
 (0)