---
- name: Helm | Ensure the Calico binary is available
  when: 
    - .cni.calico_version | empty | not
    - .cni.type | eq "calico"
  command: |
    artifact_name={{ .download.artifact_url.calico | splitList "/" | last }}
    artifact_path={{ .binary_dir }}/cni/calico
    if [ ! -f $artifact_path/$artifact_name ]; then
      mkdir -p $artifact_path
      # Download the Calico binary if it does not exist
      curl -Lo $artifact_path/$artifact_name {{ .download.artifact_url.calico }}
    fi

- name: Helm | Ensure the Cilium binary is available
  when: 
    - .cni.cilium_version | empty | not
    - .cni.type | eq "cilium"
  command: |
    artifact_name={{ .download.artifact_url.cilium | splitList "/" | last }}
    artifact_path={{ .binary_dir }}/cni/cilium
    if [ ! -f $artifact_path/$artifact_name ]; then
      mkdir -p $artifact_path
      # Download the Cilium binary if it does not exist
      curl -Lo $artifact_path/$artifact_name {{ .download.artifact_url.cilium }}
    fi

- name: Helm | Ensure the Flannel binary is available
  when: 
    - .cni.flannel_version | empty | not
    - .cni.type | eq "flannel"
  command: |
    artifact_name={{ .download.artifact_url.flannel | splitList "/" | last }}
    artifact_path={{ .binary_dir }}/cni/flannel
    if [ ! -f $artifact_path/$artifact_name ]; then
      mkdir -p $artifact_path
      # Download the Flannel binary if it does not exist
      curl -Lo $artifact_path/$artifact_name {{ .download.artifact_url.flannel }}
    fi

- name: Helm | Ensure the Kube-OVN binary is available
  when: 
    - .kubeovn_version | empty | not
    - .cni.type | eq "kubeovn"
  command: |
    artifact_name={{ .download.artifact_url.kubeovn | splitList "/" | last }}
    artifact_path={{ .binary_dir }}/cni/kubeovn
    if [ ! -f $artifact_path/$artifact_name ]; then
      mkdir -p $artifact_path
      # Download the Kube-OVN binary if it does not exist
      curl -Lo $artifact_path/$artifact_name {{ .download.artifact_url.kubeovn }}
    fi

- name: Helm | Ensure the Hybridnet binary is available
  when: 
    - .cni.hybridnet_version | empty | not
    - .cni.type | eq "hybridnet"
  command: |
    artifact_name={{ .download.artifact_url.hybridnet | splitList "/" | last }}
    artifact_path={{ .binary_dir }}/cni/hybridnet
    if [ ! -f $artifact_path/$artifact_name ]; then
      mkdir -p $artifact_path
      # Download the Hybridnet binary if it does not exist
      curl -Lo $artifact_path/$artifact_name {{ .download.artifact_url.hybridnet }}
    fi

- name: Helm | Ensure the NFS Provisioner binary is available
  when: 
    - .storage_class.nfs_provisioner_version | empty | not
    - .storage_class.nfs.enabled
  command: |
    artifact_name={{ .download.artifact_url.nfs_provisioner | splitList "/" | last }}
    artifact_path={{ .binary_dir }}/sc
    if [ ! -f $artifact_path/$artifact_name ]; then
      mkdir -p $artifact_path
      # Download the NFS Provisioner binary if it does not exist
      curl -Lo $artifact_path/$artifact_name {{ .download.artifact_url.nfs_provisioner }}
    fi
