Skip to content

Commit 4b5c1d4

Browse files
authored
Honor cpu:null on the agent container resources (#334)
A consumer-supplied cpu:null on agents[].resources.limits was rendering into the AmazonCloudWatchAgent CR as a literal cpu: null, which is invalid under the CRD, instead of removing the cpu limit. The agent resources go through mergeOverwrite over the chart defaults, and sprig's mergeOverwrite keeps nil source values, so the null survived into the merged map. Add a cloudwatch-agent.pruneNulls helper that strips nil leaves from the merged resources map before rendering, so cpu:null removes the limit (matching how the fluent-bit DaemonSet, which never merges over a default, already behaves).
1 parent 4102810 commit 4b5c1d4

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

charts/amazon-cloudwatch-observability/templates/_helpers.tpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,3 +784,20 @@ winning on key collision.
784784
{{- end -}}
785785
{{- $merged | toYaml -}}
786786
{{- end -}}
787+
788+
{{/* Recursively drop nil leaves so a user-supplied `cpu: null` removes the limit instead of emitting literal null. mergeOverwrite keeps nil values from the default, so prune after merge. */}}
789+
{{- define "cloudwatch-agent.pruneNulls" -}}
790+
{{- $in := . -}}
791+
{{- $out := dict -}}
792+
{{- range $k, $v := $in -}}
793+
{{- if kindIs "map" $v -}}
794+
{{- $nested := include "cloudwatch-agent.pruneNulls" $v | fromYaml -}}
795+
{{- if $nested -}}
796+
{{- $_ := set $out $k $nested -}}
797+
{{- end -}}
798+
{{- else if not (kindIs "invalid" $v) -}}
799+
{{- $_ := set $out $k $v -}}
800+
{{- end -}}
801+
{{- end -}}
802+
{{- $out | toYaml -}}
803+
{{- end -}}

charts/amazon-cloudwatch-observability/templates/linux/cloudwatch-agent-custom-resource.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ spec:
129129
enabled: {{ $agent.prometheus.targetAllocator.prometheusCR.enabled | default false }}
130130
{{- end }}
131131
{{- end }}
132-
{{- with $agent.resources }}
132+
{{- $prunedResources := include "cloudwatch-agent.pruneNulls" $agent.resources | fromYaml }}
133+
{{- with $prunedResources }}
133134
resources: {{- toYaml . | nindent 4}}
134135
{{- end }}
135136
volumeMounts:

0 commit comments

Comments
 (0)