{%- if taskserv.name == "kubernetes" %} 
# CLuster Name
CLUSTER_NAME="{{taskserv.cluster_name}}"

# K8s cluster role: controlpnlane or worker
MODE="{{taskserv.mode}}"

# If HOSTNAME == K8S_MASTER it will be MASTER_0 
# othewise set HOSTNAME value to be resolved in same K8S_MASTER network
# By using -cp- as part of HOSTNAME will be consider node as controlpanel 
# Other options: -wk-0  or -wkr-0 for worker nodes 
{% if taskserv.hostname == "$hostname" and server.hostname %}
HOSTNAME="{{server.hostname}}"
{%- else %}
HOSTNAME="{{taskserv.hostname}}"
{%- endif %}
K8S_MASTER_IP="{{taskserv.cp_ip}}"
{%- if taskserv.cp_name == "$hostname" and server.hostname %}
K8S_MASTER="{{server.hostname}}"
{%- else %}
K8S_MASTER="{{taskserv.cp_name}}"
{%- 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 %}
MAIN_IP="{{server.network_private_ip}}"
{% elif taskserv.ip == "$network_public_ip" and settings[server_pos].ip_addresses.pub %}
MAIN_IP="{{settings[server_pos].ip_addresses.pub}}"
{%- else %}
MAIN_IP="{{taskserv.ip}}"
{%- endif %}

# LOG path for kubeadm
export INSTALL_LOG="{{taskserv.install_log_path | replace(from="$cluster_name",to=taskserv.cluster_name)}}"
# Work path for config generated file
export WORK_PATH="{{ taskserv.work_path | replace(from="$cluster_name",to=taskserv.cluster_name) }}"

# Kubernetes URL for releases download
#URL="https://github.com/kubernetes/kubernetes/releases"
#FILE="."

# kubernetes version 
VERSION="{{taskserv.version}}"
export MAJOR_VERSION="{{taskserv.major_version}}"
K8S_VERSION=v$VERSION

# Default Arch 
OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')"

# Kubernetes CRI
K8S_CRI="{{taskserv.cri}}"

# Kubernetes CNI
{% if taskserv.cni -%} 
K8S_CNI="{{taskserv.cni}}"
{% if taskserv.cni == "cilium" %} 
 {% if taskserv.cni_version %}
    export CILIUM_CLI_VERSION="{{taskserv.cni_version}}"
 {%- else %}
    export CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt)
 {%- endif %}
{%- endif %} 
{%- endif %} 

# Kubernetes ADDONS
{% if taskserv.addons -%} 
K8S_ADDONS="{{taskserv.addons}}"
K8S_EXTERNAL_IPS="{%- for ip in taskserv.external_ips -%} 
{%- if ip == "$pub_ip" and settings[server_pos] and settings[server_pos].ip_addresses.pub -%} 
{{settings[server_pos].ip_addresses.pub}},
{%- else -%}
{{ip}},
{%- endif -%}{%- endfor -%}"
{%- endif %}

# ETCD mode could be used for multi-master  
{% if taskserv.etcd_mode == "external" %}
ETCD_MODE="{{taskserv.etcd_mode}}"

{% endif %}

# Defaul CMD_TSK, can be set as argument in kubernetes/install.sh
CMD_TSK=${1:-install}

# Set taint mode for controlpanels TAINT_NODE=no_schedule
{% if taskserv.taint_node %} TAINT_NODE=schedule{% endif %}

# OS systemctl mode for CRI and kubelet services
SYSTEMCTL_MODE=enabled

# Template file name for kubeadm config 
K8S_TPL="{{taskserv.tpl}}"
K8S_CONFIG=${K8S_TPL//.j2/}

# Dev Adm user
USER="{{taskserv.admin_user}}"
USER_HOME="/home/{{taskserv.admin_user}}"

CMD_TSK="{{taskserv.cmd_task}}"
{% set target_taskserv = server.taskservs | filter(attribute="name", value=taskserv.name) | first %}
TARGET_SAVE_PATH="{{target_taskserv.target_save_path | default(value = "")}}"
{%- endif %}
