apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: drycc-monitor-telegraf
  labels:
    heritage: drycc
  annotations:
    component.drycc.cc/version: {{ .Values.monitor.telegraf.docker_tag }}
spec:
  selector:
    matchLabels:
      app: drycc-monitor-telegraf
  {{- if ge .Capabilities.KubeVersion.Minor "6" }}
  updateStrategy:
    type: RollingUpdate
  {{- end }}
  template:
    metadata:
      labels:
        app: drycc-monitor-telegraf
    spec:
      serviceAccount: drycc-monitor-telegraf
      containers:
        - name: drycc-monitor-telegraf
          image: {{.Values.monitor.telegraf.docker_registry}}{{.Values.monitor.telegraf.org}}/telegraf:{{.Values.monitor.telegraf.docker_tag}}
          imagePullPolicy: {{.Values.monitor.telegraf.pull_policy}}
{{- if or (.Values.monitor.telegraf.limits_cpu) (.Values.monitor.telegraf.limits_memory)}}
          resources:
            limits:
{{- if (.Values.monitor.telegraf.limits_cpu) }}
              cpu: {{.Values.monitor.telegraf.limits_cpu}}
{{- end}}
{{- if (.Values.monitor.telegraf.limits_memory) }}
              memory: {{.Values.monitor.telegraf.limits_memory}}
{{- end}}
{{- end}}
          env:
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          {{- if eq .Values.global.influxdb_location "off-cluster" }}
          - name: "INFLUXDB_URLS"
            valueFrom:
              secretKeyRef:
                name: influxdb-creds
                key: url
          - name: "INFLUXDB_DATABASE"
            valueFrom:
              secretKeyRef:
                name: influxdb-creds
                key: database
          - name: "INFLUXDB_USERNAME"
            valueFrom:
              secretKeyRef:
                name: influxdb-creds
                key: user
          - name: "INFLUXDB_PASSWORD"
            valueFrom:
              secretKeyRef:
                name: influxdb-creds
                key: password
          {{- else }}
          - name: "INFLUXDB_URLS"
            value: "\"http://$(DRYCC_MONITOR_INFLUXDB_SERVICE_HOST):$(DRYCC_MONITOR_INFLUXDB_SERVICE_PORT_TRANSPORT)\""
          {{- end }}
          - name: "HOST_PROC"
            value: "/rootfs/proc"
          - name: "HOST_SYS"
            value: "/rootfs/sys"
          - name: "AGENT_QUIET"
            value: "true"
          - name: "AGENT_BUFFER_LIMIT"
            value: "100000"
          - name: "ENABLE_KUBERNETES"
            value: "true"
          - name: "ENABLE_BARE_METAL_SERVER"
            value: "true"
          volumeMounts:
          - mountPath: /var/run/docker.sock
            name: docker-socket
          - name: sysro
            mountPath: /rootfs/sys
            readOnly: true
          - name: procro
            mountPath: /rootfs/proc
            readOnly: true
          - name: varrunutmpro
            mountPath: /var/run/utmp
            readOnly: true
      volumes:
      - name: docker-socket
        hostPath:
          path: /var/run/docker.sock
      - name: sysro
        hostPath:
          path: /sys
      - name: procro
        hostPath:
          path: /proc
      - name: varrunutmpro
        hostPath:
          path: /var/run/utmp