apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "kubeapps.assetsvc.fullname" . }}
  labels:{{ include "kubeapps.extraAppLabels" . | nindent 4 }}
    app: {{ template "kubeapps.assetsvc.fullname" . }}
spec:
  replicas: {{ .Values.assetsvc.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "kubeapps.assetsvc.fullname" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "kubeapps.assetsvc.fullname" . }}
        app.kubernetes.io/name: {{ template "kubeapps.name" . }}
        release: {{ .Release.Name }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
{{- include "kubeapps.imagePullSecrets" . | indent 6 }}
      {{- if .Values.assetsvc.affinity }}
      affinity: {{- include "kubeapps.tplValue" (dict "value" .Values.assetsvc.affinity "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.assetsvc.nodeSelector }}
      nodeSelector: {{- include "kubeapps.tplValue" (dict "value" .Values.assetsvc.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.assetsvc.tolerations }}
      tolerations: {{- include "kubeapps.tplValue" (dict "value" .Values.assetsvc.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.securityContext.enabled }}
      securityContext:
        fsGroup: {{ .Values.securityContext.fsGroup }}
        runAsUser: {{ .Values.securityContext.runAsUser }}
      {{- end }}
      containers:
        - name: assetsvc
          image: {{ template "kubeapps.image" (list .Values.assetsvc.image .Values.global) }}
          imagePullPolicy: {{ .Values.assetsvc.image.pullPolicy | quote }}
          command:
            - /assetsvc
          args:
            - --database-user=postgres
            - --database-name=assets
            - --database-url={{ template "kubeapps.postgresql.fullname" . }}-headless:5432
          env:
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ .Values.postgresql.existingSecret }}
                  key: postgresql-password
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - name: http
              containerPort: {{ .Values.assetsvc.service.port }}
          {{- if .Values.assetsvc.livenessProbe }}
          livenessProbe: {{- toYaml .Values.assetsvc.livenessProbe | nindent 12 }}
          {{- end }}
          {{- if .Values.assetsvc.readinessProbe }}
          readinessProbe: {{- toYaml .Values.assetsvc.readinessProbe | nindent 12 }}
          {{- end }}
          {{- if .Values.assetsvc.resource }}
          resources: {{- toYaml .Values.assetsvc.resources | nindent 12 }}
          {{- end }}
