From 931216205b9f9ec5101eff80c3173736bbcd4c01 Mon Sep 17 00:00:00 2001 From: Jeffrey Chien Date: Fri, 24 Jan 2025 12:16:32 -0500 Subject: [PATCH] Allow both YAML string and objects to get passed in for OTEL config. (#165) --- .../templates/_helpers.tpl | 11 +++++++---- .../linux/cloudwatch-agent-custom-resource.yaml | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/charts/amazon-cloudwatch-observability/templates/_helpers.tpl b/charts/amazon-cloudwatch-observability/templates/_helpers.tpl index deb950b..0ad4ec5 100644 --- a/charts/amazon-cloudwatch-observability/templates/_helpers.tpl +++ b/charts/amazon-cloudwatch-observability/templates/_helpers.tpl @@ -46,14 +46,17 @@ Helper function to modify customer supplied agent config if ContainerInsights or {{/* Helper function to modify cloudwatch-agent YAML config */}} -{{- define "cloudwatch-agent.modify-yaml-config" -}} +{{- define "cloudwatch-agent.modify-otel-config" -}} {{- $configCopy := deepCopy .OtelConfig }} +{{- if kindIs "string" $configCopy }} + {{- $configCopy = fromYaml $configCopy }} +{{- end }} {{- range $name, $component := $configCopy }} -{{- if $component -}} +{{- if and $component (kindIs "map" $component) }} {{- range $key, $value := $component }} - {{- if (and (quote $value | empty) (not (hasKey $component $key))) }} - {{- $component = set $component $key (dict) }} + {{- if eq $value nil }} + {{- $_ := set $component $key dict }} {{- end -}} {{- end }} {{- end }} diff --git a/charts/amazon-cloudwatch-observability/templates/linux/cloudwatch-agent-custom-resource.yaml b/charts/amazon-cloudwatch-observability/templates/linux/cloudwatch-agent-custom-resource.yaml index ad93d7e..44ed29c 100644 --- a/charts/amazon-cloudwatch-observability/templates/linux/cloudwatch-agent-custom-resource.yaml +++ b/charts/amazon-cloudwatch-observability/templates/linux/cloudwatch-agent-custom-resource.yaml @@ -81,7 +81,7 @@ spec: config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" $agent.defaultConfig) $ ) }} {{- end }} {{- if $agent.otelConfig }} - otelConfig: {{ include "cloudwatch-agent.modify-yaml-config" (merge (dict "OtelConfig" $agent.otelConfig) . ) }} + otelConfig: {{ include "cloudwatch-agent.modify-otel-config" (merge (dict "OtelConfig" $agent.otelConfig) . ) }} {{- end }} {{- if $agent.prometheus.config }} prometheus: