apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "kubeapps.apprepository.fullname" . }}
  labels:{{ include "kubeapps.extraAppLabels" . | nindent 4 }}
    app: {{ template "kubeapps.apprepository.fullname" . }}
spec:
  replicas: {{ .Values.apprepository.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "kubeapps.apprepository.fullname" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "kubeapps.apprepository.fullname" . }}
        release: {{ .Release.Name }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/name: {{ template "kubeapps.name" . }}
    spec:
      serviceAccountName: {{ template "kubeapps.apprepository.fullname" . }}
{{- include "kubeapps.imagePullSecrets" . | indent 6 }}
      {{- if .Values.apprepository.affinity }}
      affinity: {{- include "kubeapps.tplValue" (dict "value" .Values.apprepository.affinity "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.apprepository.nodeSelector }}
      nodeSelector: {{- include "kubeapps.tplValue" (dict "value" .Values.apprepository.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.apprepository.tolerations }}
      tolerations: {{- include "kubeapps.tplValue" (dict "value" .Values.apprepository.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.securityContext.enabled }}
      securityContext:
        fsGroup: {{ .Values.securityContext.fsGroup }}
        runAsUser: {{ .Values.securityContext.runAsUser }}
      {{- end }}
      containers:
        - name: controller
          image: {{ template "kubeapps.image" (list .Values.apprepository.image .Values.global) }}
          imagePullPolicy: {{ .Values.apprepository.image.pullPolicy | quote }}
          command:
            - /apprepository-controller
          args:
            - --user-agent-comment=kubeapps/{{ .Chart.AppVersion }}
            - --repo-sync-image={{ template "kubeapps.image" (list .Values.apprepository.syncImage .Values.global) }}
            - --repo-sync-cmd=/asset-syncer
            - --namespace={{ .Release.Namespace }}
            - --database-secret-name={{ .Values.postgresql.existingSecret }}
            - --database-secret-key=postgresql-password
            - --database-url={{ template "kubeapps.postgresql.fullname" . }}:5432
            - --database-user=postgres
            - --database-name=assets
            {{- if .Values.apprepository.crontab }}
            - --crontab={{ .Values.apprepository.crontab }}
            {{- end }}
            - --repos-per-namespace={{ .Values.apprepository.watchAllNamespaces}}
          {{- if .Values.apprepository.resources }}
          resources: {{- toYaml .Values.apprepository.resources | nindent 12 }}
          {{- end }}
