|
| 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_installed: "{{ 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: not lso_installed |
| 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: "my-operator-catalog" |
| 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_installed: "{{ 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: not odf_installed |
| 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 != '' 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 == '' 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 | +- name: Create OperatorGroup for Quay |
| 122 | + k8s: |
| 123 | + state: present |
| 124 | + definition: |
| 125 | + apiVersion: operators.coreos.com/v1 |
| 126 | + kind: OperatorGroup |
| 127 | + metadata: |
| 128 | + name: quay-operator-group |
| 129 | + namespace: "{{ quay_registry_namespace }}" |
| 130 | + spec: {} |
| 131 | + |
| 132 | +- name: Create Quay Operator Subscription |
| 133 | + k8s: |
| 134 | + state: present |
| 135 | + definition: |
| 136 | + apiVersion: operators.coreos.com/v1alpha1 |
| 137 | + kind: Subscription |
| 138 | + metadata: |
| 139 | + name: quay-operator |
| 140 | + namespace: "{{ quay_registry_namespace }}" |
| 141 | + spec: |
| 142 | + channel: "{{ quay_operator_channel }}" |
| 143 | + name: quay-operator |
| 144 | + source: "{{ quay_catalogsource_name }}" |
| 145 | + sourceNamespace: openshift-marketplace |
| 146 | + installPlanApproval: Automatic |
| 147 | + |
| 148 | +- name: Check if Quay Operator CSV is in 'Succeeded' phase |
| 149 | + shell: | |
| 150 | + oc get csv -n {{ quay_registry_namespace }} --no-headers | grep quay-operator | grep Succeeded |
| 151 | + register: csv_status |
| 152 | + retries: 10 |
| 153 | + delay: 30 |
| 154 | + until: csv_status.stdout != "" and csv_status.stderr == "" |
| 155 | + failed_when: csv_status.rc != 0 |
| 156 | + |
| 157 | +- name: Debug Quay operator CSV status |
| 158 | + debug: |
| 159 | + msg: "Quay operator CSV has successfully reached 'Succeeded' state." |
| 160 | + |
| 161 | +# Label and taint infra nodes |
| 162 | +- name: Label and taint infra nodes |
| 163 | + shell: | |
| 164 | + oc label node --overwrite {{ worker[0] }} node-role.kubernetes.io/infra= |
| 165 | + oc adm taint nodes {{ worker[0] }} node-role.kubernetes.io/infra:NoSchedule --overwrite |
| 166 | + oc label node --overwrite {{ worker[1] }} node-role.kubernetes.io/infra= |
| 167 | + oc adm taint nodes {{ worker[1] }} node-role.kubernetes.io/infra:NoSchedule --overwrite |
| 168 | + args: |
| 169 | + executable: /bin/bash |
| 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 |
| 222 | + |
0 commit comments