apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: {{ template "aws-iam-authenticator.fullname" . }}
  labels:
    app: {{ template "aws-iam-authenticator.name" . }}
    chart: {{ template "aws-iam-authenticator.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ""
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
      labels:
        app: {{ template "aws-iam-authenticator.name" . }}
        release: {{ .Release.Name }}
    spec:
      # run on the host network (don't depend on CNI)
      hostNetwork: true

      # run on each master node
      nodeSelector:
        node-role.kubernetes.io/master: ""
      tolerations:
      - effect: NoSchedule
        key: node-role.kubernetes.io/master
      - key: CriticalAddonsOnly
        operator: Exists

      # run `aws-iam-authenticator server` with three volumes
      # - config (mounted from the ConfigMap at /etc/aws-iam-authenticator/config.yaml)
      # - state (persisted TLS certificate and keys, mounted from the host)
      # - output (output kubeconfig to plug into your apiserver configuration, mounted from the host)
      containers:
      - name: {{ template "aws-iam-authenticator.fullname" . }}
        image: gcr.io/heptio-images/authenticator:v0.1.0
        args:
        - server
        - --config=/etc/aws-iam-authenticator/config.yaml
        - --state-dir=/var/aws-iam-authenticator
        - --generate-kubeconfig=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml

        resources:
{{ toYaml .Values.resources | indent 10 }}

        volumeMounts:
        - name: config
          mountPath: /etc/aws-iam-authenticator/
        - name: state
          mountPath: /var/aws-iam-authenticator/
        - name: output
          mountPath: /etc/kubernetes/aws-iam-authenticator/

      volumes:
      - name: config
        configMap:
          name: {{ template "aws-iam-authenticator.fullname" . }}
      - name: output
        hostPath:
          path: {{ .Values.hostPathConfig.output }}
      - name: state
        hostPath:
          path: {{ .Values.hostPathConfig.state }}
