From a9dc437d74185e9d7b01a067bf0a70d05eb48d38 Mon Sep 17 00:00:00 2001 From: Kaushik Surya Date: Thu, 19 Dec 2024 11:33:00 -0500 Subject: [PATCH] Merge agent overlays --- .../cloudwatch-agent-custom-resource.yaml | 56 +++++++++---------- .../values.yaml | 4 +- 2 files changed, 27 insertions(+), 33 deletions(-) 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 0f57f59..a5bca18 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 @@ -47,22 +47,24 @@ data: --- {{- end -}} -{{- range $i, $customAgent := .Values.agents }} -{{- $clusterName := $.Values.clusterName | required "$.Values.clusterName is required." -}} -{{- $region := $.Values.region | required "$.Values.region is required." -}} +{{- $clusterName := .Values.clusterName | required ".Values.clusterName is required." -}} +{{- $region := .Values.region | required ".Values.region is required." -}} + +{{- range .Values.agents }} +{{- $agent := merge (deepCopy $.Values.agent) . }} apiVersion: cloudwatch.aws.amazon.com/v1alpha1 kind: AmazonCloudWatchAgent metadata: - name: {{ $customAgent.name | default (include "cloudwatch-agent.name" $) }} + name: {{ $agent.name | default (include "cloudwatch-agent.name" $) }} namespace: {{ $.Release.Namespace }} spec: - image: {{ include "cloudwatch-agent.modify-image" (merge (dict "image" $customAgent.image) $ ) }} - mode: {{ $customAgent.mode | default "daemonset" }} - replicas: {{ $customAgent.replicas | default 1 }} + image: {{ include "cloudwatch-agent.modify-image" (merge (dict "image" $agent.image) $ ) }} + mode: {{ $agent.mode }} + replicas: {{ $agent.replicas }} nodeSelector: kubernetes.io/os: linux - serviceAccount: {{ if hasKey ($customAgent.serviceAccount) "name" }}{{ $customAgent.serviceAccount.Name }}{{ else }}{{ (include "cloudwatch-agent.serviceAccountName" $) }}{{ end }} - priorityClassName: {{ $customAgent.priorityClassName | default $.Values.agent.priorityClassName }} + serviceAccount: {{ $agent.serviceAccount.name | default (include "cloudwatch-agent.serviceAccountName" $) }} + priorityClassName: {{ $agent.priorityClassName | default $.Values.agent.priorityClassName }} affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: @@ -73,41 +75,33 @@ spec: values: - fargate hostNetwork: true - {{- if $customAgent.config }} - config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" $customAgent.config) $ ) }} + {{- if $agent.config }} + config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" $agent.config) $ ) }} {{- else }} - config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" $.Values.agent.defaultConfig) $ ) }} + config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" $agent.defaultConfig) $ ) }} {{- end }} - {{- if $customAgent.otelConfig }} - otelConfig: {{ include "cloudwatch-agent.modify-yaml-config" (merge (dict "OtelConfig" $customAgent.otelConfig) . ) }} - {{ else if $.Values.agent.otelConfig }} - otelConfig: {{ include "cloudwatch-agent.modify-yaml-config" (merge (dict "OtelConfig" $.Values.agent.otelConfig) . ) }} + {{- if $agent.otelConfig }} + otelConfig: {{ include "cloudwatch-agent.modify-yaml-config" (merge (dict "OtelConfig" $agent.otelConfig) . ) }} {{- end }} - {{- if $customAgent.prometheus }} - {{- if $customAgent.prometheus.config }} + {{- if $agent.prometheus.config }} prometheus: - {{- with $customAgent.prometheus.config }} + {{- with $agent.prometheus.config }} config: {{- toYaml . | nindent 6 }} {{- end }} {{- end }} - {{- if $customAgent.prometheus.targetAllocator }} + {{- if $agent.prometheus.targetAllocator.enabled }} targetAllocator: - enabled: {{ $customAgent.prometheus.targetAllocator.enabled | default false }} - image: {{ include "target-allocator.modify-image" (merge (dict "image" $customAgent.prometheus.targetAllocator.image) $ ) }} + enabled: {{ $agent.prometheus.targetAllocator.enabled | default false }} + image: {{ include "target-allocator.modify-image" (merge (dict "image" $agent.prometheus.targetAllocator.image) $ ) }} allocationStrategy: "consistent-hashing" - {{- if $customAgent.prometheus.targetAllocator.prometheusCR }} - prometheusCR: {{ $customAgent.prometheus.targetAllocator.prometheusCR.enabled | default false }} + {{- if $agent.prometheus.targetAllocator.prometheusCR.enabled }} + prometheusCR: {{ $agent.prometheus.targetAllocator.prometheusCR.enabled | default false }} {{- end }} {{- end }} + {{- with $agent.resources }} + resources: {{- toYaml . | nindent 4}} {{- end }} - resources: - requests: - memory: {{ if and (hasKey ($customAgent.resources) "requests") (hasKey ($customAgent.resources.requests) "memory") }}{{ $customAgent.resources.requests.memory }}{{ else }}{{ $.Values.agent.resources.requests.memory }}{{ end }} - cpu: {{ if and (hasKey ($customAgent.resources) "requests") (hasKey ($customAgent.resources.requests) "cpu") }}{{ $customAgent.resources.requests.cpu }}{{ else }}{{ $.Values.agent.resources.requests.cpu }}{{ end }} - limits: - memory: {{ if and (hasKey ($customAgent.resources) "limits") (hasKey ($customAgent.resources.limits) "memory") }}{{ $customAgent.resources.limits.memory }}{{ else }}{{ $.Values.agent.resources.limits.memory }}{{ end }} - cpu: {{ if and (hasKey ($customAgent.resources) "limits") (hasKey ($customAgent.resources.limits) "cpu") }}{{ $customAgent.resources.limits.cpu }}{{ else }}{{ $.Values.agent.resources.limits.cpu }}{{ end }} volumeMounts: - mountPath: /rootfs name: rootfs diff --git a/charts/amazon-cloudwatch-observability/values.yaml b/charts/amazon-cloudwatch-observability/values.yaml index b6ad767..d87001d 100644 --- a/charts/amazon-cloudwatch-observability/values.yaml +++ b/charts/amazon-cloudwatch-observability/values.yaml @@ -1315,8 +1315,8 @@ agents: - name: cloudwatch-agent agent: name: - mode: # represents the mode the cloudwatch-agent will run in (deployment, daemonset or statefulset) - replicas: # The total number non-terminated pods targeted by this cloudwatch-agent's deployment or statefulSet. + mode: daemonset # Represents the mode the AmazonCloudWatchAgent workload will run in (deployment, daemonset or statefulset) + replicas: 1 # The total number non-terminated pods targeted by this AmazonCloudWatchAgent's deployment or statefulSet. image: repository: cloudwatch-agent tag: 1.300051.0b992