---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: {{ template "kubewatch.name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
  name: {{ template "kubewatch.fullname" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      annotations:
        checksum/config-map: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
      {{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
      {{- end }}
      labels:
        app: {{ template "kubewatch.name" . }}
        release: "{{ .Release.Name }}"
      {{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | indent 8 }}
      {{- end }}
    spec:
      containers:
      - name: {{ template "kubewatch.name" . }}
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        volumeMounts:
        - name: {{ template "kubewatch.name" . }}-config-map
          mountPath: /root
        resources:
{{ toYaml .Values.resources | indent 10 }}
    {{- if .Values.affinity }}
      affinity:
{{ toYaml .Values.affinity | indent 8 }}
    {{- end }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
      serviceAccountName: {{ if .Values.rbac.create }}{{ template "kubewatch.fullname" . }}{{ else }}"{{ .Values.rbac.serviceAccountName }}"{{ end }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
      restartPolicy: Always
      volumes:
      - name: {{ template "kubewatch.name" . }}-config-map
        configMap:
          name: {{ template "kubewatch.fullname" . }}-config

