{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and .Values.thanosRuler.enabled (not .Values.thanosRuler.alertmanagersConfig.existingSecret.name) (or .Values.thanosRuler.alertmanagersConfig.config .Values.alertmanager.enabled) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ printf "%s-alertmanagers-config" (include "kube-prometheus.thanosRuler.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ include "common.names.namespace" . }}
  {{- $versionLabel := dict "app.kubernetes.io/version" (include "common.images.version" (dict "imageRoot" .Values.thanosRuler.image "chart" .Chart)) }}
  {{- $labels := include "common.tplvalues.merge" (dict "values" (list .Values.commonLabels $versionLabel) "context" .) }}
  labels: {{ include "common.labels.standard" (dict "customLabels" $labels "context" .) | nindent 4 }}
    app.kubernetes.io/component: thanos-ruler
  {{- if .Values.commonAnnotations }}
  annotations: {{ include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
stringData:
  alertmanagers-config.yaml: |-
    {{- if .Values.thanosRuler.alertmanagersConfig.config }}
      {{- include "common.tplvalues.render" (dict "value" .Values.thanosRuler.alertmanagersConfig.config "context" $) | nindent 4 }}
    {{ else }}
    alertmanagers:
    - static_configs:
      - {{ template "kube-prometheus.alertmanager.fullname" . }}.{{ include "common.names.namespace" . }}:{{ .Values.alertmanager.service.ports.http }}
      scheme: http
      timeout: 10s
      api_version: v2
      path_prefix: {{ .Values.alertmanager.routePrefix }}
    {{- end }}
{{- end }}
