From 8a7f61d043bddb5a7bfe8e139667b2266923038f Mon Sep 17 00:00:00 2001 From: Helmut Wolf <3902045+shadow1runner@users.noreply.github.com> Date: Mon, 9 Mar 2026 09:22:55 +0100 Subject: [PATCH] helm (telegraf): add {{ .Release.Namespace }} for kustomize v5.8[01] compat, closes #770 --- charts/telegraf/README.md | 2 ++ charts/telegraf/templates/NOTES.txt | 6 +++--- charts/telegraf/templates/_helpers.tpl | 11 +++++++++++ charts/telegraf/templates/configmap.yaml | 1 + charts/telegraf/templates/deployment.yaml | 1 + charts/telegraf/templates/pdb.yaml | 1 + charts/telegraf/templates/role.yaml | 4 +++- charts/telegraf/templates/rolebinding.yaml | 5 ++++- charts/telegraf/templates/service.yaml | 1 + charts/telegraf/templates/serviceaccount.yaml | 1 + charts/telegraf/values.yaml | 3 +++ 11 files changed, 31 insertions(+), 5 deletions(-) diff --git a/charts/telegraf/README.md b/charts/telegraf/README.md index e07569da..757828d5 100644 --- a/charts/telegraf/README.md +++ b/charts/telegraf/README.md @@ -65,6 +65,8 @@ To configure the chart, do either of the following: > **Tip**: Use the default [values.yaml](values.yaml). +Use `namespaceOverride` when you need the chart to render namespaced resources into a specific namespace during Helm template rendering, such as Kustomize or Argo CD workflows. + ## Telegraf configuration Telegraf configuration is generated by YAML to TOML conversion of `.Values.config` entry. diff --git a/charts/telegraf/templates/NOTES.txt b/charts/telegraf/templates/NOTES.txt index d85de4d1..c6e07186 100644 --- a/charts/telegraf/templates/NOTES.txt +++ b/charts/telegraf/templates/NOTES.txt @@ -1,14 +1,14 @@ To open a shell session in the container running Telegraf run the following: - kubectl exec -i -t --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app.kubernetes.io/name={{ include "telegraf.fullname" . }} -o jsonpath='{.items[0].metadata.name}') /bin/sh + kubectl exec -i -t --namespace {{ include "telegraf.namespace" . }} $(kubectl get pods --namespace {{ include "telegraf.namespace" . }} -l app.kubernetes.io/name={{ include "telegraf.fullname" . }} -o jsonpath='{.items[0].metadata.name}') /bin/sh To view the logs for a Telegraf pod, run the following: - kubectl logs -f --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app.kubernetes.io/name={{ include "telegraf.fullname" . }} -o jsonpath='{ .items[0].metadata.name }') + kubectl logs -f --namespace {{ include "telegraf.namespace" . }} $(kubectl get pods --namespace {{ include "telegraf.namespace" . }} -l app.kubernetes.io/name={{ include "telegraf.fullname" . }} -o jsonpath='{ .items[0].metadata.name }') {{- if eq .Values.service.type "LoadBalancer" }} To watch for the LoadBalancer IP run the following: - kubectl get svc -w --namespace {{ .Release.Namespace }} -l app.kubernetes.io/name={{ include "telegraf.fullname" . }} + kubectl get svc -w --namespace {{ include "telegraf.namespace" . }} -l app.kubernetes.io/name={{ include "telegraf.fullname" . }} {{- end }} diff --git a/charts/telegraf/templates/_helpers.tpl b/charts/telegraf/templates/_helpers.tpl index d82af165..276ffdb9 100644 --- a/charts/telegraf/templates/_helpers.tpl +++ b/charts/telegraf/templates/_helpers.tpl @@ -1,4 +1,15 @@ {{/* vim: set filetype=mustache: */}} +{{/* +Allow the release namespace to be overridden for namespaced resources. +*/}} +{{- define "telegraf.namespace" -}} +{{- if .Values.namespaceOverride -}} +{{- .Values.namespaceOverride -}} +{{- else -}} +{{- .Release.Namespace -}} +{{- end -}} +{{- end -}} + {{/* Expand the name of the chart. */}} diff --git a/charts/telegraf/templates/configmap.yaml b/charts/telegraf/templates/configmap.yaml index ceb4af75..419d7589 100644 --- a/charts/telegraf/templates/configmap.yaml +++ b/charts/telegraf/templates/configmap.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: {{ include "telegraf.fullname" . }} + namespace: {{ include "telegraf.namespace" . }} labels: {{- include "telegraf.labels" . | nindent 4 }} data: diff --git a/charts/telegraf/templates/deployment.yaml b/charts/telegraf/templates/deployment.yaml index b6d4f216..5852edc5 100644 --- a/charts/telegraf/templates/deployment.yaml +++ b/charts/telegraf/templates/deployment.yaml @@ -2,6 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "telegraf.fullname" . }} + namespace: {{ include "telegraf.namespace" . }} labels: {{- include "telegraf.labels" . | nindent 4 }} spec: diff --git a/charts/telegraf/templates/pdb.yaml b/charts/telegraf/templates/pdb.yaml index 8736293f..acb4de2e 100644 --- a/charts/telegraf/templates/pdb.yaml +++ b/charts/telegraf/templates/pdb.yaml @@ -7,6 +7,7 @@ apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: name: {{ include "telegraf.fullname" . }} + namespace: {{ include "telegraf.namespace" . }} labels: {{- include "telegraf.labels" . | nindent 4 }} spec: diff --git a/charts/telegraf/templates/role.yaml b/charts/telegraf/templates/role.yaml index 8cc8dfa5..5824b928 100644 --- a/charts/telegraf/templates/role.yaml +++ b/charts/telegraf/templates/role.yaml @@ -7,7 +7,9 @@ kind: Role {{- end }} metadata: name: {{ template "telegraf.fullname" . }} - namespace: {{ .Release.Namespace }} + {{- if not .Values.rbac.clusterWide }} + namespace: {{ include "telegraf.namespace" . }} + {{- end }} labels: {{- include "telegraf.labels" . | nindent 4 }} rules: diff --git a/charts/telegraf/templates/rolebinding.yaml b/charts/telegraf/templates/rolebinding.yaml index 8aee842b..059f0c3c 100644 --- a/charts/telegraf/templates/rolebinding.yaml +++ b/charts/telegraf/templates/rolebinding.yaml @@ -7,12 +7,15 @@ kind: RoleBinding {{- end }} metadata: name: {{ template "telegraf.fullname" . }} + {{- if not .Values.rbac.clusterWide }} + namespace: {{ include "telegraf.namespace" . }} + {{- end }} labels: {{- include "telegraf.labels" . | nindent 4 }} subjects: - kind: ServiceAccount name: {{ template "telegraf.serviceAccountName" . }} - namespace: {{ .Release.Namespace }} + namespace: {{ include "telegraf.namespace" . }} roleRef: apiGroup: rbac.authorization.k8s.io {{- if .Values.rbac.clusterWide }} diff --git a/charts/telegraf/templates/service.yaml b/charts/telegraf/templates/service.yaml index a3ace349..3149fa77 100644 --- a/charts/telegraf/templates/service.yaml +++ b/charts/telegraf/templates/service.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: Service metadata: name: {{ include "telegraf.fullname" . }} + namespace: {{ include "telegraf.namespace" . }} labels: {{- include "telegraf.labels" . | nindent 4 }} {{- if .Values.service.annotations }} diff --git a/charts/telegraf/templates/serviceaccount.yaml b/charts/telegraf/templates/serviceaccount.yaml index 52989997..db944c0c 100644 --- a/charts/telegraf/templates/serviceaccount.yaml +++ b/charts/telegraf/templates/serviceaccount.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: ServiceAccount metadata: name: {{ template "telegraf.serviceAccountName" . }} + namespace: {{ include "telegraf.namespace" . }} labels: {{- include "telegraf.labels" . | nindent 4 }} {{- if .Values.serviceAccount.annotations }} diff --git a/charts/telegraf/values.yaml b/charts/telegraf/values.yaml index d621af31..f9b72017 100644 --- a/charts/telegraf/values.yaml +++ b/charts/telegraf/values.yaml @@ -2,6 +2,9 @@ ## This is a YAML-formatted file. ## ref: https://hub.docker.com/r/library/telegraf/tags/ +# Override the namespace for namespaced resources in this chart. +namespaceOverride: "" + replicaCount: 1 image: repo: "docker.io/library/telegraf"