#cloud-config
write_files:
  - path: /etc/systemd/system/enable-kube-proxy.service
    owner: "root:root"
    permissions: "0644"
    content: |
      [Unit]
      Description=Configure Kubernetes Proxy

      [Service]
      Type=oneshot
      ExecStart=/etc/sysconfig/enable-kube-proxy-master.sh

      [Install]
      WantedBy=multi-user.target

  - path: /etc/sysconfig/enable-kube-proxy-master.sh
    owner: "root:root"
    permissions: "0755"
    content: |
      #!/bin/sh

      . /etc/sysconfig/heat-params
      myip=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)


      HOST_CERTS_PATH=/usr/share/ca-certificates

      TEMPLATE=/etc/kubernetes/manifests/kube-proxy.yaml
      mkdir -p $(dirname ${TEMPLATE})
      cat > ${TEMPLATE} <<EOF
      apiVersion: v1
      kind: Pod
      metadata:
        name: kube-proxy
        namespace: kube-system
      spec:
        hostNetwork: true
        containers:
        - name: kube-proxy
          image: gcr.io/google_containers/hyperkube:${KUBE_VERSION}
          command:
          - /hyperkube
          - proxy
          - --master=http://127.0.0.1:8080
          - --logtostderr=true
          - --v=0
          securityContext:
            privileged: true
      EOF
