-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Describe the bug
The Loki Helm chart's PodLogs template for self-monitoring doesn't correctly support the v1alpha2 API version. When monitoring.selfMonitoring.podLogs.apiVersion is set to monitoring.grafana.com/v1alpha2, the rendered PodLogs CR has an empty namespaceSelector: {} instead of properly restricting to the Loki namespace.
When using v1alpha2 API version for PodLogs, the chart template renders:
apiVersion: monitoring.grafana.com/v1alpha2
kind: PodLogs
metadata:
name: loki
namespace: observability
spec:
namespaceSelector: {} # ❌ Empty - should restrict to observability namespace
selector:
matchLabels:
app.kubernetes.io/instance: loki
app.kubernetes.io/name: loki
# ... rest of specHowever, the v1alpha2 CRD schema doesn't include the matchNames field. The v1alpha2 schema uses standard Kubernetes LabelSelector format with only:
matchExpressions(list of label selector requirements)matchLabels(map of label key-value pairs)
When Kubernetes validates the PodLogs CR against the v1alpha2 schema, it strips the unknown matchNames field, resulting in an empty namespaceSelector: {}.
To Reproduce
- Deploy Loki with self-monitoring enabled:
monitoring:
selfMonitoring:
enabled: true
podLogs:
apiVersion: monitoring.grafana.com/v1alpha2- Check the rendered PodLogs CR:
kubectl get podlogs/loki -n observability -o yaml-
Observe empty
namespaceSelector: {} -
Check Alloy/grafana-agent logs - it will be collecting logs from all pods cluster-wide
Expected behavior
The namespaceSelector should be properly populated to restrict log collection to the Loki namespace using v1alpha2 format:
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: observabilityEnvironment:
- Kubernetes Version: 1.31+
- Grafana Alloy: v1.11.2 (with PodLogs CRD v1alpha2 support)
Proposed Solution
Update the chart template to conditionally render the correct format based on API version:
{{- if eq .Values.monitoring.selfMonitoring.podLogs.apiVersion "monitoring.grafana.com/v1alpha2" }}
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ include "loki.namespace" $ }}
{{- else }}
namespaceSelector:
matchNames:
- {{ include "loki.namespace" $ }}
{{- end }}