
{%- if taskserv.hostname == "$hostname" and server.hostname -%}
{% set hostname=server.hostname %}
{%- else -%}
{% set hostname=taskserv.hostname %}
{%- endif -%}
# Main Ip for node should be in same K8S_MASTER network
# Be sure main_ip is alive and reachable 
{%- if taskserv.ip == "$network_private_ip" and server.network_private_ip -%}
{% set main_ip=server.network_private_ip %}
{%- elif taskserv.ip == "$network_public_ip" and server.ip_addresses.pub -%}
{% set main_ip=server.ip_addresses.pub %}
{%- else -%}
{% set main_ip=taskserv.ip  %}
{%- endif %}
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: {{main_ip}}
  bindPort: {{taskserv.bind_port}}
nodeRegistration:
#  criSocket: taskserv.cri_socket
  imagePullPolicy: {{taskserv.pull_policy}}
  name: {{hostname}}
  {% if taskserv.taints_effect != "" -%}
  taints:
  - effect: {{taskserv.taints_effect}}
    key: node-role.kubernetes.io/master
{%- endif %}
---
apiServer:
  certSANs: {% for ip in taskserv.cert_sans %}
  - {{ ip | replace(from="$cluster_name",to=taskserv.cluster_name) | replace(from="$hostname",to=hostname) }}
  {%- endfor %}
  extraArgs:
    authorization-mode: {{taskserv.auth_mode}}
    {% if taskserv.etcd_prefix != "" %}etcd-prefix: {{taskserv.etcd_prefix | replace(from="$cluster_name",to=taskserv.cluster_name)}} {% endif %}
  timeoutForControlPlane: {{taskserv.timeout_cp}}
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: {{taskserv.certs_dir}}
clusterName: {{taskserv.cluster_name}}
controlPlaneEndpoint: {{main_ip}}:{{taskserv.bind_port}}
controllerManager: {}
dns: {}
{% if taskserv.etcd_mode == "external" -%} 
etcd:
  external:
    caFile: {{taskserv.etcd_ca_path}}
    certFile: {{taskserv.etcd_cert_path}}
    keyFile: {{taskserv.etcd_key_path}}
    endpoints: {% for endpoint in taskserv.etcd_endpoints %}
    {% if endpoint.addr -%}
    - {{endpoint.prot}}://{{endpoint.addr}}:{{endpoint.port}}
    {%- elif endpoint.name -%}
    - {{endpoint.prot}}://{{endpoint.name}}:{{endpoint.port}}
    {%- endif %}
  {%- endfor -%}
{%- endif %}
imageRepository: {{taskserv.repo}}
kind: ClusterConfiguration
kubernetesVersion: {{taskserv.version}}
networking:
  dnsDomain: {{taskserv.dns_domain}}
  podSubnet: {{taskserv.pod_net}}
  serviceSubnet: {{taskserv.service_net}}
scheduler: {}
