apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "uptimerobot.fullname" . }}
  labels:
    app: {{ template "uptimerobot.name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  selector:
    matchLabels:
      app: {{ template "uptimerobot.name" . }}
      release: {{ .Release.Name }}
  replicas: {{ default 1 .Values.replicas }}
  revisionHistoryLimit: 3
  template:
    metadata:
      labels:
        app: {{ template "uptimerobot.name" . }}
        release: {{ .Release.Name }}
      {{- if .Values.podAnnotations }}
      annotations:
        {{- range $key, $value := .Values.podAnnotations }}
        {{ $key }}: {{ $value | quote }}
        {{- end }}
      {{- end }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
            - name: UPTIMEROBOT_API_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ template "uptimerobot.fullname" . }}
                  key: uptimerobot-apikey
            {{- if .Values.config.influxdb.username }}
            - name: INFLUX_USERNAME
              valueFrom:
                secretKeyRef:
                  name: {{ template "uptimerobot.fullname" . }}
                  key: influxdb-username
            {{- end }}
            {{- if .Values.config.influxdb.password }}
            - name: INFLUX_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ template "uptimerobot.fullname" . }}
                  key: influxdb-password
            {{- end }}
            - name: APPLICATION_INTERVAL
              value: "{{ .Values.delay }}"
            {{- if .Values.config.uptimerobot.logs_limit }}
            - name: UPTIMEROBOT_LOGS_LIMIT
              value: "{{ .Values.config.uptimerobot.logs_limit }}"
            {{- end }}
            {{- if .Values.config.uptimerobot.response_times_limit }}
            - name: UPTIMEROBOT_RESPONSE_TIMES_LIMIT
              value: "{{ .Values.config.uptimerobot.response_times_limit }}"
            {{- end }}
            - name: INFLUX_HOST
              value: "{{ .Values.config.influxdb.host }}"
            - name: INFLUX_PORT
              value: "{{ .Values.config.influxdb.port }}"
            - name: INFLUX_PROTOCOL
              value: "{{ .Values.config.influxdb.protocol }}"
            - name: INFLUX_DATABASE
              value: "{{ .Values.config.influxdb.database }}"
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
