{{- if .Values.packaging.helm.enabled }}
{{- range .Values.apprepository.initialRepos }}
apiVersion: kubeapps.com/v1alpha1
kind: AppRepository
metadata:
  name: {{ .name }}
  namespace: {{ default (include "kubeapps.globalReposNamespace" $) .namespace | quote }}
  labels: {{- include "common.labels.standard" $ | nindent 4 }}
    {{- if $.Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" $.Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if $.Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  type: {{ default "helm" .type }}
  url: {{ .url }}
  {{- if .ociRepositories }}
  ociRepositories:
  {{- range .ociRepositories }}
  - {{ . }}
  {{- end }}
  {{- end }}
  {{- if or $.Values.apprepository.containerSecurityContext.enabled $.Values.apprepository.initialReposProxy.enabled .nodeSelector }}
  syncJobPodTemplate:
    spec:
      {{- if $.Values.apprepository.initialReposProxy.enabled }}
      containers:
        - env:
            - name: https_proxy
              value: {{ $.Values.apprepository.initialReposProxy.httpsProxy }}
            - name: http_proxy
              value: {{ $.Values.apprepository.initialReposProxy.httpProxy }}
            - name: no_proxy
              value: {{ $.Values.apprepository.initialReposProxy.noProxy }}
      {{- end }}
      {{- if $.Values.apprepository.containerSecurityContext.enabled }}
      securityContext:
        runAsUser: {{ $.Values.apprepository.containerSecurityContext.runAsUser }}
      {{- end }}
      {{- if .nodeSelector }}
      nodeSelector: {{- toYaml .nodeSelector | nindent 8 }}
      {{- end }}
  {{- end }}
  {{- if or .caCert .authorizationHeader .basicAuth }}
  auth:
    {{- if .caCert }}
    customCA:
      secretKeyRef:
        key: ca.crt
        name: {{ printf "apprepo-%s-secrets" .name }}
    {{- end }}
    {{- if or .authorizationHeader .basicAuth }}
    header:
      secretKeyRef:
        key: authorizationHeader
        name: {{ printf "apprepo-%s-secrets" .name }}
    {{- end }}
  {{- end }}
  {{- if .filterRule }}
  filterRule:
    {{- toYaml .filterRule | nindent 4 }}
  {{- end }}
---
{{ end -}}
{{- end -}}
