# Copyright (c) 2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: wca
  labels:
    name: wca
spec:
  selector:
    matchLabels:
      name: wca
  template:
    metadata:
      labels:
        name: wca
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9100"
    spec:
      nodeSelector:
        #kubernetes.io/hostname: node11
        # kubectl get nodes --show-labels
        goal: service

      terminationGracePeriodSeconds: 1
      hostPID: true
      hostIPC: true
      hostNetwork: true
      serviceAccountName: wca
      containers:

      - name: wca
        imagePullPolicy: Always # for debugging purpose and stream the development!
        image: wca
        securityContext:
          privileged: true
        env:
          - name: HOST_IP
            valueFrom:
              fieldRef:
                fieldPath: status.hostIP
        volumeMounts:
          - name: var-lib-wca
            mountPath: /var/lib/wca/
          - name: cgroup
            mountPath: /sys/fs/cgroup/
          - name: resctrl
            mountPath: /sys/fs/resctrl/
          - name: dev-cpu
            mountPath: /dev/cpu
          - name: wca-config
            mountPath: /etc/wca/
          - name: proc
            mountPath: /proc
#        command:
#          - sleep
#          - inf
        command:
          - /usr/bin/wca.pex
        args:
        - "--config=/etc/wca/wca-config.yaml"
        - "--log=info"
        - "--root"

      - name: node-exporter
        image: prom/node-exporter:v0.18.1
        securityContext:
          privileged: true
        args:
          - --collector.textfile.directory
          - /var/lib/wca
        ports:
          - containerPort: 9100
            protocol: TCP
        volumeMounts:
          - name: var-lib-wca
            mountPath: /var/lib/wca
          - name: dev
            mountPath: /host/dev
          - name: proc
            mountPath: /host/proc
          - name: sys
            mountPath: /host/sys
          - name: rootfs
            mountPath: /rootfs

      volumes:
        # Config for wca
        - name: wca-config
          configMap:
            name: wca-config
        # Volume to write wca log
        - name: var-lib-wca
          emptyDir: {}
        # Path for wca to read cgroup, resctrl and dev-cpu
        - name: cgroup
          hostPath:
            path: /sys/fs/cgroup/
        - name: resctrl
          hostPath:
            path: /sys/fs/resctrl/
        - name: dev-cpu
          hostPath:
            path: /dev/cpu

        # Paths for nodeexporter to collect metrics
        - name: proc
          hostPath:
            path: /proc
        - name: dev
          hostPath:
            path: /dev
        - name: sys
          hostPath:
            path: /sys
        - name: rootfs
          hostPath:
            path: /
