|
4 | 4 | - name: Deploy Watcher service |
5 | 5 | hosts: "{{ cifmw_target_hook_host | default('localhost') }}" |
6 | 6 | gather_facts: false |
| 7 | + vars: |
| 8 | + watcher_cr_file_full: "ci/full_watcher_v1beta1_watcher_tlse.yaml" |
7 | 9 | environment: |
8 | 10 | KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
9 | 11 | PATH: "{{ cifmw_path }}" |
| 12 | + CTLPLANE_PATCH: "{{ watcher_ctlplane_patch | default( '{{ watcher_repo }}/ci/ctlplane_watcher_patch.yaml' ) }}" |
10 | 13 | tasks: |
| 14 | + # If the watcher-operator installation is already included in the openstack-operator we don't need to install it as |
| 15 | + # an standalone operator. |
| 16 | + - name: Check if Watcher API resources are available |
| 17 | + ansible.builtin.shell: |
| 18 | + cmd: |
| 19 | + oc api-resources --api-group=watcher.openstack.org -o name | grep -q watcher |
| 20 | + failed_when: false |
| 21 | + register: watcher_api_resources |
| 22 | + |
| 23 | + - name: add watcher_installed_integrated fact, true if Watcher API resources exist |
| 24 | + set_fact: |
| 25 | + watcher_installed_integrated: "{{ watcher_api_resources.rc == 0 }}" |
| 26 | + |
11 | 27 | - name: Fetch dlrn md5_hash from DLRN repo |
12 | 28 | when: fetch_dlrn_hash | default(true) | bool |
13 | 29 | ansible.builtin.uri: |
|
18 | 34 | retries: 6 |
19 | 35 | delay: 5 |
20 | 36 |
|
21 | | - - name: Install Watcher Operator |
22 | | - vars: |
23 | | - _tag: "{{ latest_dlrn_tag.content | default(watcher_services_tag) | default('current-podified') }}" |
24 | | - # When there is no Depends-On from opendev, then content_provider_os_registry_url will return null |
25 | | - # value to child job. In that case, we need to set default to quay registry. |
26 | | - _registry_url: >- |
27 | | - {%- if watcher_registry_url is defined -%} |
28 | | - {{ watcher_registry_url }} |
29 | | - {%- elif content_provider_os_registry_url is defined and content_provider_os_registry_url == 'null' -%} |
30 | | - quay.io/podified-master-centos9 |
31 | | - {%- else -%} |
32 | | - {{ content_provider_os_registry_url | default('quay.io/podified-master-centos9') }} |
33 | | - {%- endif -%} |
34 | | - cifmw.general.ci_script: |
35 | | - output_dir: "{{ cifmw_basedir }}/artifacts" |
36 | | - chdir: "{{ watcher_repo }}" |
37 | | - script: make watcher |
38 | | - extra_args: |
39 | | - CATALOG_IMAGE: "{{ watcher_catalog_image | default('quay.io/openstack-k8s-operators/watcher-operator-index:latest') }}" |
40 | | - WATCHER_API_CI_IMAGE: "{{ _registry_url }}/openstack-watcher-api:{{ _tag }}" |
41 | | - WATCHER_DECISION_ENGINE_CI_IMAGE: "{{ _registry_url }}/openstack-watcher-decision-engine:{{ _tag }}" |
42 | | - WATCHER_APPLIER_CI_IMAGE: "{{ _registry_url }}/openstack-watcher-applier:{{ _tag }}" |
| 37 | + - name: Install standalone watcher-operator if not integrated or force_watcher_standalone is true |
| 38 | + when: (not watcher_installed_integrated) or (force_watcher_standalone | default(false) | bool) |
| 39 | + block: |
| 40 | + - name: Stop watcher-operator if it is running in integrated mode |
| 41 | + when: watcher_installed_integrated |
| 42 | + cifmw.general.ci_script: |
| 43 | + output_dir: "{{ cifmw_basedir }}/artifacts" |
| 44 | + chdir: "{{ watcher_repo }}" |
| 45 | + script: make stop_watcher_integrated |
| 46 | + |
| 47 | + - name: Install Watcher Operator in standalone mode |
| 48 | + vars: |
| 49 | + _tag: "{{ latest_dlrn_tag.content | default(watcher_services_tag) | default('current-podified') }}" |
| 50 | + # When there is no Depends-On from opendev, then content_provider_os_registry_url will return null |
| 51 | + # value to child job. In that case, we need to set default to quay registry. |
| 52 | + _registry_url: >- |
| 53 | + {%- if watcher_registry_url is defined -%} |
| 54 | + {{ watcher_registry_url }} |
| 55 | + {%- elif content_provider_os_registry_url is defined and content_provider_os_registry_url == 'null' -%} |
| 56 | + quay.io/podified-master-centos9 |
| 57 | + {%- else -%} |
| 58 | + {{ content_provider_os_registry_url | default('quay.io/podified-master-centos9') }} |
| 59 | + {%- endif -%} |
| 60 | + cifmw.general.ci_script: |
| 61 | + output_dir: "{{ cifmw_basedir }}/artifacts" |
| 62 | + chdir: "{{ watcher_repo }}" |
| 63 | + script: make watcher |
| 64 | + extra_args: |
| 65 | + CATALOG_IMAGE: "{{ watcher_catalog_image | default('quay.io/openstack-k8s-operators/watcher-operator-index:latest') }}" |
| 66 | + WATCHER_API_CI_IMAGE: "{{ _registry_url }}/openstack-watcher-api:{{ _tag }}" |
| 67 | + WATCHER_DECISION_ENGINE_CI_IMAGE: "{{ _registry_url }}/openstack-watcher-decision-engine:{{ _tag }}" |
| 68 | + WATCHER_APPLIER_CI_IMAGE: "{{ _registry_url }}/openstack-watcher-applier:{{ _tag }}" |
| 69 | + |
| 70 | + # Once the integration in the openstack controlplane is finished and merged everywhere we will be |
| 71 | + # able to deploy watcher using kustomize in a pre_deploy hook. Until then we need to discover |
| 72 | + # if the integration is finished and that can not be done in pre_deploy hook as it runs before |
| 73 | + # make openstack_init so I am implementing it in this playbook which runs in post_deploy |
| 74 | + - name: Check if a Watcher CR is already created |
| 75 | + ansible.builtin.shell: |
| 76 | + cmd: |
| 77 | + oc get watcher -A -o name | grep -q watcher |
| 78 | + failed_when: false |
| 79 | + register: watcher_deployed |
| 80 | + |
| 81 | + - name: Add watcher_is_deployed fact, true if a Watcher CR exist, otherwise false |
| 82 | + set_fact: |
| 83 | + watcher_is_deployed: "{{ watcher_deployed.rc == 0 }}" |
| 84 | + |
| 85 | + - name: Check if Watcher is fully integrated in the OpenStackControlPlane |
| 86 | + ansible.builtin.shell: |
| 87 | + cmd: |
| 88 | + oc explain openstackcontrolplane.spec|grep -q -w "watcher" |
| 89 | + failed_when: false |
| 90 | + register: watcher_controlplane_spec |
| 91 | + |
| 92 | + - name: Add watcher_in_ctlplane fact, true if Watcher is in the controlplane CRD |
| 93 | + set_fact: |
| 94 | + watcher_in_ctlplane: "{{ watcher_controlplane_spec.rc == 0 }}" |
43 | 95 |
|
44 | 96 | - name: Deploy Watcher service |
45 | | - when: deploy_watcher_service | default('true') | bool |
46 | | - cifmw.general.ci_script: |
47 | | - output_dir: "{{ cifmw_basedir }}/artifacts" |
48 | | - chdir: "{{ watcher_repo }}" |
49 | | - script: make watcher_deploy |
50 | | - extra_args: |
51 | | - WATCHER_SAMPLE_CR_PATH: "{{ watcher_cr_file | default('ci/watcher_v1beta1_watcher.yaml') }}" |
| 97 | + when: |
| 98 | + - deploy_watcher_service | default('true') | bool |
| 99 | + - not watcher_is_deployed |
| 100 | + block: |
| 101 | + # When not using the standalone mode in the operator but watcher is not |
| 102 | + # in the openstackcontrolplane we do not have mutating webhooks so we need |
| 103 | + # to override the Watcher CR to use one that includes the container image URLs |
| 104 | + - name: Set watcher_cr_file to the one with container images |
| 105 | + when: |
| 106 | + - not watcher_in_ctlplane |
| 107 | + - watcher_installed_integrated |
| 108 | + - not force_watcher_standalone | default(false) | bool |
| 109 | + set_fact: |
| 110 | + watcher_cr_file_override: "{{ watcher_cr_file_full }}" |
| 111 | + |
| 112 | + - name: Deploy Watcher service using standalone Watcher CR |
| 113 | + when: not watcher_in_ctlplane |
| 114 | + vars: |
| 115 | + _tag: "{{ latest_dlrn_tag.content | default(watcher_services_tag) | default('current-podified') }}" |
| 116 | + # When there is no Depends-On from opendev, then content_provider_os_registry_url will return null |
| 117 | + # value to child job. In that case, we need to set default to quay registry. |
| 118 | + _registry_url: >- |
| 119 | + {%- if watcher_registry_url is defined -%} |
| 120 | + {{ watcher_registry_url }} |
| 121 | + {%- elif content_provider_os_registry_url is defined and content_provider_os_registry_url == 'null' -%} |
| 122 | + quay.io/podified-master-centos9 |
| 123 | + {%- else -%} |
| 124 | + {{ content_provider_os_registry_url | default('quay.io/podified-master-centos9') }} |
| 125 | + {%- endif -%} |
| 126 | + cifmw.general.ci_script: |
| 127 | + output_dir: "{{ cifmw_basedir }}/artifacts" |
| 128 | + chdir: "{{ watcher_repo }}" |
| 129 | + script: make watcher_deploy |
| 130 | + extra_args: |
| 131 | + WATCHER_SAMPLE_CR_PATH: "{{ watcher_cr_file_override | default( watcher_cr_file | default('ci/watcher_v1beta1_watcher.yaml')) }}" |
| 132 | + WATCHER_API_CI_IMAGE: "{{ _registry_url }}/openstack-watcher-api:{{ _tag }}" |
| 133 | + WATCHER_DECISION_ENGINE_CI_IMAGE: "{{ _registry_url }}/openstack-watcher-decision-engine:{{ _tag }}" |
| 134 | + WATCHER_APPLIER_CI_IMAGE: "{{ _registry_url }}/openstack-watcher-applier:{{ _tag }}" |
| 135 | + |
| 136 | + - name: Deploy Watcher service by patching an existing OpenStackControlplane |
| 137 | + when: watcher_in_ctlplane |
| 138 | + ansible.builtin.shell: |
| 139 | + cmd: | |
| 140 | + set -ex |
| 141 | + CTLPLANE=$(oc get openstackcontrolplane -n openstack -o jsonpath="{range .items[*]}{@.metadata.name}{end}") |
| 142 | + oc patch openstackcontrolplane $CTLPLANE -n openstack --type merge --patch-file $CTLPLANE_PATCH |
| 143 | + oc wait openstackcontrolplane $CTLPLANE -n openstack --for condition=Ready --timeout=600s |
| 144 | + oc wait watcher watcher -n openstack --for condition=Ready --timeout=600s |
0 commit comments