- name: install and start zuul operator
  hosts: all
  vars:
    # Override this if you are running the operator interactively
    # locally for development.
    install_operator: true
    zuul_work_dir: "{{ zuul.projects['opendev.org/zuul/zuul-operator'].src_dir }}"
    runtime: minikube
  tasks:
    - name: Setup CRD
      command: kubectl apply -f deploy/crds/zuul-ci_v1alpha2_zuul_crd.yaml -f deploy/rbac.yaml
      args:
        chdir: "{{ zuul_work_dir }}"

    - name: Install operator
      when: install_operator
      command: kubectl apply -f deploy/operator.yaml
      args:
        chdir: "{{ zuul_work_dir }}"

    - name: Create static node
      include_tasks: ./tasks/create_static_node.yaml

    - name: Create required secret
      include_tasks: ./tasks/create_test_secrets.yaml

    - name: Wait for operator deployment
      when: install_operator
      command: timeout 8m kubectl rollout status deployment/zuul-operator

    - name: Deploy CR
      include_tasks: tasks/apply_cr.yaml
      vars:
        spec:
          database:
            allowUnsafeConfig: true
          executor:
            count: 1
            sshkey:
              secretName: executor-ssh-key
          merger:
            count: 1
          scheduler:
            config:
              secretName: zuul-yaml-conf
          launcher:
            config:
              secretName: nodepool-yaml-conf
          connections:
            opendev.org:
              driver: git
              baseurl: https://opendev.org
          externalConfig:
            kubernetes:
              secretName: nodepool-kube-config
          registry:
            count: 1
            config:
              secretName: zuul-registry-conf
          preview:
            count: 1

    - name: Wait for services
      include_tasks: ./tasks/wait_services.yaml

    - name: Test the cert-manager
      include_tasks: ./tasks/test_cert_manager.yaml