apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ template "verdaccio.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  name: {{ template "verdaccio.fullname" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "verdaccio.name" . }}
      release: {{ .Release.Name }}
  strategy:
    {{- if .Values.persistence.enabled }}
    type: Recreate
    rollingUpdate: null
    {{- else }}
    type: RollingUpdate
    {{- end }}
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
    {{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
    {{- end }}
      labels:
        app: {{ template "verdaccio.name" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ template "verdaccio.name" . }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - containerPort: 4873
              name: http
          livenessProbe:
            httpGet:
              path: /-/ping
              port: http
            initialDelaySeconds: 5
          readinessProbe:
            httpGet:
              path: /-/ping
              port: http
            initialDelaySeconds: 5
          resources:
{{ toYaml .Values.resources | indent 12 }}
          volumeMounts:
{{- if .Values.persistence.mounts }}
{{ toYaml .Values.persistence.mounts | indent 12 }}
{{- end }}
            - mountPath: /verdaccio/storage
              name: storage
              readOnly: false
            - mountPath: /verdaccio/conf
              name: config
              readOnly: true
          env:
{{- if .Values.extraEnvVars }}
{{ toYaml .Values.extraEnvVars | indent 12 }}
{{- end }}
      {{- if .Values.securityContext.enabled }}
      # Allow non-root user to access PersistentVolume
      securityContext:
        runAsUser: {{ .Values.securityContext.runAsUser }}
        fsGroup: {{ .Values.securityContext.fsGroup }}
      {{- end }}
      volumes:
      - name: config
        configMap:
          name: {{ template "verdaccio.fullname" . }}
{{- if .Values.persistence.volumes }}
{{ toYaml .Values.persistence.volumes | indent 6 }}
{{- end }}
      - name: storage
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.existingClaim | default (include "verdaccio.fullname" .) }}
      {{- else }}
        emptyDir: {}
      {{- end -}}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
    {{- if .Values.tolerations }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
    {{- end }}
