{{- if .Values.rolloutAnalysisTemplates.enabled }}
{{- range $defaultTemplateType, $defaultTemplateConf := .Values.rolloutAnalysisTemplates.defaultTemplates }}
{{- if $defaultTemplateConf.enabled }}
{{- range $templateName, $templateConfig := .templates }}
{{- $provider :=  printf "%s.provider" $templateName -}}
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: {{ .name }}
spec:
  args:
{{- if $.Values.rolloutAnalysisTemplates.authToken }}
  - name: prom-auth-token
    valueFrom:
      secretKeyRef:
        name: {{ include "promAuthSecretName" $  | trunc 63 }}
        key: authToken
{{- end }}
  - name: service-name
  metrics:
    - name: {{ .name }}
      interval: {{ .interval }}
      successCondition: result[0] <= {{ .changeMax }}
      failureLimit: {{ .failureLimit }}
      provider: {{- include $provider $ | nindent 8 }}
      count: {{ .count }}
---
{{- end }}
{{- end }}
{{- end }}
{{- end }}
