--- - name: Set random value ansible.builtin.set_fact: zuul_worker_ci_label: "zuul-worker-sf-operator-ci-{{ lookup('community.general.random_string', special=false, upper=false, length=8) }}" # First attempt a negative test where we expect a failure - name: Ensure nodepool directory exists ansible.builtin.file: path: "{{ config_path }}/nodepool" state: directory - name: Set bad Nodepool config ansible.builtin.blockinfile: content: | labELz: {} path: "{{ config_path }}/nodepool/nodepool.yaml" create: true - name: Commit file in the config repo ansible.builtin.command: "{{ item }}" args: chdir: "{{ config_path }}" loop: - "git add nodepool/nodepool.yaml" - "git commit -m 'Add nodepool/nodepool.yaml'" - ansible.builtin.include_role: name: "health-check/repo-submit-change" vars: ensure_job_failure: true # Now proceed with adding a correct tenant file - name: Reset the config repo ansible.builtin.command: "git reset --hard gerrit/master" args: chdir: "{{ config_path }}" - name: Ensure nodepool directory exists ansible.builtin.file: path: "{{ config_path }}/nodepool" state: directory - name: Check nodepool.yaml exists ansible.builtin.stat: path: "{{ config_path }}/nodepool/nodepool.yaml" register: _conf - name: Ensure nodepool.yaml default content ansible.builtin.copy: content: | labels: [] providers: [] dest: "{{ config_path }}/nodepool/nodepool.yaml" when: not _conf.stat.exists - name: Load current nodepool launcher config ansible.builtin.command: | cat {{ config_path }}/nodepool/nodepool.yaml register: launcher_config_raw - ansible.builtin.set_fact: launcher_config: "{{ launcher_config_raw.stdout | from_yaml }}" new_label: - name: "{{ zuul_worker_ci_label }}" microshift_provider: - name: microshiftLocal driver: openshiftpods context: openshiftpods pools: # NOTE: name is a name of the namespace # https://github.com/softwarefactory-project/sf-config/blob/master/ansible/roles/sf-repos/files/config/nodepool/openshift.yaml#L30 # https://zuul-ci.org/docs/nodepool/latest/openshift-pods.html - name: nodepool labels: - name: "{{ zuul_worker_ci_label }}" image: quay.io/software-factory/zuul-worker-sf-operator-ci:latest python-path: /bin/python3 - ansible.builtin.set_fact: launcher_labels: "{{ launcher_config['labels'] }}" when: - "'labels' in launcher_config" - ansible.builtin.set_fact: launcher_labels: [] when: - "'labels' not in launcher_config" - ansible.builtin.set_fact: launcher_providers: "{{ launcher_config['providers'] | selectattr('name', '!=', 'microshiftLocal') }}" when: - "'providers' in launcher_config" - ansible.builtin.set_fact: launcher_providers: [] when: - "'providers' not in launcher_config" - ansible.builtin.set_fact: launcher_new_labels: "{{ launcher_labels + new_label }}" launcher_new_providers: "{{ launcher_providers + microshift_provider }}" - ansible.builtin.set_fact: launcher_new_config: "{{ launcher_config | ansible.builtin.combine({'labels': launcher_new_labels, 'providers': launcher_new_providers}) }}" - name: Set dummy Nodepool config ansible.builtin.copy: content: "{{ launcher_new_config | to_nice_yaml }}" dest: "{{ config_path }}/nodepool/nodepool.yaml" - name: Commit file in the config repo ansible.builtin.command: "{{ item }}" args: chdir: "{{ config_path }}" loop: - "git add nodepool/nodepool.yaml" - "git commit -m 'Add nodepool/nodepool.yaml'" - name: Update config repo change ansible.builtin.include_role: name: "health-check/repo-submit-change" - name: Get nodepool-launcher pod name ansible.builtin.shell: | kubectl get pods -l "{{ pod_label }}" --no-headers -o custom-columns=":metadata.name" register: _pod_name - name: "Check that new {{ zuul_worker_ci_label }} label exists in the destination file" ansible.builtin.shell: | kubectl exec {{ _pod_name.stdout }} -c {{ container_name }} -- grep "{{ item }}" /etc/nodepool/nodepool.yaml loop: - "{{ zuul_worker_ci_label }}" - "microshiftLocal" - name: Ensure the new label listed in the Nodepool API ansible.builtin.uri: url: "https://{{ nodepool_endpoint }}/api/label-list" method: GET validate_certs: "{{ validate_certs }}" status_code: [200, 503] return_content: true register: this until: - this.status == 200 - zuul_worker_ci_label in this.content retries: 6 delay: 5 - name: Ensure the new label listed in the Zuul API ansible.builtin.uri: url: "https://{{ zuul_endpoint }}/api/tenant/internal/labels" method: GET validate_certs: "{{ validate_certs }}" status_code: [200, 503] return_content: true register: this until: - this.status == 200 - zuul_worker_ci_label in this.content retries: "{{ zuul_api_retries }}" delay: "{{ zuul_api_delay }}"