apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "fullname" . }}
  labels:
    app: {{ template "fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: {{ template "fullname" . }}
    spec:
      containers:
      - name: {{ template "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 }}
        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 }}
        persistentVolumeClaim:
          claimName: {{ template "fullname" . }}
      {{- else }}
        emptyDir: {}
      {{- end }}
      - name: config
        configMap:
          name: {{ template "fullname" . }}
