{% if PANORAMA_RUN_K8S_FLUENTBIT %}
# Panorama logs (fluentbit) for K8s - ClusterRole
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: fluent-bit
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: pod-log-reader
rules:
- apiGroups: [""]
  resources:
    - namespaces
    - pods
    - nodes
    - nodes/proxy
  verbs:
    - get
    - list
    - watch

---
# Panorama logs (fluentbit) for K8s - ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: pod-log-crb
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: pod-log-reader
subjects:
- kind: ServiceAccount
  name: fluent-bit
  namespace: kube-system

---
# Panorama logs (fluentbit) for K8s - DaemonSet
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentbit
  namespace: kube-system
  labels:
    app.kubernetes.io/name: fluentbit
spec:
  selector:
    matchLabels:
      name: fluentbit
  template:
    metadata:
      labels:
        name: fluentbit
    spec:
      dnsPolicy: ClusterFirstWithHostNet
      hostNetwork: true
      serviceAccountName: fluent-bit
      containers:
      - name: aws-for-fluent-bit
        env:
          - name: FLB_LOG_LEVEL
            value: {{ PANORAMA_FLB_LOG_LEVEL }}
          - name: AWS_ACCESS_KEY_ID
            value: {{ PANORAMA_AWS_ACCESS_KEY }}
          - name: AWS_SECRET_ACCESS_KEY
            value: {{ PANORAMA_AWS_SECRET_ACCESS_KEY }}
        image: {{ PANORAMA_LOGS_DOCKER_IMAGE }}
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
        - name: fluent-bit-config
          mountPath: /fluent-bit/etc/
        - name: mnt
          mountPath: /mnt
          readOnly: true
        resources:
          limits:
            memory: 256Mi
          requests:
            cpu: 500m
            memory: 100Mi
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
      - name: fluent-bit-config
        configMap:
          name: fluent-bit-config
      - name: mnt
        hostPath:
          path: /mnt
{% endif %}
