{% set daemon_args = "$DAEMON_ARGS" -%}
{% if grains['os_family'] == 'RedHat' -%}
	{% set daemon_args = "" -%}
{% endif -%}

{% set master="--master=127.0.0.1:8080" -%}

{% set machines = ""-%}
{% set cluster_name = "" -%}
{% set minion_regexp = "--minion_regexp=.*" -%}
{% set sync_nodes = "--sync_nodes=true" -%}

{% if pillar['node_instance_prefix'] is defined -%}
  {% set minion_regexp = "--minion_regexp='" + pillar['node_instance_prefix'] + ".*'" -%}
{% endif -%}
{% if pillar['instance_prefix'] is defined -%}
  {% set cluster_name = "--cluster_name=" + pillar['instance_prefix'] -%}
{% endif -%}

{% set cloud_provider = "" -%}
{% set cloud_config = "" -%}

{% if grains.cloud is defined -%}
{% set cloud_provider = "--cloud_provider=" + grains.cloud -%}

{% if grains.cloud == 'gce' -%}
  {% if grains.cloud_config is defined -%}
    {% set cloud_config = "--cloud_config=" + grains.cloud_config -%}
  {% endif -%}

{% elif grains.cloud == 'aws' -%}
  {% if grains.cloud_config is defined -%}
    {% set cloud_config = "--cloud_config=" + grains.cloud_config -%}
  {% endif -%}
  {% set machines = "--machines=" + ','.join(salt['mine.get']('roles:kubernetes-pool', 'network.ip_addrs', expr_form='grain').keys()) -%}

{% elif grains.cloud == 'azure' -%}
  MACHINES="{{ salt['mine.get']('roles:kubernetes-pool', 'grains.items', expr_form='grain').values()|join(',', attribute='hostnamef') }}"
  {% set machines = "--machines=$MACHINES" -%}

{% elif grains.cloud == 'vsphere' -%}
  # Collect IPs of minions as machines list.
  #
  # Use a bash array to build the value we need. Jinja 2.7 does support a 'map'
  # filter that would simplify this.  However, some installations (specifically
  # Debian Wheezy) only install Jinja 2.6.
  MACHINE_IPS=()
  {% for addrs in salt['mine.get']('roles:kubernetes-pool', 'network.ip_addrs', expr_form='grain').values() -%}
  MACHINE_IPS+=( {{ addrs[0] }} )
  {% endfor -%}
  {% set machines = "--machines=$(echo ${MACHINE_IPS[@]} | xargs -n1 echo | paste -sd,)" -%}
  {% set minion_regexp = "" -%}

{% endif -%} # grains.cloud switch

{% endif -%} # grains.cloud is defined

DAEMON_ARGS="{{daemon_args}} {{master}} {{machines}} {{cluster_name}} {{ minion_regexp }} {{ cloud_provider }} {{ sync_nodes }} {{ cloud_config }} {{pillar['log_level']}}"
