blob: af822572acd0070e0678e5b88e0cbd2b17bd6bfd [file] [log] [blame]
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001{{/*
2Expand the name of the chart.
3*/}}
4{{- define "vector.name" -}}
5{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6{{- end }}
7
8{{/*
9Create a default fully qualified app name.
10We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11If release name contains chart name it will be used as a full name.
12*/}}
13{{- define "vector.fullname" -}}
14{{- if .Values.fullnameOverride }}
15{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16{{- else }}
17{{- $name := default .Chart.Name .Values.nameOverride }}
18{{- if contains $name .Release.Name }}
19{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20{{- else }}
21{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22{{- end }}
23{{- end }}
24{{- end }}
25
26{{/*
27Create chart name and version as used by the chart label.
28*/}}
29{{- define "vector.chart" -}}
30{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31{{- end }}
32
33{{/*
34Common labels.
35*/}}
36{{- define "vector.labels" -}}
37helm.sh/chart: {{ include "vector.chart" . }}
38{{ include "vector.selectorLabels" . }}
39{{- if .Chart.AppVersion }}
40app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }}
41{{- end }}
42app.kubernetes.io/managed-by: {{ .Release.Service }}
43{{ with .Values.commonLabels }}
44{{- toYaml . -}}
45{{- end }}
46{{- end }}
47
48{{/*
49Selector labels.
50*/}}
51{{- define "vector.selectorLabels" -}}
52app.kubernetes.io/name: {{ include "vector.name" . }}
53app.kubernetes.io/instance: {{ .Release.Name }}
54{{- if or (ne .Values.role "Agent") (ne .Values.role "Aggregator") (ne .Values.role "Stateless-Aggregator") }}
55app.kubernetes.io/component: {{ .Values.role }}
56{{- end }}
57{{- end }}
58
59{{/*
60Create the name of the service account to use.
61*/}}
62{{- define "vector.serviceAccountName" -}}
63{{- if .Values.serviceAccount.create }}
64{{- default (include "vector.fullname" .) .Values.serviceAccount.name }}
65{{- else }}
66{{- default "default" .Values.serviceAccount.name }}
67{{- end }}
68{{- end }}
69
70{{/*
71Return the appropriate apiVersion for PodDisruptionBudget policy APIs.
72*/}}
73{{- define "policy.poddisruptionbudget.apiVersion" -}}
74{{- if or (.Capabilities.APIVersions.Has "policy/v1/PodDisruptionBudget") (semverCompare ">=1.21" .Capabilities.KubeVersion.Version) -}}
75"policy/v1"
76{{- else -}}
77"policy/v1beta1"
78{{- end -}}
79{{- end -}}
80
81{{/*
82Return the appropriate apiVersion for HPA autoscaling APIs.
83*/}}
84{{- define "autoscaling.apiVersion" -}}
85{{- if or (.Capabilities.APIVersions.Has "autoscaling/v2/HorizontalPodAutoscaler") (semverCompare ">=1.23" .Capabilities.KubeVersion.Version) -}}
86"autoscaling/v2"
87{{- else -}}
88"autoscaling/v2beta2"
89{{- end -}}
90{{- end -}}
91
92{{/*
93Generate an array of ServicePorts based on `.Values.customConfig`.
94*/}}
95{{- define "vector.ports" -}}
96 {{- range $componentKind, $components := .Values.customConfig }}
97 {{- if eq $componentKind "sources" }}
98 {{- tuple $components "_helper.generatePort" | include "_helper.componentIter" }}
99 {{- else if eq $componentKind "sinks" }}
100 {{- tuple $components "_helper.generatePort" | include "_helper.componentIter" }}
101 {{- else if eq $componentKind "api" }}
102 {{- if $components.enabled }}
103- name: api
104 port: {{ mustRegexFind "[0-9]+$" (get $components "address") }}
105 protocol: TCP
106 targetPort: {{ mustRegexFind "[0-9]+$" (get $components "address") }}
107 {{- end }}
108 {{- end }}
109 {{- end }}
110{{- end }}
111
112{{/*
113Iterate over the components defined in `.Values.customConfig`.
114*/}}
115{{- define "_helper.componentIter" -}}
116{{- $components := index . 0 }}
117{{- $helper := index . 1 }}
118 {{- range $id, $options := $components }}
119 {{- if (hasKey $options "address") }}
120 {{- tuple $id $options | include $helper -}}
121 {{- end }}
122 {{- end }}
123{{- end }}
124
125{{/*
126Generate a single ServicePort based on a component configuration.
127*/}}
128{{- define "_helper.generatePort" -}}
129{{- $name := index . 0 | kebabcase -}}
130{{- $config := index . 1 -}}
131{{- $port := mustRegexFind "[0-9]+$" (get $config "address") -}}
132{{- $protocol := default "TCP" (get $config "mode" | upper) }}
133- name: {{ $name }}
134 port: {{ $port }}
135 protocol: {{ $protocol }}
136 targetPort: {{ $port }}
137{{- if not (mustHas $protocol (list "TCP" "UDP")) }}
138{{ fail "Component's `mode` is not a supported protocol, please raise a issue at https://github.com/vectordotdev/vector" }}
139{{- end }}
140{{- end }}
141
142{{/*
143Generate an array of ContainerPorts based on `.Values.customConfig`.
144*/}}
145{{- define "vector.containerPorts" -}}
146 {{- range $componentKind, $components := .Values.customConfig }}
147 {{- if eq $componentKind "sources" }}
148 {{- tuple $components "_helper.generateContainerPort" | include "_helper.componentIter" }}
149 {{- else if eq $componentKind "sinks" }}
150 {{- tuple $components "_helper.generateContainerPort" | include "_helper.componentIter" }}
151 {{- else if eq $componentKind "api" }}
152 {{- if $components.enabled }}
153- name: api
154 containerPort: {{ mustRegexFind "[0-9]+$" (get $components "address") }}
155 protocol: TCP
156 {{- end }}
157 {{- end }}
158 {{- end }}
159{{- end }}
160
161{{/*
162Generate a single ContainerPort based on a component configuration.
163*/}}
164{{- define "_helper.generateContainerPort" -}}
165{{- $name := index . 0 | kebabcase -}}
166{{- $config := index . 1 -}}
167{{- $port := mustRegexFind "[0-9]+$" (get $config "address") -}}
168{{- $protocol := default "TCP" (get $config "mode" | upper) }}
169- name: {{ $name | trunc 15 | trimSuffix "-" }}
170 containerPort: {{ $port }}
171 protocol: {{ $protocol }}
172{{- if not (mustHas $protocol (list "TCP" "UDP")) }}
173{{ fail "Component's `mode` is not a supported protocol, please raise a issue at https://github.com/vectordotdev/vector" }}
174{{- end }}
175{{- end }}
176
177{{/*
178Print Vector's logo.
179*/}}
180{{- define "_logo" -}}
181{{ print "__ __ __" }}
182{{ print "\\ \\ / / / /" }}
183{{ print " \\ V / / / " }}
184{{ print " \\_/ \\/ " }}
185{{ print "V E C T O R" }}
186{{- end }}
187
188{{/*
189Print line divider.
190*/}}
191{{- define "_divider" -}}
192{{ print "--------------------------------------------------------------------------------" }}
193{{- end }}
194
195{{/*
196Print `vector top` instructions.
197*/}}
198{{- define "_vector.top" -}}
199 {{- if eq "true" (include "_vector.apiEnabled" $) -}}
200{{ print "Vector is starting in your cluster. After a few minutes, you can use Vector's" }}
201{{ println "API to view internal metrics by running:" }}
202 {{- $resource := include "_vector.role" $ -}}
203 {{- $url := include "_vector.url" $ }}
204 $ kubectl -n {{ $.Release.Namespace }} exec -it {{ $resource }}/{{ include "vector.fullname" $ }} -- vector top {{ $url }}
205 {{- else -}}
206 {{- $resource := include "_vector.role" $ -}}
207{{ print "Vector is starting in your cluster. After a few minutes, you can view Vector's" }}
208{{ println "internal logs by running:" }}
209 $ kubectl -n {{ $.Release.Namespace }} logs -f {{ $resource }}/{{ include "vector.fullname" $ }}
210 {{- end }}
211{{- end }}
212
213{{/*
214Return `true` if we can determine if Vector's API is enabled.
215*/}}
216{{- define "_vector.apiEnabled" -}}
217 {{- if $.Values.existingConfigMaps -}}
218false
219 {{- else if $.Values.customConfig -}}
220 {{- if $.Values.customConfig.api -}}
221 {{- if $.Values.customConfig.api.enabled -}}
222true
223 {{- end }}
224 {{- end }}
225 {{- else -}}
226true
227 {{- end }}
228{{- end }}
229
230{{/*
231Return Vector's Resource type based on its `.Values.role`.
232*/}}
233{{- define "_vector.role" -}}
234 {{- if eq $.Values.role "Stateless-Aggregator" -}}
235deployment
236 {{- else if eq $.Values.role "Agent" -}}
237daemonset
238 {{- else -}}
239statefulset
240 {{- end -}}
241{{- end }}
242
243{{/*
244Print the `url` option for the Vector command.
245*/}}
246{{- define "_vector.url" -}}
247 {{- if $.Values.customConfig -}}
248 {{- if $.Values.customConfig.api -}}
249 {{- if $.Values.customConfig.api.address -}}
250{{ print "\\" }}
251 --url {{ printf "http://%s/graphql" $.Values.customConfig.api.address }}
252 {{- end }}
253 {{- end }}
254 {{- end }}
255{{- end }}
256
257{{/*
258Configuring Datadog Agents to forward to Vector.
259This is really alpha level, and should be refactored
260to be more generally usable for other components.
261*/}}
262{{- define "_configure.datadog" -}}
263{{- $hasSourceDatadogAgent := false }}
264{{- $sourceDatadogAgentPort := "" }}
265{{- $hasTls := "" }}
266{{- $protocol := "http" }}
267{{- range $componentKind, $configs := .Values.customConfig }}
268 {{- if eq $componentKind "sources" }}
269 {{- range $componentId, $componentConfig := $configs }}
270 {{- if eq (get $componentConfig "type") "datadog_agent" }}
271 {{- $hasSourceDatadogAgent = true }}
272 {{- $sourceDatadogAgentPort = mustRegexFind "[0-9]+$" (get $componentConfig "address") }}
273 {{- if (hasKey $componentConfig "tls") }}
274 {{- $tlsOpts := get $componentConfig "tls" }}
275 {{- $hasTls = get $tlsOpts "enabled" }}
276 {{- if $hasTls }}{{ $protocol = "https" }}{{ end }}
277 {{- end }}
278 {{- end }}
279 {{- end }}
280 {{- end }}
281{{- end }}
282{{- if or (not .Values.customConfig) (and .Values.customConfig $hasSourceDatadogAgent) }}
283{{- template "_divider" }}
284
285{{ print "datadog_agent:" }}
286
287To forward logs from Datadog Agents deployed with the "datadog" Helm chart,
288include the following in the "values.yaml" for your "datadog" chart:
289
290For Datadog Agents version "7.34"/"6.34" or lower:
291
292datadog:
293 containerExclude: "name:vector"
294 logs:
295 enabled: true
296 containerCollectAll: true
297agents:
298 useConfigMap: true
299 customAgentConfig:
300 kubelet_tls_verify: false
301 logs_config:
302 {{- if .Values.haproxy.enabled }}
303 logs_dd_url: "{{ include "haproxy.fullname" $ }}.{{ $.Release.Namespace }}:{{ $sourceDatadogAgentPort | default "8282" }}"
304 {{- else }}
305 logs_dd_url: "{{ include "vector.fullname" $ }}.{{ $.Release.Namespace }}:{{ $sourceDatadogAgentPort | default "8282" }}"
306 {{- end }}
307 {{- if $hasTls }}
308 logs_no_ssl: false
309 {{- else }}
310 logs_no_ssl: true
311 {{- end }}
312 use_http: true
313{{- end }}
314
315For Datadog Agents version "7.35"/"6.35" or greater:
316
317datadog:
318 containerExclude: "name:vector"
319 logs:
320 enabled: true
321 containerCollectAll: true
322agents:
323 useConfigMap: true
324 customAgentConfig:
325 kubelet_tls_verify: false
326 vector:
327 logs:
328 enabled: true
329 {{- if .Values.haproxy.enabled }}
330 url: "{{ $protocol }}://{{ include "haproxy.fullname" $ }}.{{ $.Release.Namespace }}:{{ $sourceDatadogAgentPort | default "8282" }}"
331 {{- else }}
332 url: "{{ $protocol }}://{{ include "vector.fullname" $ }}.{{ $.Release.Namespace }}:{{ $sourceDatadogAgentPort | default "8282" }}"
333 {{- end }}
334 metrics:
335 enabled: true
336 {{- if .Values.haproxy.enabled }}
337 url: "{{ $protocol }}://{{ include "haproxy.fullname" $ }}.{{ $.Release.Namespace }}:{{ $sourceDatadogAgentPort | default "8282" }}"
338 {{- else }}
339 url: "{{ $protocol }}://{{ include "vector.fullname" $ }}.{{ $.Release.Namespace }}:{{ $sourceDatadogAgentPort | default "8282" }}"
340 {{- end }}
341{{- end }}