apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "podinfo.fullname" . }}
  labels:
    app: {{ template "podinfo.name" . }}
    chart: {{ template "podinfo.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
  selector:
    matchLabels:
      app: {{ template "podinfo.fullname" . }}
  template:
    metadata:
      labels:
        app: {{ template "podinfo.fullname" . }}
      annotations:
        prometheus.io/scrape: 'true'
        {{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
        {{- end }}
    spec:
      terminationGracePeriodSeconds: 30
      containers:
        - name: podinfo
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - ./podinfo
            - --port={{ .Values.service.port }}
            - --level={{ .Values.logLevel }}
            - --random-delay={{ .Values.faults.delay }}
            - --random-error={{ .Values.faults.error }}
            - --config-path=/podinfo/config
            {{- range .Values.backends }}
            - --backend-url={{ . }}
            {{- end }}
          env:
          - name: PODINFO_UI_COLOR
            value: "#34577c"
          {{- if .Values.message }}
          - name: PODINFO_UI_MESSAGE
            value: {{ .Values.message }}
          {{- end }}
          {{- if .Values.backend }}
          - name: PODINFO_BACKEND_URL
            value: {{ .Values.backend }}
          {{- end }}
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          livenessProbe:
            exec:
              command:
              - podcli
              - check
              - http
              - localhost:{{ .Values.service.port }}/healthz
            initialDelaySeconds: 5
            timeoutSeconds: 5
          readinessProbe:
            exec:
              command:
              - podcli
              - check
              - http
              - localhost:{{ .Values.service.port }}/readyz
            initialDelaySeconds: 5
            timeoutSeconds: 5
          volumeMounts:
          - name: data
            mountPath: /data
          - name: config
            mountPath: /podinfo/config
            readOnly: true
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
      volumes:
      - name: data
        emptyDir: {}
      - name: config
        configMap:
          name: {{ template "podinfo.fullname" . }}
