{{- if .Values.agent.processExporter.enabled }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ .Values.agent.processExporter.serviceAccountName }}
  namespace: {{ .Values.namespaces.observability }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: process-exporter-config
  namespace: {{ .Values.namespaces.observability }}
data:
  config.yaml: |
    {{- .Values.agent.processExporter.config | nindent 4 }}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: process-exporter
  namespace: {{ .Values.namespaces.observability }}
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: process-exporter
  template:
    metadata:
      labels:
        app.kubernetes.io/name: process-exporter
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "{{ .Values.agent.processExporter.port }}"
    spec:
      serviceAccountName: {{ .Values.agent.processExporter.serviceAccountName }}
      hostPID: true
      containers:
        - name: process-exporter
          image: "{{ .Values.agent.processExporter.image.repository }}:{{ .Values.agent.processExporter.image.tag }}"
          imagePullPolicy: {{ .Values.agent.processExporter.image.pullPolicy }}
          args:
            - --procfs
            - /host/proc
            - --config.path
            - /etc/process-exporter/config.yaml
            - --web.listen-address=:{{ .Values.agent.processExporter.port }}
          ports:
            - name: metrics
              containerPort: {{ .Values.agent.processExporter.port }}
              protocol: TCP
          resources:
            {{- toYaml .Values.agent.processExporter.resources | nindent 12 }}
          volumeMounts:
            - name: config
              mountPath: /etc/process-exporter
            - name: proc
              mountPath: /host/proc
              readOnly: true
      volumes:
        - name: config
          configMap:
            name: process-exporter-config
        - name: proc
          hostPath:
            path: /proc
{{- end }}
