blob: e7f7bc187c93e9daedf8e50efb3c0bde5644f759 [file] [log] [blame]
Mohammed Naserf3f59a72023-01-15 21:02:04 -05001{{/*
2Licensed under the Apache License, Version 2.0 (the "License");
3you may not use this file except in compliance with the License.
4You may obtain a copy of the License at
5
6 http://www.apache.org/licenses/LICENSE-2.0
7
8Unless required by applicable law or agreed to in writing, software
9distributed under the License is distributed on an "AS IS" BASIS,
10WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11See the License for the specific language governing permissions and
12limitations under the License.
13*/}}
14
15{{- define "libvirtReadinessProbeTemplate" }}
16exec:
17 command:
18 - bash
19 - -c
20 - /usr/bin/virsh list
21{{- end }}
22{{- define "libvirtLivenessProbeTemplate" }}
23exec:
24 command:
25 - bash
26 - -c
27 - /usr/bin/virsh list
28{{- end }}
29
30{{- define "libvirt.daemonset" }}
31{{- $daemonset := index . 0 }}
32{{- $configMapName := index . 1 }}
33{{- $serviceAccountName := index . 2 }}
34{{- $envAll := index . 3 }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -050035{{- with $envAll }}
36
37{{- $mounts_libvirt := .Values.pod.mounts.libvirt.libvirt }}
38{{- $mounts_libvirt_init := .Values.pod.mounts.libvirt.init_container }}
39
40---
41apiVersion: apps/v1
42kind: DaemonSet
43metadata:
44 name: libvirt
45 annotations:
46 {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
47 labels:
48{{ tuple $envAll .Chart.Name $daemonset | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }}
49spec:
50 selector:
51 matchLabels:
52{{ tuple $envAll .Chart.Name $daemonset | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 6 }}
53{{ tuple $envAll $daemonset | include "helm-toolkit.snippets.kubernetes_upgrades_daemonset" | indent 2 }}
54 template:
55 metadata:
56 labels:
57{{ tuple $envAll .Chart.Name $daemonset | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }}
58 annotations:
Mohammed Naser168acc32024-01-09 17:15:26 -050059 kubectl.kubernetes.io/default-container: libvirt
Mohammed Naserf3f59a72023-01-15 21:02:04 -050060{{- dict "envAll" $envAll "podName" "libvirt-libvirt-default" "containerNames" (list "libvirt") | include "helm-toolkit.snippets.kubernetes_mandatory_access_control_annotation" | indent 8 }}
61{{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }}
62 configmap-bin-hash: {{ tuple "configmap-bin.yaml" . | include "helm-toolkit.utils.hash" }}
63 configmap-etc-hash: {{ tuple "configmap-etc.yaml" . | include "helm-toolkit.utils.hash" }}
64 spec:
65{{ dict "envAll" $envAll "application" "libvirt" | include "helm-toolkit.snippets.kubernetes_pod_security_context" | indent 6 }}
66 serviceAccountName: {{ $serviceAccountName }}
67 nodeSelector:
68 {{ .Values.labels.agent.libvirt.node_selector_key }}: {{ .Values.labels.agent.libvirt.node_selector_value }}
okozachenko1203d2cd6872023-08-31 19:53:51 +100069{{ if $envAll.Values.pod.tolerations.libvirt.enabled }}
70{{ tuple $envAll "libvirt" | include "helm-toolkit.snippets.kubernetes_tolerations" | indent 6 }}
71{{ end }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -050072 hostNetwork: true
73 hostPID: true
74 hostIPC: true
75 dnsPolicy: {{ .Values.pod.dns_policy }}
76 initContainers:
77{{ tuple $envAll "pod_dependency" $mounts_libvirt_init | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 8 }}
78{{ dict "envAll" $envAll | include "helm-toolkit.snippets.kubernetes_apparmor_loader_init_container" | indent 8 }}
79{{- if .Values.conf.ceph.enabled }}
80 {{- if empty .Values.conf.ceph.cinder.keyring }}
81 - name: ceph-admin-keyring-placement
82{{ tuple $envAll "ceph_config_helper" | include "helm-toolkit.snippets.image" | indent 10 }}
83{{ dict "envAll" $envAll "application" "libvirt" "container" "ceph_admin_keyring_placement" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }}
84 command:
85 - /tmp/ceph-admin-keyring.sh
86 volumeMounts:
87 - name: pod-tmp
88 mountPath: /tmp
89 - name: etcceph
90 mountPath: /etc/ceph
91 - name: libvirt-bin
92 mountPath: /tmp/ceph-admin-keyring.sh
93 subPath: ceph-admin-keyring.sh
94 readOnly: true
95 {{- if empty .Values.conf.ceph.admin_keyring }}
96 - name: ceph-keyring
97 mountPath: /tmp/client-keyring
98 subPath: key
99 readOnly: true
100 {{ end }}
101 {{ end }}
102 - name: ceph-keyring-placement
103{{ tuple $envAll "ceph_config_helper" | include "helm-toolkit.snippets.image" | indent 10 }}
104{{ dict "envAll" $envAll "application" "libvirt" "container" "ceph_keyring_placement" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }}
105 env:
106 - name: CEPH_CINDER_USER
107 value: "{{ .Values.conf.ceph.cinder.user }}"
108 {{- if .Values.conf.ceph.cinder.keyring }}
109 - name: CEPH_CINDER_KEYRING
110 value: "{{ .Values.conf.ceph.cinder.keyring }}"
111 {{ end }}
112 - name: LIBVIRT_CEPH_CINDER_SECRET_UUID
113 value: "{{ .Values.conf.ceph.cinder.secret_uuid }}"
114 command:
115 - /tmp/ceph-keyring.sh
116 volumeMounts:
117 - name: pod-tmp
118 mountPath: /tmp
119 - name: etcceph
120 mountPath: /etc/ceph
121 - name: libvirt-bin
122 mountPath: /tmp/ceph-keyring.sh
123 subPath: ceph-keyring.sh
124 readOnly: true
125 - name: ceph-etc
126 mountPath: /etc/ceph/ceph.conf.template
127 subPath: ceph.conf
128 readOnly: true
129{{- end }}
130 containers:
Mohammed Naser168acc32024-01-09 17:15:26 -0500131 - name: tls-sidecar
132{{ tuple $envAll "libvirt_tls_sidecar" | include "helm-toolkit.snippets.image" | indent 10 }}
133{{ tuple $envAll $envAll.Values.pod.resources.libvirt_tls_sidecar | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
134{{ dict "envAll" $envAll "application" "libvirt" "container" "libvirt_tls_sidecar" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }}
135 env:
136 - name: API_ISSUER_KIND
137 value: {{ .Values.issuers.libvirt.kind }}
138 - name: API_ISSUER_NAME
139 value: {{ .Values.issuers.libvirt.name }}
140 - name: VNC_ISSUER_KIND
141 value: {{ .Values.issuers.vencrypt.kind }}
142 - name: VNC_ISSUER_NAME
143 value: {{ .Values.issuers.vencrypt.name }}
144 - name: POD_UID
145 valueFrom:
146 fieldRef:
147 fieldPath: metadata.uid
148 - name: POD_NAME
149 valueFrom:
150 fieldRef:
151 fieldPath: metadata.name
152 - name: POD_NAMESPACE
153 valueFrom:
154 fieldRef:
155 fieldPath: metadata.namespace
156 - name: POD_IP
157 valueFrom:
158 fieldRef:
159 fieldPath: status.podIP
160 volumeMounts:
161 - name: etc-pki-qemu
162 mountPath: /etc/pki/qemu
163 - name: etc-pki-ca
164 mountPath: /etc/pki/CA
165 - name: etc-pki-libvirt
166 mountPath: /etc/pki/libvirt
167 - name: etc-pki-libvirt-vnc
168 mountPath: /etc/pki/libvirt-vnc
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500169 - name: libvirt
170{{ tuple $envAll "libvirt" | include "helm-toolkit.snippets.image" | indent 10 }}
171{{ tuple $envAll $envAll.Values.pod.resources.libvirt | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
172{{ dict "envAll" $envAll "application" "libvirt" "container" "libvirt" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500173 env:
okozachenko1203d2cd6872023-08-31 19:53:51 +1000174 {{- if .Values.conf.ceph.enabled }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500175 - name: CEPH_CINDER_USER
176 value: "{{ .Values.conf.ceph.cinder.user }}"
177 {{- if .Values.conf.ceph.cinder.keyring }}
178 - name: CEPH_CINDER_KEYRING
179 value: "{{ .Values.conf.ceph.cinder.keyring }}"
180 {{ end }}
181 - name: LIBVIRT_CEPH_CINDER_SECRET_UUID
182 value: "{{ .Values.conf.ceph.cinder.secret_uuid }}"
okozachenko1203d2cd6872023-08-31 19:53:51 +1000183 {{ end }}
184 {{- if .Values.conf.ceph.cinder.external_ceph.enabled }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500185 - name: EXTERNAL_CEPH_CINDER_USER
186 value: "{{ .Values.conf.ceph.cinder.external_ceph.user }}"
187 - name: LIBVIRT_EXTERNAL_CEPH_CINDER_SECRET_UUID
188 value: "{{ .Values.conf.ceph.cinder.external_ceph.secret_uuid }}"
189 {{ end }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500190{{ dict "envAll" . "component" "libvirt" "container" "libvirt" "type" "readiness" "probeTemplate" (include "libvirtReadinessProbeTemplate" . | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }}
191{{ dict "envAll" . "component" "libvirt" "container" "libvirt" "type" "liveness" "probeTemplate" (include "libvirtLivenessProbeTemplate" . | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }}
192 command:
193 - /tmp/libvirt.sh
194 lifecycle:
Mohammed Naser168acc32024-01-09 17:15:26 -0500195 postStart:
196 exec:
197 command:
198 - /tmp/wait-for-libvirt.sh
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500199 preStop:
200 exec:
201 command:
202 - bash
203 - -c
204 - |-
205 kill $(cat /var/run/libvirtd.pid)
206 volumeMounts:
okozachenko120314e38012023-09-01 01:40:19 +1000207 - name: etc-pki-qemu
208 mountPath: /etc/pki/qemu
Mohammed Naser168acc32024-01-09 17:15:26 -0500209 - name: etc-pki-ca
210 mountPath: /etc/pki/CA
211 - name: etc-pki-libvirt
212 mountPath: /etc/pki/libvirt
213 - name: etc-pki-libvirt-vnc
214 mountPath: /etc/pki/libvirt-vnc
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500215 - name: pod-tmp
216 mountPath: /tmp
217 - name: libvirt-bin
218 mountPath: /tmp/libvirt.sh
219 subPath: libvirt.sh
220 readOnly: true
Mohammed Naser168acc32024-01-09 17:15:26 -0500221 - name: libvirt-bin
222 mountPath: /tmp/wait-for-libvirt.sh
223 subPath: wait-for-libvirt.sh
224 readOnly: true
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500225 - name: libvirt-etc
226 mountPath: /etc/libvirt/libvirtd.conf
227 subPath: libvirtd.conf
228 readOnly: true
229 - name: libvirt-etc
230 mountPath: /etc/libvirt/qemu.conf
231 subPath: qemu.conf
232 readOnly: true
233 - name: etc-libvirt-qemu
234 mountPath: /etc/libvirt/qemu
235 - mountPath: /lib/modules
236 name: libmodules
237 readOnly: true
238 - name: var-lib-libvirt
239 mountPath: /var/lib/libvirt
240 {{- if or ( gt .Capabilities.KubeVersion.Major "1" ) ( ge .Capabilities.KubeVersion.Minor "10" ) }}
241 mountPropagation: Bidirectional
242 {{- end }}
243 - name: var-lib-nova
244 mountPath: /var/lib/nova
245 {{- if or ( gt .Capabilities.KubeVersion.Major "1" ) ( ge .Capabilities.KubeVersion.Minor "10" ) }}
246 mountPropagation: Bidirectional
247 {{- end }}
248 - name: run
249 mountPath: /run
250 - name: dev
251 mountPath: /dev
252 - name: cgroup
253 mountPath: /sys/fs/cgroup
254 - name: logs
255 mountPath: /var/log/libvirt
256 - name: machine-id
257 mountPath: /etc/machine-id
258 readOnly: true
259 {{- if .Values.conf.ceph.enabled }}
260 - name: etcceph
261 mountPath: /etc/ceph
262 {{- if or ( gt .Capabilities.KubeVersion.Major "1" ) ( ge .Capabilities.KubeVersion.Minor "10" ) }}
263 mountPropagation: Bidirectional
264 {{- end }}
265 {{- if empty .Values.conf.ceph.cinder.keyring }}
266 - name: ceph-keyring
267 mountPath: /tmp/client-keyring
268 subPath: key
269 readOnly: true
270 {{- end }}
okozachenko1203d2cd6872023-08-31 19:53:51 +1000271 {{- end }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500272 {{- if .Values.conf.ceph.cinder.external_ceph.enabled }}
273 - name: external-ceph-keyring
274 mountPath: /tmp/external-ceph-client-keyring
275 subPath: key
276 readOnly: true
277 {{- end }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500278{{ if $mounts_libvirt.volumeMounts }}{{ toYaml $mounts_libvirt.volumeMounts | indent 12 }}{{ end }}
okozachenko1203d2cd6872023-08-31 19:53:51 +1000279 {{- if .Values.pod.sidecars.libvirt_exporter }}
280 - name: libvirt-exporter
281{{ tuple $envAll "libvirt_exporter" | include "helm-toolkit.snippets.image" | indent 10 }}
282{{ tuple $envAll $envAll.Values.pod.resources.libvirt_exporter | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
283{{ dict "envAll" $envAll "application" "libvirt" "container" "libvirt_exporter" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }}
Oleksandr K.ad8f45e2024-08-09 20:18:09 +0200284 args:
285 - "--libvirt.nova"
okozachenko1203d2cd6872023-08-31 19:53:51 +1000286 ports:
287 - name: metrics
288 protocol: TCP
289 containerPort: {{ tuple "libvirt_exporter" "direct" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
290 livenessProbe:
291 httpGet:
292 path: /
293 port: metrics
294 readinessProbe:
295 httpGet:
296 path: /
297 port: metrics
298 volumeMounts:
299 - name: run
300 mountPath: /run
301 {{- if or ( gt .Capabilities.KubeVersion.Major "1" ) ( ge .Capabilities.KubeVersion.Minor "10" ) }}
302 mountPropagation: Bidirectional
303 {{- end }}
304 {{- end }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500305 volumes:
okozachenko120314e38012023-09-01 01:40:19 +1000306 - name: etc-pki-qemu
307 hostPath:
308 path: /etc/pki/qemu
Mohammed Naser168acc32024-01-09 17:15:26 -0500309 - name: etc-pki-ca
310 emptyDir: {}
311 - name: etc-pki-libvirt
312 emptyDir: {}
313 - name: etc-pki-libvirt-vnc
Yaguang Tang6d499812024-10-22 06:30:54 +0800314 hostPath:
315 path: /etc/pki/libvirt-vnc
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500316 - name: pod-tmp
317 emptyDir: {}
318 - name: libvirt-bin
319 configMap:
320 name: libvirt-bin
321 defaultMode: 0555
322 - name: libvirt-etc
323 secret:
324 secretName: {{ $configMapName }}
325 defaultMode: 0444
326 {{- if .Values.conf.ceph.enabled }}
327 - name: etcceph
328 hostPath:
329 path: /var/lib/openstack-helm/compute/libvirt
330 - name: ceph-etc
331 configMap:
332 name: {{ .Values.ceph_client.configmap }}
333 defaultMode: 0444
334 {{- if empty .Values.conf.ceph.cinder.keyring }}
335 - name: ceph-keyring
336 secret:
337 secretName: {{ .Values.ceph_client.user_secret_name }}
338 {{ end }}
okozachenko1203d2cd6872023-08-31 19:53:51 +1000339 {{ end }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500340 {{- if .Values.conf.ceph.cinder.external_ceph.enabled }}
341 - name: external-ceph-keyring
342 secret:
343 secretName: {{ .Values.conf.ceph.cinder.external_ceph.user_secret_name }}
344 {{ end }}
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500345 - name: libmodules
346 hostPath:
347 path: /lib/modules
348 - name: var-lib-libvirt
349 hostPath:
350 path: /var/lib/libvirt
351 - name: var-lib-nova
352 hostPath:
353 path: /var/lib/nova
354 - name: run
355 hostPath:
356 path: /run
357 - name: dev
358 hostPath:
359 path: /dev
360 - name: logs
361 hostPath:
362 path: /var/log/libvirt
363 - name: cgroup
364 hostPath:
365 path: /sys/fs/cgroup
366 - name: machine-id
367 hostPath:
368 path: /etc/machine-id
369 - name: etc-libvirt-qemu
370 hostPath:
371 path: /etc/libvirt/qemu
Mohammed Naserf3f59a72023-01-15 21:02:04 -0500372{{ dict "envAll" $envAll "component" "libvirt" "requireSys" true | include "helm-toolkit.snippets.kubernetes_apparmor_volumes" | indent 8 }}
373{{ if $mounts_libvirt.volumes }}{{ toYaml $mounts_libvirt.volumes | indent 8 }}{{ end }}
374{{- end }}
375{{- end }}
376
377{{- if .Values.manifests.daemonset_libvirt }}
378
379{{- $envAll := . }}
380{{- $daemonset := "libvirt" }}
381{{- $configMapName := "libvirt-etc" }}
382{{- $serviceAccountName := "libvirt" }}
383
384{{- $dependencyOpts := dict "envAll" $envAll "dependencyMixinParam" $envAll.Values.network.backend "dependencyKey" "libvirt" -}}
385{{- $_ := include "helm-toolkit.utils.dependency_resolver" $dependencyOpts | toString | fromYaml }}
386
387{{ tuple $envAll "pod_dependency" $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }}
388{{- $daemonset_yaml := list $daemonset $configMapName $serviceAccountName . | include "libvirt.daemonset" | toString | fromYaml }}
389{{- $configmap_yaml := "libvirt.configmap.etc" }}
390{{- list $daemonset $daemonset_yaml $configmap_yaml $configMapName . | include "helm-toolkit.utils.daemonset_overrides" }}
391
392{{- end }}