- job:
    description: |
      Test that nodepool works with kubernetes.
    name: nodepool-functional-k8s
    pre-run: playbooks/nodepool-functional-k8s/pre.yaml
    run: playbooks/nodepool-functional-k8s/run.yaml
    required-projects:
      - zuul/nodepool
    nodeset: debian-bookworm

- job:
    description: |
      Test that nodepool works with openshift.
    name: nodepool-functional-openshift
    pre-run: playbooks/nodepool-functional-openshift/pre.yaml
    run: playbooks/nodepool-functional-openshift/run.yaml
    nodeset:
      nodes:
        # Runs openshift
        - name: cluster
          label: centos-7
        # Runs nodepool
        - name: launcher
          label: debian-bookworm
    required-projects:
      - zuul/nodepool

- secret:
    name: nodepool-registry-credentials
    data:
      quay.io:
        username: zuul-ci+opendevzuul
        password: !encrypted/pkcs1-oaep
          - UzvPj5Dpro6eKDiAjCehYrm25f0auDdSh4UqDbcoVaqhGDXOFh3p1UCE46NxgE5Cuy210
            uOUXhvPL14s4BwwfQT8JMYFLnnJapEJTETBNIz9WQx/7AsKWiCiArovRwXKoZ3984Akk3
            CppNtnxrhxA+Cd9gdYUiAme6tr686UfN2MLvZOlfhCZ2roWfKY1qu/Ceo8CTmiYmuegFH
            iaWbgg/g4/8IZ+r9+xecBhSyTYj0C/jKUU6dvXDr2Q5tAfqEJN2pAetO6ElMW88gPCHyo
            BoYV0iBNVRBcfGVrzRRPD7Tyy6wrdQnpIGulUCn3s4v4Ds636a7JwCWn/g7gWxbi3tnxh
            vi1qKtzJ/f1NDCuGdy3wbfqo0emBzb6a155WytGxBRUXP4fpPTaGTKwKtJ1wIJ+fPrIc8
            E8Z3xJS8M4FC+VaJL+g7/JxIYJAuYwa0W8fKLo9WBKWnRfOmikwSwqe3Yr85ZR5yrpSBy
            ish0WSbIXLG3X9jgTWCAPDNrH/icwwBfEdfjHC2TnOVQmuP7qbzS3p5EQohArKmRCEitb
            oavnn7EDev0uyibyD9FQRhCdVzlfO+bA5fq7MaDaqs33J/oEcvvhKN93kKV01khBZFIpg
            5EXi9mbFMKiNBAx4wzxvSBIOQmZwrNsxCBZ1RLTqmX5mSmAngEvwOUWacA8r/4=
        api_token: !encrypted/pkcs1-oaep
          - nx/eF0tDwNN4Hhm38HIXhaHHO/IM6KoaHtUIgQOdlQvE2RwixAcSG8b4OCJe5zVVrGtjj
            MGsRC0qR8tNifsM6Lp005B+cYq7zgWFdeTtlFzYcZZkPZkIIlycfwKBAEJJ8gPwEOkh6D
            +D7MbC0+KhHnPMLh1jGng1tF6ekpWMsZ0qPIseYGoPe4RiM68kFBEI6rw1yZr43Q7aW40
            iWPK4ve2P8ACZX0vvCsiJdhjv3TIJNqY9B85oiwKBLjDxeHsAFiCfjQ126WuHw5qrY19+
            q64X3X7LSb284Tgb5zd7lm2lxPkNDY1eiLD0FN1ehnKRA3x7NCn4MeZUftVpC5hYMpBDJ
            2eJbuYhlvoBx7Dfb9ytV0b9rb6iuWd9W75ebSyLMiznur0e1nk8QVRWqwEBUpwCXm89W6
            pq1mBdi071Iqti3gQP/toSwgzzkqFZr3EGZPnD/dhHxfWNsGV7mAYGVlp09eet20EJ6Gw
            iCmxoFA7SZgj598MURNL7nbKGE2R4giDaBD1fEIrONVuk71u3AGDR2FKkKnRyjMNcPa86
            8CzjqGaMBmK394Jh5EklN2hI2J2FiGAq+cGvuXT3mIcG/DtpDKreRIdnPgBRG/ih7EJac
            of0pW1Z02wJQifV6bI2ONe9E7W6wmhRQhfXq3iJcWWLb42OI8ZWQQx4qdy6LN4=

- job:
    name: nodepool-build-image
    parent: opendev-build-container-image
    description: Build container images.
    timeout: &image_build_timeout 4800
    dependencies:
      - opendev-buildset-registry
    requires:
      - python-builder-3.11-bullseye-container-image
      - python-base-3.11-bullseye-container-image
    provides: nodepool-container-image
    vars: &nodepool_image_vars
      promote_container_image_method: intermediate-registry
      promote_container_image_job: nodepool-upload-image
      container_command: docker
      container_images:
        - context: .
          registry: quay.io
          repository: quay.io/zuul-ci/nodepool
          target: nodepool
          tags:
            # If zuul.tag is defined: [ '3', '3.19', '3.19.0' ].  Only works for 3-component tags.
            # Otherwise: ['latest']
            &imagetag "{{ zuul.tag is defined | ternary([zuul.get('tag', '').split('.')[0], '.'.join(zuul.get('tag', '').split('.')[:2]), zuul.get('tag', '')], ['latest']) }}"
          arch:
            - linux/amd64
            - linux/arm64
        - context: .
          registry: quay.io
          repository: quay.io/zuul-ci/nodepool-launcher
          target: nodepool-launcher
          tags: *imagetag
          arch:
            - linux/amd64
            - linux/arm64
        - context: .
          registry: quay.io
          repository: quay.io/zuul-ci/nodepool-builder
          target: nodepool-builder
          tags: *imagetag
          arch:
            - linux/amd64
            - linux/arm64

- job:
    name: nodepool-upload-image
    parent: opendev-upload-container-image
    description: Build container images and upload.
    timeout: *image_build_timeout
    requires:
      - python-builder-3.11-bullseye-container-image
      - python-base-3.11-bullseye-container-image
    provides: nodepool-container-image
    vars: *nodepool_image_vars
    secrets:
      - name: container_registry_credentials
        secret: nodepool-registry-credentials
        pass-to-parent: true

- job:
    name: nodepool-promote-image
    parent: opendev-promote-container-image
    description: Promote previously uploaded container images.
    vars: *nodepool_image_vars
    secrets:
      - name: container_registry_credentials
        secret: nodepool-registry-credentials
        pass-to-parent: true

# NOTE(ianw) : kept separate as these aren't intended to be released
- job:
    name: nodepool-build-image-siblings
    dependencies:
      - opendev-buildset-registry
    parent: opendev-build-container-image
    description: Build container images, with required projects as sibling from source
    required-projects:
      - zuul/nodepool
      - openstack/diskimage-builder
    requires:
      - python-builder-3.11-bullseye-container-image
      - python-base-3.11-bullseye-container-image
    provides: nodepool-siblings-container-image
    vars:
      zuul_work_dir: "{{ zuul.projects['opendev.org/zuul/nodepool'].src_dir }}"
      container_images:
        - context: .
          registry: quay.io
          repository: quay.io/zuul-ci/nodepool-launcher
          target: nodepool-launcher
          tags:
            - siblings
        - context: .
          registry: quay.io
          repository: quay.io/zuul-ci/nodepool-builder
          target: nodepool-builder
          tags:
            - siblings
          siblings:
            - opendev.org/openstack/diskimage-builder

- job:
    name: nodepool-functional-container-openstack-base
    abstract: true
    description: |
      Test Nodepool containers with an OpenStack.

      Note this is an abstract job and does not define an image to
      build and test, and you should not inherit directly from this
      job.

      If you wish to build the nodepool containers with released
      dependencies, you should inherit from
      nodepool-functional-container-openstack-release-base and define
      nodepool_diskimage for the image to build and test.

      If you wish to build the nodepool containers with dependencies
      installed from source, you should inherit from
      nodepool-functional-container-openstack-siblings-base and define
      nodepool_diskimage for the image build and test.
    timeout: 5400
    required-projects:
      - zuul/nodepool
    pre-run: playbooks/nodepool-functional-container-openstack/pre.yaml
    run: playbooks/nodepool-functional-container-openstack/run.yaml
    post-run: playbooks/nodepool-functional-container-openstack/post.yaml
    vars:
      zuul_copy_output:
        /var/log/nodepool: logs
    nodeset: ubuntu-jammy

- job:
    name: nodepool-functional-container-openstack-release-base
    abstract: true
    description: |
      Test Nodepool containers and OpenStack, against released
      dependencies.

      Note, this job does not define an image to build.  It should be
      inherited from and nodepool_diskimage defined.
    parent: nodepool-functional-container-openstack-base
    dependencies:
      - nodepool-build-image
    required-projects:
      - name: opendev/glean # note, installed by dib
      - name: zuul/nodepool

- job:
    name: nodepool-functional-container-openstack-release
    description: |
      Test Nodepool containers and OpenStack, with released projects

      This builds, uploads and boots a CentOS 8 image into a
      OpenStack cloud.
    parent: nodepool-functional-container-openstack-release-base
    vars:
      nodepool_diskimage:
        base_element: centos-minimal
        release: 9-stream
        mirror: "http://{{ zuul_site_mirror_fqdn }}/centos"
        env-vars:
          DIB_SIMPLE_INIT_NETWORKMANAGER: '1'

- job:
    name: nodepool-functional-container-openstack-siblings-base
    abstract: true
    description: |
      Test Nodepool containers and OpenStack, with some projects from source

      Note, this job does not define an image to build.  It should be
      inherited from and nodepool_diskimage defined.
    parent: nodepool-functional-container-openstack-base
    dependencies:
      - nodepool-build-image-siblings
    required-projects:
      - name: opendev/glean # note, installed by dib
      - name: zuul/nodepool
    vars:
      nodepool_container_tag: ':siblings'

- job:
    name: nodepool-functional-container-openstack-siblings
    description: |
      Test Nodepool containers and OpenStack, with some projects from source

      This builds, uploads and boots a CentOS 8 image into a
      OpenStack cloud.
    parent: nodepool-functional-container-openstack-siblings-base
    vars:
      nodepool_diskimage:
        base_element: centos-minimal
        release: 9-stream
        mirror: "http://{{ zuul_site_mirror_fqdn }}/centos"
        env-vars:
          DIB_SIMPLE_INIT_NETWORKMANAGER: '1'

- job:
    name: nodepool-nox-py311
    description: |
      Nodepool unit tests with ZooKeeper running
    parent: nox-py311
    pre-run: playbooks/nodepool-nox/pre.yaml
    vars:
      nox_environment:
        NODEPOOL_ZK_CA: /opt/zookeeper/ca/certs/cacert.pem
        NODEPOOL_ZK_CERT: /opt/zookeeper/ca/certs/client.pem
        NODEPOOL_ZK_KEY: /opt/zookeeper/ca/keys/clientkey.pem
    nodeset: ubuntu-jammy

- project:
    queue: zuul
    vars:
      release_python: python3
    check:
      jobs:
        - opendev-buildset-registry
        - nodepool-build-image
        - zuul-nox-docs:
            vars:
              nox_force_python: "3.11"
              python_version: "3.11"
        - nox-linters:
            nodeset: ubuntu-jammy
        - nodepool-nox-py311
        - nodepool-functional-container-openstack-release
        - nodepool-functional-k8s
        - nodepool-functional-openshift
        - zuul-quick-start:
            requires: zuul-container-image
            dependencies: nodepool-build-image
        - build-python-release
    gate:
      jobs:
        - nodepool-upload-image
        - zuul-nox-docs:
            vars:
              nox_force_python: "3.11"
              python_version: "3.11"
        - nox-linters:
            nodeset: ubuntu-jammy
        - nodepool-nox-py311
        - nodepool-functional-k8s
        - nodepool-functional-openshift
        - zuul-quick-start:
            requires: zuul-container-image
            dependencies: nodepool-upload-image
        - build-python-release
    promote:
      jobs:
        - nodepool-promote-image
        - zuul-promote-nox-docs
        - opendev-promote-python
    release:
      jobs:
        - opendev-release-python
        - zuul-publish-nox-docs:
            vars:
              nox_force_python: "3.11"
              python_version: "3.11"
        - upload-container-image:
            timeout: *image_build_timeout
            secrets:
              name: container_registry_credentials
              secret: nodepool-registry-credentials
              pass-to-parent: true
            vars:
              <<: *nodepool_image_vars
              upload_container_image_promote: false