apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "influxdb.fullname" . }}
  labels:
    app: {{ template "influxdb.fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: {{ template "influxdb.fullname" . }}
        release: "{{ .Release.Name }}"
    spec:
      containers:
      - name: {{ template "influxdb.fullname" . }}
        image: "{{ .Values.image.repo }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
        resources:
{{ toYaml .Values.resources | indent 10 }}
        ports:
        - name: api
          containerPort: {{ .Values.config.http.bind_address }}
        {{ if .Values.config.admin.enabled -}}
        - name: admin
          containerPort: {{ .Values.config.admin.bind_address }}
        {{- end }}
        {{ if .Values.config.graphite.enabled -}}
        - name: graphite
          containerPort: {{ .Values.config.graphite.bind_address }}
        {{- end }}
        {{ if .Values.config.collectd.enabled -}}
        - name: collectd
          containerPort: {{ .Values.config.collectd.bind_address }}
        {{- end }}
        {{ if .Values.config.udp.enabled -}}
        - name: udp
          containerPort: {{ .Values.config.udp.bind_address }}
        {{- end }}
        {{ if .Values.config.opentsdb.enabled -}}
        - name: opentsdb
          containerPort: {{ .Values.config.opentsdb.bind_address }}
        {{- end }}
        {{ if .Values.env }}
        env:
{{ toYaml .Values.env | indent 10 }}
        {{- end }}
        livenessProbe:
          httpGet:
            path: /ping
            port: api
          initialDelaySeconds: 30
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            path: /ping
            port: api
          initialDelaySeconds: 5
          timeoutSeconds: 1
        volumeMounts:
        - name: data
          mountPath: {{ .Values.config.storage_directory }}
        - name: config
          mountPath: /etc/influxdb
      volumes:
      - name: data
      {{- if .Values.persistence.enabled }}
        {{- if not (empty .Values.persistence.name) }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.name }}
        {{- else }}
        persistentVolumeClaim:
          claimName: {{ template "influxdb.fullname" . }}
        {{- end }}
      {{- else }}
        emptyDir: {}
      {{- end }}
      - name: config
        configMap:
          name: {{ template "influxdb.fullname" . }}
    {{- if .Values.schedulerName }}
      schedulerName: "{{ .Values.schedulerName }}"
    {{- end }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
      {{- end -}}
      {{- if .Values.affinity }}
      affinity:
{{ toYaml .Values.affinity | indent 8 }}
      {{- end }}
      {{- if .Values.tolerations }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
      {{- end }}
