apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: {{ template "kube-lego.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  name: {{ template "kube-lego.fullname" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
    {{- if .Values.podAnnotations }}
      annotations:
{{ toYaml .Values.podAnnotations | indent 8 }}
    {{- end }}
      labels:
        app: {{ template "kube-lego.name" . }}
        release: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ if .Values.rbac.create }}{{ template "kube-lego.fullname" . }}{{ else }}"{{ .Values.rbac.serviceAccountName }}"{{ end }}
      containers:
        - name: {{ template "kube-lego.name" . }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: "{{ .Values.image.pullPolicy }}"
          env:
            - name: LEGO_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: LEGO_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
          {{- range $key, $value := .Values.config }}
            - name: "{{ $key }}"
              value: "{{ $value }}"
          {{- end }}
          ports:
            - containerPort: {{ .Values.config.LEGO_PORT }}
          readinessProbe:
            httpGet:
              path: /healthz
              port: {{ .Values.config.LEGO_PORT }}
            initialDelaySeconds: 5
            timeoutSeconds: 1
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
