---
- name: Add kubeovn label to node
  command: |
    kubectl label node -lbeta.kubernetes.io/os=linux kubernetes.io/os=linux --overwrite
    kubectl label node -lnode-role.kubernetes.io/control-plane kube-ovn/role=master --overwrite

# kubeovn-0.1.0.tgz is helm version not helm appVersion
- name: Sync kubeovn helm chart to remote
  copy:
    src: |
      {{ .work_dir }}/kubekey/cni/kubeovn-{{ .kubeovn_version }}.tgz
    dest: |
      /etc/kubernetes/cni/kubeovn-{{ .kubeovn_version }}.tgz

# https://kubeovn.github.io/docs/stable/start/one-step-install/#helm-chart
- name: Install kubeovn
  command: |
    helm install kubeovn /etc/kubernetes/cni/kubeovn-{{ .kubeovn_version }}.tgz --set replicaCount={{ .cni.kubeovn.replica }} \
    {{- $ips := list }}
    {{- range .groups.kube_control_plane | default list }}
        {{- $ips = append $ips (index $.inventory_hosts . "internal_ipv4") }}
    {{- end }}
      --set MASTER_NODES={{ $ips | join "," }} \
      --set global.registry.address={{ .cni.kubeovn.registry }} \
      --set ipv4.POD_CIDR={{ .cni.kubeovn.kube_pods_v4_cidr }} --set ipv4.SVC_CIDR={{ .cni.kubeovn.kube_svc_cidr }} \
    {{- if .cni.ipv6_support }}
      --set networking.NET_STACK=dual_stack \
      --set dual_stack.POD_CIDR={{ .cni.kubeovn.kube_pods_v4_cidr }},{{ .cni.kubeovn.kube_pods_v6_cidr }} \
      --set dual_stack.SVC_CIDR={{ .cni.kubeovn.kube_svc_cidr }} \
    {{- end }}
