heat_template_version: 2014-10-16

description: >
  This is a nested stack that defines a single Kubernetes minion, This stack is
  included by an AutoScalingGroup resource in the parent template
  (kubecluster.yaml).

parameters:

  name:
    type: string
    description: server name

  server_image:
    type: string
    description: glance image used to boot the server

  minion_flavor:
    type: string
    description: flavor to use when booting the server

  ssh_key_name:
    type: string
    description: name of ssh key to be provisioned on our server

  external_network:
    type: string
    description: uuid/name of a network to use for floating ip addresses

  fixed_network:
    type: string
    description: Network from which to allocate fixed addresses.

  fixed_subnet:
    type: string
    description: Subnet from which to allocate fixed addresses.

  secgroup_kube_minion_id:
    type: string
    description: ID of the security group for kubernetes minion.

  flannel_network_cidr:
    type: string
    description: network range for flannel overlay network

  kube_software_configs:
    type: string
    description : >
      ID of the multipart mime.

  nodes_server_group_id:
    type: string
    description: ID of the server group for kubernetes cluster nodes.

resources:

  ######################################################################
  #
  # a single kubernetes minion.
  #

  # do NOT use "_" (underscore) in the Nova server name
  # it creates a mismatch between the generated Nova name and its hostname
  # which can lead to weird problems
  kube-minion:
    type: OS::Nova::Server
    properties:
      name: {get_param: name}
      image: {get_param: server_image}
      flavor: {get_param: minion_flavor}
      key_name: {get_param: ssh_key_name}
      user_data_format: RAW
      user_data: {get_param: kube_software_configs}
      networks:
        - port: {get_resource: kube_minion_eth0}
      scheduler_hints: { group: { get_param: nodes_server_group_id }}

  kube_minion_eth0:
    type: "OS::Neutron::Port"
    properties:
      network_id:
        get_param: fixed_network
      security_groups:
        - {get_param: secgroup_kube_minion_id}
      fixed_ips:
        - subnet_id:
            get_param: fixed_subnet
      allowed_address_pairs:
        - ip_address: {get_param: flannel_network_cidr}

  kube_minion_floating:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network:
        get_param: external_network
      port_id:
        get_resource: kube_minion_eth0

outputs:

  kube_minion_ip:
    value: {get_attr: [kube_minion_eth0, fixed_ips, 0, ip_address]}
    description: >
      This is the "public" IP address of the Kubernetes minion node.

  kube_minion_external_ip:
    value: {get_attr: [kube_minion_floating, floating_ip_address]}
    description: >
      This is the "public" IP address of the Kubernetes minion node.

  OS::stack_id:
    value: {get_param: "OS::stack_id"}
    description: >
      This is a id of the stack which creates from this template.
