From 1cff2e52ce95becc8ed5540f5f48333a5f502501 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Tue, 29 Aug 2023 19:29:27 +0100 Subject: [PATCH] Use _dir instead of hardcoding all directories relative to base_dir This will allow configuration of the repo clone destination, so we can use pre-cloned dirs instead of explicitly cloning the dirs each time. This is essential for CI systems like zuul, that set-up the repos with particular versions/branches prior to running the test scripts. --- build/stf-run-ci/tasks/clone_repos.yml | 61 +++++++++++-------- build/stf-run-ci/tasks/main.yml | 15 +++-- .../tasks/setup_stf_local_build.yml | 10 +-- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/build/stf-run-ci/tasks/clone_repos.yml b/build/stf-run-ci/tasks/clone_repos.yml index 23a8ae630..afe04d4df 100644 --- a/build/stf-run-ci/tasks/clone_repos.yml +++ b/build/stf-run-ci/tasks/clone_repos.yml @@ -4,74 +4,87 @@ # recovery when the request branch doesn't exist) we have to define each # of these separately rather than using a loop. -- name: Check if the {{ sgo_repository }} already exists - stat: - path: "{{ sgo_repository }}" - register: sgo_dir +# This will be removed and these will become defaults. +# we can then set the values in zuul... and set a clone_repos: false instead +- name: Check if the {{ sgo_dir }} already exists + ansible.builtin.stat: + path: "{{ sgo_dir }}" + register: check_sgo_dir + +- name: Check if the {{ sg_core_dir }} already exists + ansible.builtin.stat: + path: "{{ sg_core_dir }}" + register: check_sg_core_dir + +- name: Check if the {{ sg_bridge_dir }} already exists + ansible.builtin.stat: + path: "{{ sg_bridge_dir }}" + register: check_sg_bridge_dir + +- name: Check if the {{ prometheus_webhook_snmp_dir }} already exists + ansible.builtin.stat: + path: "{{ prometheus_webhook_snmp_dir }}" + register: check_prometheus_webhook_snmp_dir - name: Get Smart Gateway Operator - when: not sgo_dir.stat.exists + when: not check_sgo_dir.stat.exists block: - name: Try cloning same-named branch or override branch from SGO repository ansible.builtin.git: repo: "{{ sgo_repository }}" - dest: "{{ base_dir }}/working/smart-gateway-operator" - version: "{{ sgo_branch | default(branch, true) }}" - force: yes + dest: "{{ sgo_dir }}" + version: "{{ version_branches.sgo | default(branch, true) }}" rescue: - name: "Get {{ version_branches.sgo }} upstream branch because specified branch or repository doesn't exist" ansible.builtin.git: repo: https://github.com/infrawatch/smart-gateway-operator - dest: "{{ base_dir }}/working/smart-gateway-operator" + dest: "{{ sgo_dir }}" version: "{{ version_branches.sgo }}" # have this task clone one repo, and use include/import_task to loop -- name: Check if the {{ sg_core_repository }} exists - ansible.builtin.stat: - path: "{{ sg_core_repository }}" - register: sgcore_dir - - name: Get sg-core - when: not sgcore_dir.stat.exists + when: not check_sg_core_dir.stat.exists block: - name: Try cloning same-named branch or override branch from sg-core repository ansible.builtin.git: repo: "{{ sg_core_repository }}" - dest: "{{ base_dir }}/working/sg-core" - version: "{{ sg_core_branch | default(branch, true) }}" + dest: "{{ sg_core_dir }}" + version: "{{ version_branches.sg_core | default(branch, true) }}" rescue: - name: "Get {{ version_branches.sg_core }} upstream branch because specified branch or repository doesn't exist" ansible.builtin.git: repo: https://github.com/infrawatch/sg-core - dest: "{{ base_dir }}/working/sg-core" + dest: "{{ sg_core_dir }}" version: "{{ version_branches.sg_core }}" - name: Get sg-bridge + when: not check_sg_bridge_dir.stat.exists block: - name: Try cloning same-named branch or override branch from sg-bridge repository git: repo: "{{ sg_bridge_repository }}" - dest: "{{ base_dir }}/working/sg-bridge" - version: "{{ sg_bridge_branch | default(branch, true) }}" + dest: "{{ sg_bridge_dir }}" + version: "{{ version_branches.sg_bridge | default(branch, true) }}" rescue: - name: "Get {{ version_branches.sg_bridge }} upstream branch because specified branch or repository doesn't exist" git: repo: https://github.com/infrawatch/sg-bridge - dest: "{{ base_dir }}/working/sg-bridge" + dest: "{{ sg_bridge_dir }}" version: "{{ version_branches.sg_bridge }}" - name: Get prometheus-webhook-snmp + when: not check_prometheus_webhook_snmp_dir.stat.exists block: - name: Try cloning same-named branch or override branch from prometheus-webhook-snmp repository git: repo: "{{ prometheus_webhook_snmp_repository }}" - dest: "{{ base_dir }}/working/prometheus-webhook-snmp" - version: "{{ prometheus_webhook_snmp_branch | default(branch, true) }}" + dest: "{{ prometheus_webhook_snmp_dir }}" + version: "{{ version_branches.prometheus_webhook_snmp | default(branch, true) }}" rescue: - name: "Get {{ version_branches.prometheus_webhook_snmp }} upstream branch because specified branch or repository doesn't exist" git: repo: https://github.com/infrawatch/prometheus-webhook-snmp - dest: "{{ base_dir }}/working/prometheus-webhook-snmp" + dest: "{{ prometheus_webhook_snmp_dir }}" version: "{{ version_branches.prometheus_webhook_snmp }}" diff --git a/build/stf-run-ci/tasks/main.yml b/build/stf-run-ci/tasks/main.yml index a2b902444..2973f04b2 100644 --- a/build/stf-run-ci/tasks/main.yml +++ b/build/stf-run-ci/tasks/main.yml @@ -71,6 +71,13 @@ base_dir: "{{ playbook_dir }}" when: base_dir | length == 0 +- name: Set the repo destination dirs, if not provided + ansible.builtin.set_fact: + sgo_dir: "{{ sgo_dir if sgo_dir is defined else base_dir + '/working/smart-gateway-operator' }}" + sg_core_dir: "{{ sg_core_dir if sg_core_dir is defined else base_dir + '/working/sg-core' }}" + sg_bridge_dir: "{{ sg_bridge_dir if sg_bridge_dir is defined else base_dir + '/working/sg-bridge'}}" + prometheus_webhook_snmp_dir: "{{ prometheus_webhook_snmp_dir if prometheus_webhook_snmp_dir is defined else base_dir + '/working/prometheus-webhook-snmp' }}" + - name: Get new operator sdk when: __local_build_enabled | bool or __deploy_from_bundles_enabled | bool or __deploy_from_index_enabled | bool ansible.builtin.command: @@ -94,10 +101,10 @@ ansible.builtin.set_fact: build_list: - {name: service-telemetry-operator, dockerfile_path: build/Dockerfile, image_reference_name: sto_image_path, working_build_dir: "{{ base_dir }}/../"} - - {name: smart-gateway-operator, dockerfile_path: build/Dockerfile, image_reference_name: sgo_image_path, working_build_dir: "{{ base_dir }}/working/smart-gateway-operator"} - - {name: sg-core, dockerfile_path: build/Dockerfile, image_reference_name: sg_core_image_path, working_build_dir: "{{ base_dir }}/working/sg-core"} - - {name: sg-bridge, dockerfile_path: build/Dockerfile, image_reference_name: sg_bridge_image_path, working_build_dir: "{{ base_dir }}/working/sg-bridge"} - - {name: prometheus-webhook-snmp, dockerfile_path: Dockerfile, image_reference_name: prometheus_webhook_snmp_image_path, working_build_dir: "{{ base_dir }}/working/prometheus-webhook-snmp"} + - {name: smart-gateway-operator, dockerfile_path: build/Dockerfile, image_reference_name: sgo_image_path, working_build_dir: "{{ sgo_dir }}"} + - {name: sg-core, dockerfile_path: build/Dockerfile, image_reference_name: sg_core_image_path, working_build_dir: "{{ sg_core_dir }}"} + - {name: sg-bridge, dockerfile_path: build/Dockerfile, image_reference_name: sg_bridge_image_path, working_build_dir: "{{ sg_bridge_dir }}"} + - {name: prometheus-webhook-snmp, dockerfile_path: Dockerfile, image_reference_name: prometheus_webhook_snmp_image_path, working_build_dir: "{{ prometheus_webhook_snmp_dir }}"} - ansible.builtin.debug: var: build_list diff --git a/build/stf-run-ci/tasks/setup_stf_local_build.yml b/build/stf-run-ci/tasks/setup_stf_local_build.yml index 10ac3b533..14c094586 100644 --- a/build/stf-run-ci/tasks/setup_stf_local_build.yml +++ b/build/stf-run-ci/tasks/setup_stf_local_build.yml @@ -17,7 +17,7 @@ - name: Generate Smart Gateway Operator CSV ansible.builtin.shell: - chdir: "{{ base_dir }}/working/smart-gateway-operator/build" + chdir: "{{ sgo_dir }}/build" cmd: | LOGFILE="./sgo_gen_bundle.log" \ OPERATOR_SDK="{{ base_dir }}/working/operator-sdk-{{ new_operator_sdk_version }}" \ @@ -39,12 +39,12 @@ - name: Show logfile from generate_bundle ansible.builtin.command: cmd: cat sgo_gen_bundle.log - chdir: "{{ base_dir }}/working/smart-gateway-operator/build" + chdir: "{{ sgo_dir }}/build" ignore_errors: true - name: Replace namespace in SGO role binding ansible.builtin.replace: - path: "{{ base_dir }}/working/smart-gateway-operator/deploy/role_binding.yaml" + path: "{{ sgo_dir }}/deploy/role_binding.yaml" regexp: 'placeholder' replace: '{{ namespace }}' @@ -58,8 +58,8 @@ block: - name: Load Smart Gateway Operator RBAC ansible.builtin.command: - cmd: oc apply -f working/smart-gateway-operator/deploy/{{ item }} -n "{{ namespace }}" - chdir: "{{ base_dir }}" + cmd: oc apply -f ./deploy/{{ item }} -n "{{ namespace }}" + chdir: "{{ sgo_dir }}" loop: - service_account.yaml - role.yaml