apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ include "chartmuseum.fullname" . }}
  annotations:
{{ toYaml .Values.deployment.annotations | indent 4 }}
  labels:
{{ include "chartmuseum.labels.standard" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
{{ toYaml .Values.strategy | indent 4 }}
  revisionHistoryLimit: 10
  template:
    metadata:
      name: {{ include "chartmuseum.fullname" . }}
      annotations:
{{ toYaml .Values.replica.annotations | indent 8 }}
      labels:
        app: {{ template "chartmuseum.name" . }}
        release: {{ .Release.Name | quote }}
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        env:
{{- range $name, $value := .Values.env.open }}
{{- if not (empty $value) }}
        - name: {{ $name | quote }}
          value: {{ $value | quote }}
{{- end }}
{{- end }}
{{- $secret_name := include "chartmuseum.fullname" . }}
{{- range $name, $value := .Values.env.secret }}
{{- if not ( empty $value) }}
        - name: {{ $name | quote }}
          valueFrom:
            secretKeyRef:
              name: {{ $secret_name }}
              key: {{ $name | quote }}
{{- end }}
{{- end }}
        args:
        - --port=8080
{{- if eq .Values.env.open.STORAGE "local" }}
        - --storage-local-rootdir=/storage
{{- end }}
        ports:
        - name: http
          containerPort: 8080
        livenessProbe:
          httpGet:
            path: {{ .Values.env.open.CONTEXT_PATH }}/health
            port: http
{{ toYaml .Values.probes.liveness | indent 10 }}
        readinessProbe:
          httpGet:
            path: {{ .Values.env.open.CONTEXT_PATH }}/health
            port: http
{{ toYaml .Values.probes.readiness | indent 10 }}
{{- if eq .Values.env.open.STORAGE "local" }}
        volumeMounts:
        - mountPath: /storage
          name: storage-volume
{{- end }}
      {{- with .Values.resources }}
        resources:
{{ toYaml . | indent 10 }}
      {{- end }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}

      volumes:
      - name: storage-volume
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.existingClaim | default (include "chartmuseum.fullname" .) }}
      {{- else }}
        emptyDir: {}
      {{- end -}}
