{{- if and .Values.istio.enabled ( or .Values.addons.authservice.enabled .Values.monitoring.sso.enabled .Values.jaeger.sso.enabled ) }}
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: authservice
  namespace: {{ .Release.Namespace }}
  labels:
    app.kubernetes.io/name: authservice
    app.kubernetes.io/component: "core"
    {{- include "commonLabels" . | nindent 4}}
spec:
  targetNamespace: authservice
  chart:
    spec:
      chart: {{ .Values.addons.authservice.git.path }}
      interval: 5m
      sourceRef:
        kind: GitRepository
        name: authservice
        namespace: {{ .Release.Namespace }}

  {{- with .Values.flux }}
  interval: {{ .interval }}
  test:
    enable: false
  install:
    remediation:
      retries: {{ .install.retries }}
  upgrade:
    remediation:
      retries: {{ .upgrade.retries }}
      remediateLastFailure: true
    cleanupOnFail: true
  rollback:
    timeout: {{ .rollback.timeout }}
    cleanupOnFail: {{ .rollback.cleanupOnFail }}
  {{- end }}

  valuesFrom:
    - name: {{ .Release.Name }}-authservice-values
      kind: Secret
      valuesKey: "common"
    - name: {{ .Release.Name }}-authservice-values
      kind: Secret
      valuesKey: "defaults"
    - name: {{ .Release.Name }}-authservice-values
      kind: Secret
      valuesKey: "overlays"

  {{- if .Values.istio.enabled }}
  dependsOn:
  - name: istio
    namespace: {{ .Release.Namespace }}
  {{- end }}
{{- end }}