{{- if eq .Values.registry.external false -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "docker-registry.fullname" . }}
  labels:
{{ include "docker-registry.labels" . | indent 4 }}
spec:
  replicas: {{ .Values.registry.replicaCount }}
  selector:
    matchLabels:
{{ include "docker-registry.matchLabels" . | indent 6 }}
  template:
    metadata:
      labels:
{{ include "docker-registry.matchLabels" . | indent 8 }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      volumes:
        - name: config
          configMap:
            defaultMode: 420
            name: {{ include "docker-registry.fullname" . }}
        - name: data
{{- if .Values.registry.persistence.enabled }}
          persistentVolumeClaim:
            claimName: {{ include "docker-registry.fullname" . }}
{{- else }}
          emptyDir: {}
{{- end }}
      containers:
        - name: registry
          image: "{{ .Values.registry.image.registry }}/{{ .Values.registry.image.repository }}:{{ .Values.registry.image.tag }}"
          imagePullPolicy: {{ .Values.registry.image.pullPolicy }}
          ports:
            - name: registry
              containerPort: 5000
              protocol: TCP
          volumeMounts:
            - mountPath: "/var/lib/registry"
              name: "data"
            - mountPath: "/etc/docker/registry"
              name: "config"
{{ include "docker-registry.probes" . | indent 10 }}
          resources:
            {{- toYaml .Values.registry.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
{{- end -}}
