{{- if .Values.chartmuseum.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: "{{ template "harbor.chartmuseum" . }}"
  labels:
{{ include "harbor.labels" . | indent 4 }}
    component: chartmuseum
spec:
  replicas: {{ .Values.chartmuseum.replicas }}
  selector:
    matchLabels:
{{ include "harbor.matchLabels" . | indent 6 }}
      component: chartmuseum
  template:
    metadata:
      labels:
{{ include "harbor.labels" . | indent 8 }}
        component: chartmuseum
      annotations:
        checksum/configmap: {{ include (print $.Template.BasePath "/chartmuseum/chartmuseum-cm.yaml") . | sha256sum }}
        checksum/secret: {{ include (print $.Template.BasePath "/chartmuseum/chartmuseum-secret.yaml") . | sha256sum }}
        checksum/secret-core: {{ include (print $.Template.BasePath "/core/core-secret.yaml") . | sha256sum }}
{{- if .Values.chartmuseum.podAnnotations }}
{{ toYaml .Values.chartmuseum.podAnnotations | indent 8 }}
{{- end }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
      - name: chartmuseum
        image: {{ .Values.chartmuseum.image.repository }}:{{ .Values.chartmuseum.image.tag }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
        livenessProbe:
          httpGet:
            path: /health
            port: 9999
          initialDelaySeconds: 1
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: 9999
          initialDelaySeconds: 1
          periodSeconds: 10
{{- if .Values.chartmuseum.resources }}
        resources:
{{ toYaml .Values.chartmuseum.resources | indent 10 }}
{{- end }}
        envFrom:
        - configMapRef:
            name: "{{ template "harbor.chartmuseum" . }}"
        - secretRef:
            name: "{{ template "harbor.chartmuseum" . }}"
        env:
          - name: BASIC_AUTH_PASS
            valueFrom:
              secretKeyRef:
                name: {{ template "harbor.core" . }}
                key: secret
        ports:
        - containerPort: 9999
        volumeMounts:
        - name: chartmuseum-data
          mountPath: /chart_storage
          subPath: {{ .Values.persistence.persistentVolumeClaim.chartmuseum.subPath }}
        {{- if and .Values.persistence.enabled (eq .Values.persistence.imageChartStorage.type "gcs") }}
        - name: gcs-key
          mountPath: /etc/chartmuseum/gcs-key.json
          subPath: gcs-key.json
        {{- end }}
        {{- if .Values.persistence.imageChartStorage.caBundleSecretName }}
        - name: storage-service-ca
          mountPath: /harbor_cust_cert/custom-ca-bundle.crt
          subPath: ca.crt
        {{- end }}
      volumes:
      - name: chartmuseum-data
      {{- if and .Values.persistence.enabled (eq .Values.persistence.imageChartStorage.type "filesystem") }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.persistentVolumeClaim.chartmuseum.existingClaim | default (include "harbor.chartmuseum" .) }}
      {{- else }}
        emptyDir: {}
      {{- end }}
      {{- if and .Values.persistence.enabled (eq .Values.persistence.imageChartStorage.type "gcs") }}
      - name: gcs-key
        secret:
          secretName: {{ template "harbor.registry" . }}
          items:
            - key: GCS_KEY_DATA
              path: gcs-key.json
      {{- end }}
      {{- if .Values.persistence.imageChartStorage.caBundleSecretName }}
      - name: storage-service-ca
        secret:
          secretName: {{ .Values.persistence.imageChartStorage.caBundleSecretName }}
      {{- end }}
      {{- with .Values.chartmuseum.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with .Values.chartmuseum.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- with .Values.chartmuseum.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
      {{- end }}
{{- end }}
