{{- if .Values.podMonitor.create }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: {{ include "aws-vpc-cni.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- with .Values.podMonitor.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- with .Values.podMonitor.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  jobLabel: {{ include "aws-vpc-cni.fullname" . }}
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
  podMetricsEndpoints:
  - interval: {{ .Values.podMonitor.interval }}
    path: /metrics
    port: metrics
    {{- with .Values.podMonitor.relabelings }}
    relabelings:
      {{- toYaml . | nindent 6 }}
    {{- end }}
  {{- if .Values.nodeAgent.enabled }}
  - interval: {{ .Values.podMonitor.interval }}
    path: /metrics
    port: agentmetrics
    {{- with .Values.podMonitor.relabelings }}
    relabelings:
      {{- toYaml . | nindent 6 }}
    {{- end }}
  {{- end }}
  selector:
    matchLabels:
      k8s-app: aws-node
{{- end }}
