Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target allocator #126

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build
.tmp
*.iml
.DS_Store
*.DS_Store
.idea
.attach_pid*
bin

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions charts/amazon-cloudwatch-observability/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ Name for neuron-monitor
{{- default "neuron-monitor" .Values.neuronMonitor.name }}
{{- end }}

{{/*
Get the current recommended cloudwatch agent image for a region
*/}}
{{- define "cloudwatch-agent.modify-image" -}}
{{- $repository := .Values.agent.image.repository -}}
{{- $tag := .Values.agent.image.tag -}}

{{- if (.image) }}
{{- $imageCopy := deepCopy .image }}
{{- if hasKey $imageCopy "repository" }}
{{- $repository = $imageCopy.repository -}}
{{- end -}}
{{- if hasKey $imageCopy "tag" }}
{{- $tag = $imageCopy.tag -}}
{{- end -}}
{{- end -}}

{{- $imageDomain := "" -}}
{{- $imageDomain = index .Values.agent.image.repositoryDomainMap .Values.region -}}
{{- if not $imageDomain -}}
{{- $imageDomain = .Values.agent.image.repositoryDomainMap.public -}}
{{- end -}}
{{- printf "%s/%s:%s" $imageDomain $repository $tag -}}
{{- end -}}

{{/*
Get the current recommended cloudwatch agent image for a region
*/}}
Expand All @@ -89,6 +114,31 @@ Get the current recommended cloudwatch agent operator image for a region
{{- printf "%s/%s:%s" $imageDomain .Values.manager.image.repository .Values.manager.image.tag -}}
{{- end -}}

{{/*
Get the current recommended target allocator image for a region
*/}}
{{- define "target-allocator.modify-image" -}}
{{- $repository := .Values.agent.prometheus.targetAllocator.image.repository -}}
{{- $tag := .Values.agent.prometheus.targetAllocator.image.tag -}}

{{- if (.image) }}
{{- $imageCopy := deepCopy .image }}
{{- if hasKey $imageCopy "repository" }}
{{- $repository = $imageCopy.repository -}}
{{- end -}}
{{- if hasKey $imageCopy "tag" }}
{{- $tag = $imageCopy.tag -}}
{{- end -}}
{{- end -}}

{{- $imageDomain := "" -}}
{{- $imageDomain = index .Values.agent.prometheus.targetAllocator.image.repositoryDomainMap .Values.region -}}
{{- if not $imageDomain -}}
{{- $imageDomain = .Values.agent.prometheus.targetAllocator.image.repositoryDomainMap.public -}}
{{- end -}}
{{- printf "%s/%s:%s" $imageDomain $repository $tag -}}
{{- end -}}

{{/*
Get the current recommended fluent-bit image for a region
*/}}
Expand Down
17 changes: 10 additions & 7 deletions charts/amazon-cloudwatch-observability/templates/certmanager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
subject:
organizationalUnits:
- {{ template "amazon-cloudwatch-observability.name" . }}
{{- if not .Values.admissionWebhooks.certManager.issuerRef }}
{{- if not .Values.admissionWebhooks.certManager.issuerRef }}
---
apiVersion: cert-manager.io/v1
kind: Issuer
Expand All @@ -41,10 +41,10 @@ metadata:
namespace: {{ .Release.Namespace }}
spec:
selfSigned: { }
{{- end }}
{{- end }}
{{- end }}
{{- end }}

{{- if ( .Values.agent.certManager.enabled) }}
{{- if ( .Values.agent.certManager.enabled) }}
---
apiVersion: cert-manager.io/v1
kind: Certificate
Expand All @@ -55,6 +55,9 @@ metadata:
namespace: {{ .Release.Namespace }}
spec:
dnsNames:
{{- range $i, $customAgent := .Values.agents }}
- {{( printf "%s-target-allocator-service" $customAgent.name )}}
{{- end }}
- "dcgm-exporter-service"
- "dcgm-exporter-service.amazon-cloudwatch.svc"
- "neuron-monitor-service"
Expand All @@ -63,7 +66,7 @@ spec:
kind: Issuer
name: "agent-ca"
secretName: "amazon-cloudwatch-observability-agent-cert"
{{- if not .Values.agent.certManager.issuerRef }}
{{- if not .Values.agent.certManager.issuerRef }}
---
apiVersion: cert-manager.io/v1
kind: Issuer
Expand All @@ -78,7 +81,7 @@ metadata:
namespace: {{ .Release.Namespace }}
spec:
selfSigned: { }
{{- end }}
{{- end }}
---
apiVersion: v1
kind: Secret
Expand All @@ -87,5 +90,5 @@ metadata:
{{- include "amazon-cloudwatch-observability.labels" . | nindent 4 }}
name: "amazon-cloudwatch-observability-agent-cert"
namespace: {{ .Release.Namespace }}
{{- end }}
{{- end }}

Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{{- if .Values.agent.enabled }}
{{- if and (.Values.agent.autoGenerateCert.enabled) (not .Values.agent.certManager.enabled) -}}
{{- $altNames := list ( printf "%s-service" (include "dcgm-exporter.name" .) ) ( printf "%s-service" (include "neuron-monitor.name" .) ) ( printf "%s-service.%s.svc" (include "dcgm-exporter.name" .) .Release.Namespace ) ( printf "%s-service.%s.svc" (include "neuron-monitor.name" .) .Release.Namespace ) -}}
{{- range $i, $customAgent := .Values.agents }}
{{ $altNames = append $altNames ( printf "%s-target-allocator-service" $customAgent.name )}}
{{- end }}
{{- $ca := genCA ("agent-ca") ( .Values.agent.autoGenerateCert.expiryDays | int ) -}}
{{- $cert := genSignedCert ("agent") nil $altNames ( .Values.admissionWebhooks.autoGenerateCert.expiryDays | int ) $ca -}}
apiVersion: v1
kind: Secret
metadata:
labels:
{{- include "amazon-cloudwatch-observability.labels" . | nindent 4}}
{{- include "amazon-cloudwatch-observability.labels" . | nindent 4}}
name: "amazon-cloudwatch-observability-agent-cert"
namespace: {{ .Release.Namespace }}
data:
Expand All @@ -17,37 +20,61 @@ data:
---
{{- end -}}

{{- $clusterName := .Values.clusterName | required ".Values.clusterName is required." -}}
{{- $region := .Values.region | required ".Values.region is required." -}}
{{- range $i, $customAgent := .Values.agents }}
{{- $clusterName := $.Values.clusterName | required "$.Values.clusterName is required." -}}
{{- $region := $.Values.region | required "$.Values.region is required." -}}
apiVersion: cloudwatch.aws.amazon.com/v1alpha1
kind: AmazonCloudWatchAgent
metadata:
name: {{ template "cloudwatch-agent.name" . }}
namespace: {{ .Release.Namespace }}
name: {{ $customAgent.name | default (include "cloudwatch-agent.name" $) }}
namespace: {{ $.Release.Namespace }}
spec:
image: {{ template "cloudwatch-agent.image" . }}
mode: daemonset
image: {{ include "cloudwatch-agent.modify-image" (merge (dict "image" $customAgent.image) $ ) }}
mode: {{ $customAgent.mode | default "daemonset" }}
replicas: {{ $customAgent.replicas | default 1 }}
nodeSelector:
kubernetes.io/os: linux
serviceAccount: {{ template "cloudwatch-agent.serviceAccountName" . }}
serviceAccount: {{ if hasKey ($customAgent.serviceAccount) "name" }}{{ $customAgent.serviceAccount.Name }}{{ else }}{{ (include "cloudwatch-agent.serviceAccountName" $) }}{{ end }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .Values.fargateLabelKey }}
- key: {{ $.Values.fargateLabelKey }}
operator: NotIn
values:
- fargate
hostNetwork: true
{{- if .Values.agent.config }}
config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" .Values.agent.config) . ) }}
{{- if $customAgent.config }}
config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" $customAgent.config) $ ) }}
{{- else }}
config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" .Values.agent.defaultConfig) . ) }}
config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" $.Values.agent.defaultConfig) $ ) }}
{{- end }}
{{- if $customAgent.prometheus }}
{{- if $customAgent.prometheus.config }}
prometheus:
{{- with $customAgent.prometheus.config }}
config:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end }}
{{- with .Values.agent.resources }}
resources: {{- toYaml . | nindent 4}}
{{- if $customAgent.prometheus.targetAllocator }}
targetAllocator:
enabled: {{ $customAgent.prometheus.targetAllocator.enabled | default false }}
image: {{ include "target-allocator.modify-image" (merge (dict "image" $customAgent.prometheus.targetAllocator.image) $ ) }}
allocationStrategy: "consistent-hashing"
{{- if $customAgent.prometheus.targetAllocator.prometheusCR }}
prometheusCR: {{ $customAgent.prometheus.targetAllocator.prometheusCR.enabled | default false }}
{{- end }}
{{- end }}
{{- 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
Expand Down Expand Up @@ -117,7 +144,9 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- with .Values.tolerations }}
{{- with $.Values.tolerations }}
tolerations: {{- toYaml . | nindent 2}}
{{- end }}
---
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ rules:
- apiGroups: [ "route.openshift.io" ]
resources: [ "routes", "routes/custom-host" ]
verbs: [ "create","delete","get","list","patch","update","watch" ]
- apiGroups: [ "policy" ]
resources: [ "poddisruptionbudgets" ]
verbs: [ "create","delete","get","list","patch","update","watch" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- if .Values.agent.enabled }}
{{- range $i, $customAgent := .Values.agents }}
{{- if and (and (hasKey ($customAgent.prometheus) "targetAllocator") (hasKey ($customAgent.prometheus.targetAllocator) "enabled")) $customAgent.prometheus.targetAllocator.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
{{- include "amazon-cloudwatch-observability.labels" $ | nindent 4}}
name: "cloudwatch-agent-target-allocator-role"
rules:
- apiGroups: [ "" ]
resources: [ "pods", "nodes", "nodes/metrics", "services", "endpoints" ]
verbs: [ "list", "watch", "get" ]
- apiGroups: [ "" ]
resources: [ "configmaps" ]
verbs: [ "get" ]
- apiGroups: ["discovery.k8s.io"]
resources: ["endpointslices"]
verbs: ["get", "list", "watch"]
- apiGroups: [ "networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get", "list", "watch"]
- nonResourceURLs: ["/metrics"]
verbs: ["get"]
{{- if and (hasKey ($customAgent.prometheus.targetAllocator) "PrometheusCR") $customAgent.prometheus.targetAllocator.PrometheusCR.enabled }}
- apiGroups: [ "monitoring.coreos.com"]
resources: ["podmonitors", "servicemonitors"]
verbs: ["get", "list", "watch"]
{{- end }}
{{- end }}
---
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if .Values.agent.enabled }}
{{- range $i, $customAgent := .Values.agents }}
{{- if and (and (hasKey ($customAgent.prometheus) "targetAllocator") (hasKey ($customAgent.prometheus.targetAllocator) "enabled")) $customAgent.prometheus.targetAllocator.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
{{- include "amazon-cloudwatch-observability.labels" $ | nindent 4 }}
name: "cloudwatch-agent-target-allocator-rolebinding"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: "cloudwatch-agent-target-allocator-role"
subjects:
- kind: ServiceAccount
name: "target-allocator-service-acct"
namespace: {{ $.Release.Namespace }}
{{- end }}
---
{{- end }}
{{- end }}
37 changes: 37 additions & 0 deletions charts/amazon-cloudwatch-observability/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,14 @@ admissionWebhooks:
## Secret labels
secretLabels: { }

## List of AmazonCloudWatchAgent workloads to install & manage, each representing an independent installation of the AmazonCloudWatchAgent CustomResource. Each entry in this list uses the schema & the defaults from $.agent, so only provide any overrides here.
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.
image:
repository: cloudwatch-agent
tag: 1.300045.1b823
Expand Down Expand Up @@ -602,6 +608,37 @@ agent:
}
}
}
windowsDefaultConfig:
{
"logs": {
"metrics_collected": {
"kubernetes": {
"enhanced_container_insights": true
},
"application_signals": { }
}
},
"traces": {
"traces_collected": {
"application_signals": { }
}
}
}
prometheus:
config:
targetAllocator:
enabled: false
image:
repository: cloudwatch-agent-target-allocator
tag: latest
repositoryDomainMap:
public: public.ecr.aws/cloudwatch-agent
cn-north-1: 934860584483.dkr.ecr.cn-north-1.amazonaws.com.cn
cn-northwest-1: 934860584483.dkr.ecr.cn-northwest-1.amazonaws.com.cn
us-gov-east-1: 743662458514.dkr.ecr.us-gov-east-1.amazonaws.com
us-gov-west-1: 743662458514.dkr.ecr.us-gov-west-1.amazonaws.com
prometheusCR:
enabled: false

dcgmExporter:
name:
Expand Down