From e18b2b760aff7b7fc0d4fdd831f60417e22af4a8 Mon Sep 17 00:00:00 2001 From: Liliya Belaus <59583867+liliyadd@users.noreply.github.com> Date: Tue, 21 Nov 2023 18:35:51 -0500 Subject: [PATCH] [APM Onboarding] Disable APM Instrumentation on Datadog namespace (#1252) * Disable APM Instrumentation on Datadog namespace * Add empty line to .helpers * Normalize disabledNamespaces to list * Remove datadog namespace from enabledNamespaces list * Fix usage of .Release.Namespace * Fix enabledNamespaces option * Revert values.yaml to correct default values --- charts/datadog/CHANGELOG.md | 4 +++ charts/datadog/Chart.yaml | 2 +- charts/datadog/README.md | 2 +- charts/datadog/templates/_helpers.tpl | 32 +++++++++++++++++++ .../templates/cluster-agent-deployment.yaml | 10 +++--- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/charts/datadog/CHANGELOG.md b/charts/datadog/CHANGELOG.md index 831512bf2..2432b5b10 100644 --- a/charts/datadog/CHANGELOG.md +++ b/charts/datadog/CHANGELOG.md @@ -1,5 +1,9 @@ # Datadog changelog +## 3.49.4 + +* Exclude a namespace with Datadog resources from APM Single Step Instrumentation + ## 3.49.3 * Fix NOTES warning for APM Instrumentation when apm.intrumentation.disabledNamespaces is set diff --git a/charts/datadog/Chart.yaml b/charts/datadog/Chart.yaml index d7c915a6a..8818971e2 100644 --- a/charts/datadog/Chart.yaml +++ b/charts/datadog/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: datadog -version: 3.49.3 +version: 3.49.4 appVersion: "7" description: Datadog Agent keywords: diff --git a/charts/datadog/README.md b/charts/datadog/README.md index 992731db2..5f90040db 100644 --- a/charts/datadog/README.md +++ b/charts/datadog/README.md @@ -1,6 +1,6 @@ # Datadog -![Version: 3.49.3](https://img.shields.io/badge/Version-3.49.3-informational?style=flat-square) ![AppVersion: 7](https://img.shields.io/badge/AppVersion-7-informational?style=flat-square) +![Version: 3.49.4](https://img.shields.io/badge/Version-3.49.4-informational?style=flat-square) ![AppVersion: 7](https://img.shields.io/badge/AppVersion-7-informational?style=flat-square) [Datadog](https://www.datadoghq.com/) is a hosted infrastructure monitoring platform. This chart adds the Datadog Agent to all nodes in your cluster via a DaemonSet. It also optionally depends on the [kube-state-metrics chart](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics). For more information about monitoring Kubernetes with Datadog, please refer to the [Datadog documentation website](https://docs.datadoghq.com/agent/basic_agent_usage/kubernetes/). diff --git a/charts/datadog/templates/_helpers.tpl b/charts/datadog/templates/_helpers.tpl index c4ff5b076..79374a457 100644 --- a/charts/datadog/templates/_helpers.tpl +++ b/charts/datadog/templates/_helpers.tpl @@ -893,3 +893,35 @@ Create RBACs for custom resources false {{- end -}} {{- end -}} + +{{/* +Return all namespaces with enabled Single Step Instrumentation. If instrumentation.enabledNamespaces contains the namespace where Datadog is installed, +it will be removed. +*/}} +{{- define "apmInstrumentation.enabledNamespaces" -}} +{{- if and .Values.datadog.apm .Values.datadog.apm.instrumentation -}} +{{- if and .Values.datadog.apm.instrumentation.enabledNamespaces (not .Values.datadog.apm.instrumentation.enabled) -}} +{{- if has .Release.Namespace .Values.datadog.apm.instrumentation.enabledNamespaces -}} +{{- $ns := mustWithout .Values.datadog.apm.instrumentation.enabledNamespaces .Release.Namespace -}} +{{- if $ns -}} +{{- $ns | toJson | quote -}} +{{- end -}} +{{- else -}} +{{- .Values.datadog.apm.instrumentation.enabledNamespaces | toJson | quote -}} +{{- end -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Return all namespaces with disabled Single Step Instrumentation +*/}} +{{- define "apmInstrumentation.disabledNamespaces" -}} +{{- if and .Values.datadog.apm .Values.datadog.apm.instrumentation -}} +{{- if and .Values.datadog.apm.instrumentation.disabledNamespaces .Values.datadog.apm.instrumentation.enabled -}} +{{- append .Values.datadog.apm.instrumentation.disabledNamespaces .Release.Namespace | toJson | quote -}} +{{- else if .Values.datadog.apm.instrumentation.enabled -}} +{{- list .Release.Namespace | toJson | quote -}} +{{- end -}} +{{- end -}} +{{- end -}} diff --git a/charts/datadog/templates/cluster-agent-deployment.yaml b/charts/datadog/templates/cluster-agent-deployment.yaml index 78364db0b..b2ab539ff 100644 --- a/charts/datadog/templates/cluster-agent-deployment.yaml +++ b/charts/datadog/templates/cluster-agent-deployment.yaml @@ -236,17 +236,17 @@ spec: {{- end }} - name: DD_REMOTE_CONFIGURATION_ENABLED value: {{ include "clusterAgent-remoteConfiguration-enabled" . | quote }} - {{- if .Values.datadog.apm.instrumentation.enabled }} + {{- if .Values.datadog.apm.instrumentation.enabled }} - name: DD_APM_INSTRUMENTATION_ENABLED value: "true" {{- end }} - {{- if .Values.datadog.apm.instrumentation.enabledNamespaces }} + {{- if ne (include "apmInstrumentation.enabledNamespaces" .) "" }} - name: DD_APM_INSTRUMENTATION_ENABLED_NAMESPACES - value: {{ .Values.datadog.apm.instrumentation.enabledNamespaces | toJson | quote }} + value: {{ include "apmInstrumentation.enabledNamespaces" . }} {{- end }} - {{- if .Values.datadog.apm.instrumentation.disabledNamespaces }} + {{- if ne (include "apmInstrumentation.disabledNamespaces" .) "" }} - name: DD_APM_INSTRUMENTATION_DISABLED_NAMESPACES - value: {{ .Values.datadog.apm.instrumentation.disabledNamespaces | toJson | quote }} + value: {{ include "apmInstrumentation.disabledNamespaces" . }} {{- end }} {{- if .Values.datadog.apm.instrumentation.libVersions }} - name: DD_APM_INSTRUMENTATION_LIB_VERSIONS