# monitor-pv will be launch as daemonset.
# choose appropriate namespace and serviceaccount. defaults to ns: openebs, sa: openebs-maya-operator
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: monitor-pv
  namespace: openebs
spec:
  selector:
    matchLabels:
      app: monitor-pv
  template:
    metadata:
      labels:
        app: monitor-pv
      name: monitor-pv
    spec:
      serviceAccount: openebs-maya-operator
      containers:
      - image: quay.io/prometheus/node-exporter:v0.18.1 
        args:
          - --path.procfs=/host/proc
          - --path.sysfs=/host/sys
          - --path.rootfs=/host/root
          - --collector.filesystem.ignored-mount-points=^/(dev|proc|sys|var/lib|run|boot|home/kubernetes/.+)($|/)
          - --collector.filesystem.ignored-fs-types=^(autofs|binfmt_misc|cgroup|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|mqueue|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|sysfs|tracefs)$
          - --collector.textfile.directory=/shared_vol
        name: node-exporter
        ports:
        - containerPort: 9100
          hostPort: 9100
          name: scrape
        resources:
            requests:
              # A memory request of 250M means it will try to ensure minimum
              # 250MB RAM .
              memory: "128M"
              # A cpu request of 128m means it will try to ensure minimum
              # .125 CPU; where 1 CPU means :
              # 1 *Hyperthread* on a bare-metal Intel processor with Hyperthreading
              cpu: "128m"
            limits:
              memory: "700M"
              cpu: "500m"
        volumeMounts:
        # All the application data stored in data-disk
        - name: proc
          mountPath: /host/proc
          readOnly: false
        # Root disk is where OS(Node) is installed
        - name: sys
          mountPath: /host/sys
          readOnly: false
        - name: root
          mountPath: /host/root
          mountPropagation: HostToContainer
          readOnly: true
        - name: tmpvol
          mountPath: /shared_vol
      - name: monitor-pv
        image: openebs/monitor-pv:ci
        imagePullPolicy: Always
        env:
          - name: TEXTFILE_PATH
            value: /shared_vol
          - name: COLLECT_INTERVAL 
            value: "10"
        command:
        - /bin/bash
        args:
        - -c
        - ./textfile_collector.sh
        volumeMounts:
        - mountPath: /host/proc
          name: proc
        - mountPath: /host/sys
          name: sys
        - mountPath: /host/root
          mountPropagation: HostToContainer
          name: root
          readOnly: true
        - mountPath: /shared_vol
          name: tmpvol 
      tolerations:
      - effect: NoSchedule
        operator: Exists
      volumes:
        - name: proc
          hostPath:
            path: /proc
        - name: sys
          hostPath:
            path: /sys
        - name: root
          hostPath:
            path: /
        - name: tmpvol
          emptyDir: {}
      hostNetwork: true
      hostPID: true
