Skip to content

Commit

Permalink
Handle chart dependencies better (#714)
Browse files Browse the repository at this point in the history
Also create an enabled flag for the main alloy, giving the opportunity to skip that if required

Signed-off-by: Pete Wall <pete.wall@grafana.com>
  • Loading branch information
petewall authored Sep 4, 2024
1 parent 618487e commit 7ff4623
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 1,482 deletions.
4 changes: 2 additions & 2 deletions charts/k8s-monitoring/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ dependencies:
- name: beyla
repository: https://grafana.github.io/helm-charts
version: 1.3.0
digest: sha256:ce7702f0d65f1d906f273c8f9cf41978d0f4b2aca89ca1d6ab009b697307d80f
generated: "2024-08-28T12:29:38.875476-05:00"
digest: sha256:7976367130ea7f872c5f063196d1bbb1ffacaba41bc19d1e1b278606c8605f6f
generated: "2024-09-03T17:46:27.894161-05:00"
5 changes: 3 additions & 2 deletions charts/k8s-monitoring/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ dependencies:
- name: alloy
version: 0.6.1
repository: https://grafana.github.io/helm-charts
condition: alloy.enabled
- alias: alloy-events
name: alloy
version: 0.6.1
repository: https://grafana.github.io/helm-charts
condition: logs.cluster_events.enabled
condition: logs.enabled, logs.cluster_events.enabled
- alias: alloy-logs
name: alloy
version: 0.6.1
repository: https://grafana.github.io/helm-charts
condition: logs.pod_logs.enabled
condition: logs.enabled, logs.pod_logs.enabled
- alias: alloy-profiles
name: alloy
version: 0.6.1
Expand Down
1 change: 1 addition & 0 deletions charts/k8s-monitoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ The Prometheus and Loki services may be hosted on the same cluster, or remotely

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| alloy.enabled | bool | `true` | Deploy this Alloy instance. Only set this to false if you are not using metrics or any receivers. |
| alloy.liveDebugging.enabled | bool | `false` | Enable live debugging for the Alloy instance. Requires stability level to be set to "experimental". |
| alloy.logging.format | string | `"logfmt"` | Format to use for writing Alloy log lines. |
| alloy.logging.level | string | `"info"` | Level at which Alloy log lines should be written. |
Expand Down
9 changes: 9 additions & 0 deletions charts/k8s-monitoring/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
{{- end -}}
{{- end -}}

{{/* This returns the first enabled alloy instance */}}
{{- define "getEnabledAlloy" -}}
{{- if .Values.alloy.enabled }}alloy
{{- else if (and .Values.logs.enabled .Values.logs.cluster_events.enabled) }}alloy-events
{{- else if (and .Values.logs.enabled .Values.logs.pod_logs.enabled) }}alloy-logs
{{- else if .Values.profiles.enabled }}alloy-profiles
{{- end -}}
{{- end -}}

{{- define "kubernetes_monitoring_telemetry.metrics" -}}
{{- $metrics := list -}}
{{- if .Values.metrics.enabled -}}
Expand Down
2 changes: 2 additions & 0 deletions charts/k8s-monitoring/templates/alloy-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if and .Values.alloy.enabled }}
---
apiVersion: v1
kind: ConfigMap
Expand All @@ -13,3 +14,4 @@ data:
# TYPE grafana_kubernetes_monitoring_build_info gauge
grafana_kubernetes_monitoring_build_info{version="{{ .Chart.Version }}", namespace="{{ .Release.Namespace }}", metrics="{{ include "kubernetes_monitoring_telemetry.metrics" . }}", logs="{{ include "kubernetes_monitoring_telemetry.logs" . }}", traces="{{ include "kubernetes_monitoring_telemetry.traces" . }}", deployments="{{ include "kubernetes_monitoring_telemetry.deployments" . }}"} 1
{{- end }}
{{- end }}
1 change: 1 addition & 0 deletions charts/k8s-monitoring/templates/alloy-events-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if and .Values.logs.enabled .Values.logs.cluster_events.enabled }}
---
apiVersion: v1
kind: ConfigMap
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.receivers.deployGrafanaAgentService .Values.alloy.service.enabled -}}
{{- if and .Values.alloy.enabled .Values.receivers.deployGrafanaAgentService .Values.alloy.service.enabled -}}
apiVersion: v1
kind: Service
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if .Values.configValidator.enabled }}
{{- $enabledAlloy := include "getEnabledAlloy" . }}
---
apiVersion: v1
kind: Pod
Expand All @@ -24,12 +25,12 @@ spec:
{{- if .Values.configValidator.serviceAccount.name }}
serviceAccountName: {{ .Values.configValidator.serviceAccount.name }}
{{- end }}
{{- if or .Values.global.image.pullSecrets .Values.alloy.image.pullSecrets }}
{{- if or .Values.global.image.pullSecrets (index .Values $enabledAlloy).image.pullSecrets }}
imagePullSecrets:
{{- if .Values.global.image.pullSecrets }}
{{- toYaml .Values.global.image.pullSecrets | nindent 8 }}
{{- else }}
{{- toYaml .Values.alloy.image.pullSecrets | nindent 8 }}
{{- toYaml (index .Values $enabledAlloy).image.pullSecrets | nindent 8 }}
{{- end }}
{{- end }}
restartPolicy: Never
Expand All @@ -43,7 +44,7 @@ spec:
{{- end }}
containers:
- name: alloy
image: "{{ .Values.global.image.registry | default .Values.alloy.image.registry }}/{{ .Values.alloy.image.repository }}{{ include "alloy.imageId" .Subcharts.alloy }}"
image: "{{ .Values.global.image.registry | default (index .Values $enabledAlloy).image.registry }}/{{ (index .Values $enabledAlloy).image.repository }}{{ include "alloy.imageId" .Subcharts.alloy }}"
command:
- bash
- -c
Expand All @@ -52,7 +53,7 @@ spec:
if ! alloy fmt /etc/alloy/config.alloy > /dev/null; then
exit 1
fi
output=$(alloy run --stability.level {{ .Values.alloy.alloy.stabilityLevel | default "generally-available" }} "/etc/alloy/config.alloy" 2>&1)
output=$(alloy run --stability.level {{ (index .Values $enabledAlloy).alloy.stabilityLevel | default "generally-available" }} "/etc/alloy/config.alloy" 2>&1)
if ! echo "${output}" | grep "KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined" >/dev/null; then
echo "${output}"
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ subjects:

{{- if eq .Values.cluster.platform "openshift" }}
{{/* Create the SecurityContextConstraints for the main Alloy instance */}}
{{- if .Values.alloy.enabled }}
{{$data := dict "name" (include "alloy.fullname" (index .Subcharts "alloy")) "namespace" .Release.Namespace "hostpath" false }}
{{- include "alloySecurityContextConstraintTemplate" $data }}
{{- end }}

{{/* Create the SecurityContextConstraints for the Alloy for Cluster Events instance */}}
{{- if and .Values.logs.enabled .Values.logs.cluster_events.enabled }}
Expand Down
2 changes: 1 addition & 1 deletion charts/k8s-monitoring/templates/tests/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ queries:
{{- end }}
{{- end -}}

{{- if .Values.configAnalysis.enabled }}
{{- if and .Values.configAnalysis.enabled .Values.alloy.enabled }}
---
apiVersion: v1
kind: Pod
Expand Down
4 changes: 4 additions & 0 deletions charts/k8s-monitoring/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,10 @@ beyla:
# Settings for the Grafana Alloy instance that gathers metrics, and opens receivers for application data.
# See https://github.com/grafana/alloy/tree/main/operations/helm/charts/alloy for available values.
alloy:
# -- Deploy this Alloy instance. Only set this to false if you are not using metrics or any receivers.
# @section -- Deployment: [Alloy](https://github.com/grafana/alloy/tree/main/operations/helm/charts/alloy)
enabled: true

logging:
# -- Level at which Alloy log lines should be written.
# @section -- Deployment: [Alloy](https://github.com/grafana/alloy/tree/main/operations/helm/charts/alloy)
Expand Down
94 changes: 0 additions & 94 deletions examples/logs-journal/metrics.alloy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ff4623

Please sign in to comment.