{{- if .Values.notary.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "harbor.notary-signer" . }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
    app.kubernetes.io/component: notary-signer
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  replicas: {{ .Values.notary.signer.replicaCount }}
  selector:
    matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
      app.kubernetes.io/component: notary-signer
  {{- if .Values.notary.signer.updateStrategy }}
  strategy: {{- toYaml .Values.notary.signer.updateStrategy | nindent 4 }}
  {{- end }}
  template:
    metadata:
      labels: {{- include "common.labels.standard" . | nindent 8 }}
        {{- if .Values.commonLabels }}
        {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 8 }}
        {{- end }}
        {{- if .Values.notary.signer.podLabels }}
        {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.podLabels "context" $) | nindent 8 }}
        {{- end }}
        app.kubernetes.io/component: notary-signer
      annotations:
        checksum/secret: {{ include (print $.Template.BasePath "/notary/notary-secret.yaml") . | sha256sum }}
        {{- if .Values.notary.signer.podAnnotations }}
        annotations: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.podAnnotations "context" $) | nindent 8 }}
        {{- end }}
    spec:
      {{- include "harbor.imagePullSecrets" . | nindent 6 }}
      automountServiceAccountToken: {{ .Values.notary.signer.automountServiceAccountToken }}
      {{- if .Values.notary.signer.hostAliases }}
      hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.hostAliases "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.notary.signer.affinity }}
      affinity: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.affinity "context" $) | nindent 8 }}
      {{- else }}
      affinity:
        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.notary.signer.podAffinityPreset "component" "notary-signer" "context" $) | nindent 10 }}
        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.notary.signer.podAntiAffinityPreset "component" "notary-signer" "context" $) | nindent 10 }}
        nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.notary.signer.nodeAffinityPreset.type "key" .Values.notary.signer.nodeAffinityPreset.key "values" .Values.notary.signer.nodeAffinityPreset.values) | nindent 10 }}
      {{- end }}
      {{- if .Values.notary.signer.nodeSelector }}
      nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.notary.signer.tolerations }}
      tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.notary.signer.topologySpreadConstraints }}
      topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.topologySpreadConstraints "context" .) | nindent 8 }}
      {{- end }}
      {{- if .Values.notary.signer.priorityClassName }}
      priorityClassName: {{ .Values.notary.signer.priorityClassName | quote }}
      {{- end }}
      {{- if .Values.notary.signer.schedulerName }}
      schedulerName: {{ .Values.notary.signer.schedulerName }}
      {{- end }}
      {{- if .Values.notary.signer.podSecurityContext.enabled }}
      securityContext: {{- omit .Values.notary.signer.podSecurityContext "enabled" | toYaml | nindent 8 }}
      {{- end }}
      {{- if .Values.notary.signer.initContainers }}
      initContainers: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.initContainers "context" $) | nindent 8 }}
      {{- end }}
      containers:
        - name: notary-signer
          image: {{ include "harbor.notary.signer.image" . }}
          imagePullPolicy: {{ .Values.notary.signer.image.pullPolicy | quote }}
          {{- if .Values.notary.signer.containerSecurityContext.enabled }}
          securityContext: {{- omit .Values.notary.signer.containerSecurityContext "enabled" | toYaml | nindent 12 }}
          {{- end }}
          {{- if .Values.diagnosticMode.enabled }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
          {{- else if .Values.notary.signer.command }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.command "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.diagnosticMode.enabled }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
          {{- else if .Values.notary.signer.args }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.args "context" $) | nindent 12 }}
          {{- end }}
          env:
            - name: BITNAMI_DEBUG
              value: {{ ternary "true" "false" .Values.notary.signer.image.debug | quote }}
            - name: MIGRATIONS_PATH
              value: migrations/signer/postgresql
            - name: DB_URL
              valueFrom:
                secretKeyRef:
                  name: {{ printf "%s-envvars" (include "harbor.notary-server" .) }}
                  key: signer_db_url
            - name: NOTARY_SIGNER_DEFAULTALIAS
              value: defaultalias
            {{- if .Values.notary.signer.extraEnvVars }}
            {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.extraEnvVars "context" $) | nindent 12 }}
            {{- end }}
          envFrom:
            {{- if .Values.notary.signer.extraEnvVarsCM }}
            - configMapRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.notary.signer.extraEnvVarsCM "context" $) }}
            {{- end }}
            {{- if .Values.notary.signer.extraEnvVarsSecret }}
            - secretRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.notary.signer.extraEnvVarsSecret "context" $) }}
            {{- end }}
          ports:
            - containerPort: {{ .Values.notary.signer.containerPorts.signer }}
              name: notary-signer
          {{- if not .Values.diagnosticMode.enabled }}
          {{- if .Values.notary.signer.startupProbe.enabled }}
          startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.notary.signer.startupProbe "enabled") "context" $) | nindent 12 }}
            tcpSocket:
              port: notary-signer
          {{- else if .Values.notary.signer.customStartupProbe }}
          startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.customStartupProbe "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.notary.signer.livenessProbe.enabled }}
          livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.notary.signer.livenessProbe "enabled") "context" $) | nindent 12 }}
            tcpSocket:
              port: notary-signer
          {{- else if .Values.notary.signer.customLivenessProbe }}
          livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.customLivenessProbe "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.notary.signer.readinessProbe.enabled }}
          readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.notary.signer.readinessProbe "enabled") "context" $) | nindent 12 }}
            tcpSocket:
              port: notary-signer
          {{- else if .Values.notary.signer.customReadinessProbe }}
          readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.customReadinessProbe "context" $) | nindent 12 }}
          {{- end }}
          {{- end }}
          {{- if .Values.notary.signer.lifecycleHooks }}
          lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.lifecycleHooks "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.notary.signer.resources }}
          resources: {{- toYaml .Values.notary.signer.resources | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: notary-config
              mountPath: /etc/notary
            {{- if .Values.notary.secretName }}
            - name: notary-cert
              mountPath: /etc/ssl/notary/cert/notary-signer-ca.crt
              subPath: notary-signer-ca.crt
            - name: notary-cert
              mountPath: /etc/ssl/notary/cert/notary-signer.crt
              subPath: notary-signer.crt
            - name: notary-cert
              mountPath: /etc/ssl/notary/cert/notary-signer.key
              subPath: notary-signer.key
            {{- end }}
            {{- if .Values.notary.signer.extraVolumeMounts }}
            {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.extraVolumeMounts "context" $) | nindent 12 }}
            {{- end }}
        {{- if .Values.notary.signer.sidecars }}
        {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.sidecars "context" $) | nindent 8 }}
        {{- end }}
      volumes:
        - name: notary-config
          secret:
            secretName: {{ include "harbor.notary-server" . }}
        {{- if .Values.notary.secretName }}
        - name: notary-cert
          secret:
            secretName: {{ .Values.notary.secretName }}
        {{- end }}
      {{- if .Values.notary.signer.extraVolumes }}
      {{- include "common.tplvalues.render" (dict "value" .Values.notary.signer.extraVolumes "context" $) | nindent 8 }}
      {{- end }}
{{- end }}
