---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: logdna-agent
  namespace: logdna-agent
  labels:
    app.kubernetes.io/name: logdna-agent
    app.kubernetes.io/instance: logdna-agent
    app.kubernetes.io/version: 2.2.4
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: logdna-agent
  name: logdna-agent
  labels:
    app.kubernetes.io/name: logdna-agent
    app.kubernetes.io/instance: logdna-agent
    app.kubernetes.io/version: 2.2.4
rules:
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["get","list", "create", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: logdna-agent
  namespace: logdna-agent
  labels:
    app.kubernetes.io/name: logdna-agent
    app.kubernetes.io/instance: logdna-agent
    app.kubernetes.io/version: 2.2.4
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: logdna-agent
subjects:
  - kind: ServiceAccount
    name: logdna-agent
    namespace: logdna-agent
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: logdna-agent
  labels:
    app.kubernetes.io/name: logdna-agent
    app.kubernetes.io/instance: logdna-agent
    app.kubernetes.io/version: 2.2.4
rules:
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["get","list", "create", "watch"]
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get","list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: logdna-agent
  labels:
    app.kubernetes.io/name: logdna-agent
    app.kubernetes.io/instance: logdna-agent
    app.kubernetes.io/version: 2.2.4
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: logdna-agent
subjects:
  - kind: ServiceAccount
    name: logdna-agent
    namespace: logdna-agent
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: logdna-agent
  namespace: logdna-agent
  labels:
    app.kubernetes.io/name: logdna-agent
    app.kubernetes.io/instance: logdna-agent
    app.kubernetes.io/version: 2.2.4
spec:
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 100%
  selector:
    matchLabels:
      app: logdna-agent
  template:
    metadata:
      labels:
        app: logdna-agent
        app.kubernetes.io/name: logdna-agent
        app.kubernetes.io/instance: logdna-agent
        app.kubernetes.io/version: 2.2.4
    spec:
      serviceAccountName: logdna-agent
      containers:
        - name: logdna-agent
          image: logdna/logdna-agent:2.2.4
          imagePullPolicy: Always
          securityContext:
            capabilities:
              add:
                - DAC_READ_SEARCH
              drop:
                - all
          env:
            - name: LOGDNA_AGENT_KEY
              valueFrom:
                secretKeyRef:
                  name: logdna-agent-key
                  key: logdna-agent-key
            - name: LOGDNA_HOST
              value: logs.logdna.com
            - name: POD_APP_LABEL
              valueFrom:
                fieldRef:
                  fieldPath: metadata.labels['app.kubernetes.io/name']
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          resources:
            requests:
              cpu: 20m
            limits:
              memory: 500Mi
          volumeMounts:
            - name: varlog
              mountPath: /var/log
            - name: vardata
              mountPath: /var/data
            - name: varlibdockercontainers
              mountPath: /var/lib/docker/containers
              readOnly: true
            - name: mnt
              mountPath: /mnt
              readOnly: true
            - name: osrelease
              mountPath: /etc/os-release
            - name: logdnahostname
              mountPath: /etc/logdna-hostname
      volumes:
        - name: varlog
          hostPath:
            path: /var/log
        - name: vardata
          hostPath:
            path: /var/data
        - name: varlibdockercontainers
          hostPath:
            path: /var/lib/docker/containers
        - name: mnt
          hostPath:
            path: /mnt
        - name: osrelease
          hostPath:
            path: /etc/os-release
        - name: logdnahostname
          hostPath:
            path: /etc/hostname
