---
- include_tasks: setup_remote_tmp_dir.yml

- set_fact:
    virtualenv: "{{ remote_tmp_dir }}/virtualenv"
    virtualenv_command: "{{ ansible_python_interpreter }} -m venv"

- set_fact:
    virtualenv_interpreter: "{{ virtualenv }}/bin/python"

# Test graceful failure for missing kubernetes-validate

- pip:
    name:
      - kubernetes>=12.0.0
      - coverage>=5.3
    virtualenv: "{{ virtualenv }}"
    virtualenv_command: "{{ virtualenv_command }}"
    virtualenv_site_packages: no

- include_tasks: validate_not_installed.yml
  vars:
    ansible_python_interpreter: "{{ virtualenv_interpreter }}"

- file:
    path: "{{ virtualenv }}"
    state: absent
  no_log: yes

# Test validate with kubernetes-validate

- pip:
    name:
      - kubernetes-validate==1.12.0
      - kubernetes>=12.0.0
      - coverage>=5.3
    virtualenv: "{{ virtualenv }}"
    virtualenv_command: "{{ virtualenv_command }}"
    virtualenv_site_packages: no

- include_tasks: validate_installed.yml
  vars:
    ansible_python_interpreter: "{{ virtualenv_interpreter }}"
    playbook_namespace: ansible-test-k8s-validate

- file:
    path: "{{ virtualenv }}"
    state: absent
  no_log: yes

# Test new config getter (kubernetes==12.0.0)

- pip:
    name:
      - kubernetes==12.0.0
      - coverage>=5.3
    virtualenv: "{{ virtualenv }}"
    virtualenv_command: "{{ virtualenv_command }}"
    virtualenv_site_packages: no

- pip:
    name:
      - kubernetes>=12.0.0
    virtualenv: "{{ virtualenv }}"
    virtualenv_command: "{{ virtualenv_command }}"
    virtualenv_site_packages: no

- include_tasks: new_config_getter.yml
  vars:
    ansible_python_interpreter: "{{ virtualenv_interpreter }}"
    playbook_namespace: ansible-test-k8s-config-getter

- file:
    path: "{{ virtualenv }}"
    state: absent
  no_log: yes
