alloy:
  alloy:
    configMap:
      content: |
        // Discover pods and collect logs
        discovery.kubernetes "pods" {
          role = "pod"
        }

        // Relabel to extract pod metadata
        discovery.relabel "pods" {
          targets = discovery.kubernetes.pods.targets

          rule {
            source_labels = ["__meta_kubernetes_namespace"]
            target_label  = "namespace"
          }
          rule {
            source_labels = ["__meta_kubernetes_pod_name"]
            target_label  = "pod"
          }
          rule {
            source_labels = ["__meta_kubernetes_pod_container_name"]
            target_label  = "container"
          }
        }

        // Collect logs from discovered pods
        loki.source.kubernetes "pods" {
          targets    = discovery.relabel.pods.output
          forward_to = [loki.write.default.receiver]
        }

        // Forward to Loki
        loki.write "default" {
          endpoint {
            url = "http://loki-stack.monitoring.svc.cluster.local:3100/loki/api/v1/push"
          }
        }

  controller:
    type: daemonset
    tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      - key: node-role.kubernetes.io/control-plane
        operator: Exists
        effect: NoSchedule

  serviceAccount:
    create: true
