---
- name: Ensuring fabric directory exists
  shell: >
    mkdir -p {{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric
  ignore_errors: yes

- name: Generate canal deployment file
  template: src=canal.yaml.part.jinja2
            dest="{{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric/canal.yaml"

- name: Generate canal configuration file
  template: src=config.yaml.part.jinja2
            dest="{{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric/config.yaml"

- name: Wait for api server to become available in case it's not
  wait_for:
    host: "{{ item|regex_replace('https://','') }}"
    port: 443
    timeout: 600
  with_items: "{{ api_servers }}"

- name: Ensure the kube-networking namespace exists
  command: >
    kubectl --kubeconfig={{ kubeconfig | expanduser }} create namespace kube-networking
  retries: 120
  delay: 1

- name: Deploy canal configuration
  command: >
    kubectl --kubeconfig={{ kubeconfig | expanduser }} apply -f {{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric/config.yaml

- name: Deploy canal daemonset
  command: >
    kubectl --kubeconfig={{ kubeconfig | expanduser }} apply -f {{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric/canal.yaml

---
- name: Ensuring fabric directory exists
  shell: >
    mkdir -p {{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric
  ignore_errors: yes

- name: Generate canal deployment file
  template: src=canal.yaml.part.jinja2
            dest="{{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric/canal.yaml"

- name: Generate canal configuration file
  template: src=config.yaml.part.jinja2
            dest="{{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric/config.yaml"

- name: Wait for api server to become available in case it's not
  wait_for:
    host: "{{ item|regex_replace('https://','') }}"
    port: 443
    timeout: 600
  with_items: "{{ api_servers }}"

- name: check kube-networking namespace state
  command: >  
    kubectl --kubeconfig={{ kubeconfig | expanduser }} get namespace kube-networking
  ignore_errors: yes
  changed_when: false
  register: kube_networking_namespace

- name: Ensure the kube-networking namespace exists
  command: >
    kubectl --kubeconfig={{ kubeconfig | expanduser }} create namespace kube-networking
  retries: 120
  delay: 1
  when: not kube_networking_namespace.rc == 0

- name: Deploy canal configuration
  command: >
    kubectl --kubeconfig={{ kubeconfig | expanduser }} apply -f {{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric/config.yaml

- name: Deploy canal daemonset
  command: >
    kubectl --kubeconfig={{ kubeconfig | expanduser }} apply -f {{ config_base | expanduser }}/{{kraken_config.cluster}}/fabric/canal.yaml

Check if the kube-networking namespace exists
Check if the kube-networking namespace exists

On a second "up" run, `Ensure the kube-networking namespace exists`
failed with:
> "Error from server: namespaces \"kube-networking\" already exists", "stdout"

This checks to see if the namespace has already been created and skips
creation if it does.
