---
# https://raw.githubusercontent.com/kubernetes/kubernetes/v1.10.2/cluster/addons/fluentd-elasticsearch/fluentd-es-ds.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: "fluentd-es-{{ fluentd_version }}"
  namespace: "kube-system"
  labels:
    k8s-app: fluentd-es
    version: "{{ fluentd_version }}"
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
spec:
  selector:
    matchLabels:
      k8s-app: fluentd-es
      version: "{{ fluentd_version }}"
  template:
    metadata:
      labels:
        k8s-app: fluentd-es
        kubernetes.io/cluster-service: "true"
        version: "{{ fluentd_version }}"
      # This annotation ensures that fluentd does not get evicted if the node
      # supports critical pod annotation based priority scheme.
      # Note that this does not guarantee admission on the nodes (#40573).
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
    spec:
      priorityClassName: system-node-critical
      serviceAccountName: efk
      containers:
      - name: fluentd-es
        image: "{{ fluentd_image_repo }}:{{ fluentd_image_tag }}"
        env:
        - name: FLUENTD_ARGS
          value: "--no-supervisor -q"
        resources:
          limits:
{% if fluentd_cpu_limit is defined and fluentd_cpu_limit != "0m" %}
            cpu: {{ fluentd_cpu_limit }}
{% endif %}
            memory: {{ fluentd_mem_limit }}
          requests:
            cpu: {{ fluentd_cpu_requests }}
            memory: {{ fluentd_mem_requests }}
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: "{{ docker_daemon_graph }}/containers"
          readOnly: true
        - name: config-volume
          mountPath: "{{ fluentd_config_dir }}"
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: {{ docker_daemon_graph }}/containers
      - name: config-volume
        configMap:
          name: fluentd-config
