diff --git a/charts/telegraf/README.md b/charts/telegraf/README.md index e07569da5..757828d50 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 d85de4d17..c6e071869 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 d82af165d..276ffdb94 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 ceb4af757..419d7589c 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 b6d4f216a..5852edc5a 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 8736293fb..acb4de2e3 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 8cc8dfa53..5824b928a 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 8aee842b8..059f0c3c3 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 a3ace349f..3149fa77c 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 529899976..db944c0c3 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 d621af311..f9b72017e 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"