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

{{- if and .Values.msgTopologyOperator.enabled  .Values.msgTopologyOperator.metrics.podMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: {{ template "rmqco.msgTopologyOperator.fullname" . }}
  {{- $versionLabel := dict "app.kubernetes.io/version" ( include "common.images.version" ( dict "imageRoot" .Values.msgTopologyOperator.image "chart" .Chart ) ) }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.msgTopologyOperator.metrics.podMonitor.labels .Values.commonLabels $versionLabel ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: messaging-topology-operator
    app.kubernetes.io/part-of: rabbitmq
    {{- if .Values.msgTopologyOperator.metrics.podMonitor.additionalLabels }}
    {{- include "common.tplvalues.render" (dict "value" .Values.msgTopologyOperator.metrics.podMonitor.additionalLabels "context" $) | nindent 4 }}
    {{- end }}
  namespace: {{ default (include "common.names.namespace" .) .Values.msgTopologyOperator.metrics.podMonitor.namespace | quote }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  jobLabel: {{ .Values.msgTopologyOperator.metrics.podMonitor.jobLabel }}
  selector:
    matchLabels:
      {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.msgTopologyOperator.podLabels .Values.commonLabels ) "context" . ) }}
      {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }}
      {{- if .Values.msgTopologyOperator.metrics.podMonitor.selector }}
      {{- include "common.tplvalues.render" ( dict "value" .Values.msgTopologyOperator.metrics.podMonitor.selector "context" $ ) | nindent 6 }}
      {{- end }}
      app.kubernetes.io/component: messaging-topology-operator
  namespaceSelector:
    matchNames:
      - {{ include "common.names.namespace" . | quote }}
  podMetricsEndpoints:
    - port: http-metrics
      {{- if .Values.msgTopologyOperator.metrics.podMonitor.interval }}
      interval: {{ .Values.msgTopologyOperator.metrics.podMonitor.interval }}
      {{- end }}
      {{- if .Values.msgTopologyOperator.metrics.podMonitor.honorLabels }}
      honorLabels: {{ .Values.msgTopologyOperator.metrics.podMonitor.honorLabels }}
      {{- end }}
      {{- if .Values.msgTopologyOperator.metrics.podMonitor.scrapeTimeout }}
      scrapeTimeout: {{ .Values.msgTopologyOperator.metrics.podMonitor.scrapeTimeout }}
      {{- end }}
      {{- if .Values.msgTopologyOperator.metrics.podMonitor.relabelings }}
      relabelings: {{ toYaml .Values.msgTopologyOperator.metrics.podMonitor.relabelings | nindent 8 }}
      {{- end }}
      {{- if .Values.msgTopologyOperator.metrics.podMonitor.metricRelabelings }}
      metricRelabelings: {{ toYaml .Values.msgTopologyOperator.metrics.podMonitor.metricRelabelings | nindent 8 }}
      {{- end }}
{{- end }}
