diff --git a/charts/datadog/CHANGELOG.md b/charts/datadog/CHANGELOG.md index 4f321d683..e61e14a16 100644 --- a/charts/datadog/CHANGELOG.md +++ b/charts/datadog/CHANGELOG.md @@ -1,5 +1,9 @@ # Datadog changelog +## 3.88.0 + +* Adds env vars `DD_AGENT_IPC_PORT` and `DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL` when Otel Agent is enabled and adds flag `--sync-delay=30s` to otel agent. + ## 3.87.0 * Launch `otel-agent` with the `--core-config` switch pointing to the main agent configuration. Note that this affects the OTel Agent beta images, early beta image releases with version tag `<7.59.0-v.1.2.0` will experience issues and should remain on older helm chart versions for their deployments. For regular users not deploying the `otel-agent` beta images, this should be a NOOP. diff --git a/charts/datadog/Chart.yaml b/charts/datadog/Chart.yaml index e498fa421..63952f8db 100644 --- a/charts/datadog/Chart.yaml +++ b/charts/datadog/Chart.yaml @@ -1,7 +1,7 @@ --- apiVersion: v1 name: datadog -version: 3.87.0 +version: 3.88.0 appVersion: "7" description: Datadog Agent keywords: diff --git a/charts/datadog/README.md b/charts/datadog/README.md index ed41fc206..994cb3ad3 100644 --- a/charts/datadog/README.md +++ b/charts/datadog/README.md @@ -1,6 +1,6 @@ # Datadog -![Version: 3.87.0](https://img.shields.io/badge/Version-3.87.0-informational?style=flat-square) ![AppVersion: 7](https://img.shields.io/badge/AppVersion-7-informational?style=flat-square) +![Version: 3.88.0](https://img.shields.io/badge/Version-3.88.0-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/_container-agent.yaml b/charts/datadog/templates/_container-agent.yaml index 151e1cebd..09d5c3bbf 100644 --- a/charts/datadog/templates/_container-agent.yaml +++ b/charts/datadog/templates/_container-agent.yaml @@ -59,6 +59,16 @@ {{- include "containers-common-env" . | nindent 4 }} {{- include "fips-envvar" . | nindent 4 }} {{- include "processes-common-envs" . | nindent 4 }} + {{- if eq (include "should-enable-otel-agent" .) "true" }} + {{- if eq (include "agentIpcPort-envvar-agent-present" .) "false" }} + - name: DD_AGENT_IPC_PORT + value: "5009" + {{- end }} + {{- if eq (include "agentIpcConfigRefreshInterval-envvar-agent-present" .) "false" }} + - name: DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL + value: "60" + {{- end }} + {{- end }} {{- if .Values.datadog.logLevel }} - name: DD_LOG_LEVEL diff --git a/charts/datadog/templates/_container-otel-agent.yaml b/charts/datadog/templates/_container-otel-agent.yaml index 193748157..888854685 100644 --- a/charts/datadog/templates/_container-otel-agent.yaml +++ b/charts/datadog/templates/_container-otel-agent.yaml @@ -3,10 +3,10 @@ image: "{{ include "image-path" (dict "root" .Values "image" .Values.agents.image) }}" imagePullPolicy: {{ .Values.agents.image.pullPolicy }} {{- if eq .Values.targetSystem "linux" }} - command: ["otel-agent", "--config={{ template "datadog.otelconfPath" . }}/otel-config.yaml", "--core-config={{ template "datadog.confPath" . }}/datadog.yaml"] + command: ["otel-agent", "--config={{ template "datadog.otelconfPath" . }}/otel-config.yaml", "--core-config={{ template "datadog.confPath" . }}/datadog.yaml", "--sync-delay=30s"] {{- end -}} {{- if eq .Values.targetSystem "windows" }} - command: ["otel-agent", "-foreground", "-config={{ template "datadog.otelconfPath" . }}/otel-config.yaml", "--core-config={{ template "datadog.confPath" . }}/datadog.yaml"] + command: ["otel-agent", "-foreground", "-config={{ template "datadog.otelconfPath" . }}/otel-config.yaml", "--core-config={{ template "datadog.confPath" . }}/datadog.yaml", "--sync-delay=30s"] {{- end -}} {{ include "generate-security-context" (dict "securityContext" .Values.agents.containers.otelAgent.securityContext "targetSystem" .Values.targetSystem "seccomp" "" "kubeversion" .Capabilities.KubeVersion.Version) | indent 2 }} resources: @@ -32,6 +32,14 @@ env: {{- include "containers-common-env" . | nindent 4 }} {{- include "containers-cluster-agent-env" . | nindent 4 }} + {{- if eq (include "agentIpcPort-envvar-otel-agent-present" .) "false" }} + - name: DD_AGENT_IPC_PORT + value: "5009" + {{- end }} + {{- if eq (include "agentIpcConfigRefreshInterval-envvar-otel-agent-present" .) "false" }} + - name: DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL + value: "60" + {{- end }} {{- include "fips-envvar" . | nindent 4 }} - name: DD_LOG_LEVEL value: {{ .Values.agents.containers.otelAgent.logLevel | default .Values.datadog.logLevel | quote }} diff --git a/charts/datadog/templates/_helpers.tpl b/charts/datadog/templates/_helpers.tpl index 1d8b6819d..377747b3a 100644 --- a/charts/datadog/templates/_helpers.tpl +++ b/charts/datadog/templates/_helpers.tpl @@ -117,6 +117,77 @@ false {{- end -}} {{- end -}} +{{/* +Return whether "DD_AGENT_IPC_PORT" env var is set in otelAgent.env or datadog.env. +*/}} +{{- define "agentIpcPort-envvar-otel-agent-present" -}} +{{- $found := false -}} +{{- range .Values.agents.containers.otelAgent.env -}} +{{- if eq .name "DD_AGENT_IPC_PORT" -}} +{{- $found = true}} +{{- end -}} +{{- end -}} +{{- range .Values.datadog.env -}} +{{- if eq .name "DD_AGENT_IPC_PORT" -}} +{{- $found = true -}} +{{- end -}} +{{- end -}} +{{- if $found -}}true{{- else -}}false{{- end -}} +{{- end -}} + +{{/* +Return whether "DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL" env var is set in otelAgent.env or datadog.env. +*/}} +{{- define "agentIpcConfigRefreshInterval-envvar-otel-agent-present" -}} +{{- $found := false -}} +{{- range .Values.agents.containers.otelAgent.env -}} +{{- if eq .name "DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL" -}} +{{- $found = true}} +{{- end -}} +{{- end -}} +{{- range .Values.datadog.env -}} +{{- if eq .name "DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL" -}} +{{- $found = true -}} +{{- end -}} +{{- end -}} +{{- if $found -}}true{{- else -}}false{{- end -}} +{{- end -}} + +{{/* +Return whether "DD_AGENT_IPC_PORT" env var is set in agent.env or datadog.env. +*/}} +{{- define "agentIpcPort-envvar-agent-present" -}} +{{- $found := false -}} +{{- range .Values.agents.containers.agent.env -}} +{{- if eq .name "DD_AGENT_IPC_PORT" -}} +{{- $found = true}} +{{- end -}} +{{- end -}} +{{- range .Values.datadog.env -}} +{{- if eq .name "DD_AGENT_IPC_PORT" -}} +{{- $found = true -}} +{{- end -}} +{{- end -}} +{{- if $found -}}true{{- else -}}false{{- end -}} +{{- end -}} + +{{/* +Return whether "DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL" env var is set in agent.env or datadog.env. +*/}} +{{- define "agentIpcConfigRefreshInterval-envvar-agent-present" -}} +{{- $found := false -}} +{{- range .Values.agents.containers.agent.env -}} +{{- if eq .name "DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL" -}} +{{- $found = true}} +{{- end -}} +{{- end -}} +{{- range .Values.datadog.env -}} +{{- if eq .name "DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL" -}} +{{- $found = true -}} +{{- end -}} +{{- end -}} +{{- if $found -}}true{{- else -}}false{{- end -}} +{{- end -}} {{/* diff --git a/test/datadog/otel_agent_test.go b/test/datadog/otel_agent_test.go new file mode 100644 index 000000000..97e31b543 --- /dev/null +++ b/test/datadog/otel_agent_test.go @@ -0,0 +1,75 @@ +package datadog + +import ( + "testing" + + "github.com/stretchr/testify/assert" + appsv1 "k8s.io/api/apps/v1" + + "github.com/DataDog/helm-charts/test/common" +) + +const ( + DDAgentIpcPort = "DD_AGENT_IPC_PORT" + DDAgentIpcConfigRefreshInterval = "DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL" +) + +type ExpectedIpcEnv struct { + ipcPort string + ipcConfigRefreshInterval string +} + +func Test_otelAgentConfigs(t *testing.T) { + tests := []struct { + name string + command common.HelmCommand + assertions func(t *testing.T, manifest string, expectedIpcEnv ExpectedIpcEnv) + expectedIpcEnv ExpectedIpcEnv + }{ + { + name: "no ipc provided", + command: common.HelmCommand{ + ReleaseName: "datadog", + ChartPath: "../../charts/datadog", + ShowOnly: []string{"templates/daemonset.yaml"}, + Values: []string{"../../charts/datadog/values.yaml"}, + Overrides: map[string]string{ + "datadog.apiKeyExistingSecret": "datadog-secret", + "datadog.appKeyExistingSecret": "datadog-secret", + "datadog.otelCollector.enabled": "true", + }, + }, + expectedIpcEnv: ExpectedIpcEnv{ + ipcPort: "5009", + ipcConfigRefreshInterval: "60", + }, + assertions: verifyOtelAgentEnvVars, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + manifest, err := common.RenderChart(t, tt.command) + assert.Nil(t, err, "couldn't render template") + tt.assertions(t, manifest, tt.expectedIpcEnv) + }) + } +} + +func verifyOtelAgentEnvVars(t *testing.T, manifest string, expectedIpcEnv ExpectedIpcEnv) { + var deployment appsv1.DaemonSet + common.Unmarshal(t, manifest, &deployment) + // otel agent + otelAgentContainer, ok := getContainer(t, deployment.Spec.Template.Spec.Containers, "otel-agent") + assert.True(t, ok) + coreEnvs := getEnvVarMap(otelAgentContainer.Env) + assert.Equal(t, expectedIpcEnv.ipcPort, coreEnvs[DDAgentIpcPort]) + assert.Equal(t, expectedIpcEnv.ipcConfigRefreshInterval, coreEnvs[DDAgentIpcConfigRefreshInterval]) + + // core agent + coreAgentContainer, ok := getContainer(t, deployment.Spec.Template.Spec.Containers, "otel-agent") + assert.True(t, ok) + coreEnvs = getEnvVarMap(coreAgentContainer.Env) + assert.Equal(t, expectedIpcEnv.ipcPort, coreEnvs[DDAgentIpcPort]) + assert.Equal(t, expectedIpcEnv.ipcConfigRefreshInterval, coreEnvs[DDAgentIpcConfigRefreshInterval]) +}