{{- if or .Values.addons.mattermostoperator.enabled .Values.addons.mattermost.enabled }}
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: mattermost-operator
  namespace: {{ .Release.Namespace }}
  labels:
    app.kubernetes.io/name: mattermost-operator
    app.kubernetes.io/component: "collaboration-tools"
    {{- include "commonLabels" . | nindent 4}}
spec:
  targetNamespace: mattermost-operator
  chart:
    spec:
      chart: {{ .Values.addons.mattermostoperator.git.path }}
      interval: 5m
      sourceRef:
        kind: GitRepository
        name: mattermost-operator
        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 }}
  {{- if .Values.addons.mattermostoperator.postRenderers }}
  postRenderers:
  {{ toYaml .Values.addons.authservice.postRenderers | nindent 4 }}
  {{- end }}
  valuesFrom:
    - name: {{ .Release.Name }}-mattermost-operator-values
      kind: Secret
      valuesKey: "common"
    - name: {{ .Release.Name }}-mattermost-operator-values
      kind: Secret
      valuesKey: "defaults"
    - name: {{ .Release.Name }}-mattermost-operator-values
      kind: Secret
      valuesKey: "overlays"

  {{- if or .Values.gatekeeper.enabled .Values.monitoring.enabled }}
  dependsOn:
    {{- if .Values.gatekeeper.enabled }}
    - name: gatekeeper
      namespace: {{ .Release.Namespace }}
    {{- end }}
    {{- if .Values.monitoring.enabled }}
    - name: monitoring
      namespace: {{ .Release.Namespace }}
    {{- end }}
  {{- end }}
{{- end }}
