apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: {{ template "cert-manager.fullname" . }}
  namespace: {{ .Release.Namespace | quote }}
  labels:
    app: {{ template "cert-manager.name" . }}
    chart: {{ template "cert-manager.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "cert-manager.name" . }}
      release: {{ .Release.Name }}
  {{- with .Values.strategy }}
  strategy:
    {{- . | toYaml | nindent 4 }}
  {{- end }}
  template:
    metadata:
      labels:
        app: {{ template "cert-manager.name" . }}
        release: {{ .Release.Name }}
{{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | indent 8 }}
{{- end }}
      annotations:
      {{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
      {{- end }}
    spec:
      serviceAccountName: {{ template "cert-manager.serviceAccountName" . }}
      {{- if .Values.global.priorityClassName }}
      priorityClassName: {{ .Values.global.priorityClassName | quote }}
      {{- end }}
      {{- if .Values.securityContext.enabled }}
      securityContext:
        fsGroup: {{ .Values.securityContext.fsGroup }}
        runAsUser: {{ .Values.securityContext.runAsUser }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
        {{- if .Values.clusterResourceNamespace }}
          - --cluster-resource-namespace={{ .Values.clusterResourceNamespace }}
        {{- else }}
          - --cluster-resource-namespace=$(POD_NAMESPACE)
        {{- end }}
        {{- if .Values.leaderElection.namespace }}
          - --leader-election-namespace={{ .Values.leaderElection.namespace }}
        {{- else }}
          - --leader-election-namespace=$(POD_NAMESPACE)
        {{- end }}
        {{- if .Values.extraArgs }}
{{ toYaml .Values.extraArgs | indent 10 }}
        {{- end }}
          {{- with .Values.ingressShim }}
          {{- if .defaultIssuerName }}
          - --default-issuer-name={{ .defaultIssuerName }}
          {{- end }}
          {{- if .defaultIssuerKind }}
          - --default-issuer-kind={{ .defaultIssuerKind }}
          {{- end }}
          {{- if .defaultACMEChallengeType }}
          - --default-acme-issuer-challenge-type={{ .defaultACMEChallengeType }}
          {{- end }}
          {{- if .defaultACMEDNS01ChallengeProvider }}
          - --default-acme-issuer-dns01-provider-name={{ .defaultACMEDNS01ChallengeProvider }}
          {{- end }}
          {{- end }}
          env:
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        {{- if .Values.extraEnv }}
{{ toYaml .Values.extraEnv | indent 10 }}
        {{- end }}
          {{- if .Values.http_proxy }}
          - name: HTTP_PROXY
            value: {{ .Values.http_proxy }}
          {{- end }}
          {{- if .Values.https_proxy }}
          - name: HTTPS_PROXY
            value: {{ .Values.https_proxy }}
          {{- end }}
          {{- if .Values.no_proxy }}
          - name: NO_PROXY
            value: {{ .Values.no_proxy }}
          {{- end }}
          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 }}
{{- if .Values.podDnsPolicy }}
      dnsPolicy: {{ .Values.podDnsPolicy }}
{{- end }}
{{- if .Values.podDnsConfig }}
      dnsConfig:
{{ toYaml .Values.podDnsConfig | indent 8 }}
{{- end }}
