blob: d4efac5706dc2df52bde7f5ade438747b7163c08 [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{{- if .Values.manifests.job_clean }}
16{{- $envAll := . }}
17{{ if or (contains "cinder.backup.drivers.ceph" .Values.conf.cinder.DEFAULT.backup_driver) (eq "true" (include "cinder.utils.has_ceph_backend" $envAll)) }}
18
19{{- $serviceAccountName := print "cinder-clean" }}
20{{ tuple $envAll "clean" $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }}
21---
22apiVersion: rbac.authorization.k8s.io/v1
23kind: Role
24metadata:
25 name: {{ $serviceAccountName }}
26rules:
27 - apiGroups:
28 - ""
29 resources:
30 - secrets
31 verbs:
32 - get
33 - delete
34---
35apiVersion: rbac.authorization.k8s.io/v1
36kind: RoleBinding
37metadata:
38 name: {{ $serviceAccountName }}
39roleRef:
40 apiGroup: rbac.authorization.k8s.io
41 kind: Role
42 name: {{ $serviceAccountName }}
43subjects:
44 - kind: ServiceAccount
45 name: {{ $serviceAccountName }}
46 namespace: {{ $envAll.Release.Namespace }}
47---
48apiVersion: batch/v1
49kind: Job
50metadata:
51 name: {{ print "cinder-clean" }}
52 labels:
53{{ tuple $envAll "cinder" "clean" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }}
54 annotations:
55 "helm.sh/hook": pre-delete
56 "helm.sh/hook-delete-policy": hook-succeeded
57 {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
58spec:
59 template:
60 metadata:
61 labels:
62{{ tuple $envAll "cinder" "clean" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }}
63 spec:
64 serviceAccountName: {{ $serviceAccountName }}
65{{ dict "envAll" $envAll "application" "clean" | include "helm-toolkit.snippets.kubernetes_pod_security_context" | indent 6 }}
66 restartPolicy: OnFailure
67{{ if $envAll.Values.pod.tolerations.cinder.enabled }}
68{{ tuple $envAll "cinder" | include "helm-toolkit.snippets.kubernetes_tolerations" | indent 6 }}
69{{ end }}
70 nodeSelector:
71 {{ .Values.labels.job.node_selector_key }}: {{ .Values.labels.job.node_selector_value }}
72 initContainers:
73{{ tuple $envAll "clean" list | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 8 }}
74 containers:
75 {{- if eq "true" (include "cinder.utils.has_ceph_backend" $envAll) }}
76 - name: cinder-volume-rbd-secret-clean
77{{ tuple $envAll "cinder_storage_init" | include "helm-toolkit.snippets.image" | indent 10 }}
78{{ tuple $envAll $envAll.Values.pod.resources.jobs.clean | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
79{{ dict "envAll" $envAll "application" "clean" "container" "cinder_volume_rbd_secret_clean" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }}
80 env:
81 - name: NAMESPACE
82 valueFrom:
83 fieldRef:
84 fieldPath: metadata.namespace
85 - name: RBD_POOL_SECRET
86 value: {{ .Values.secrets.rbd.volume | quote }}
87 command:
88 - /tmp/clean-secrets.sh
89 volumeMounts:
90 - name: pod-tmp
91 mountPath: /tmp
92 - name: cinder-bin
93 mountPath: /tmp/clean-secrets.sh
94 subPath: clean-secrets.sh
95 readOnly: true
96 {{ end }}
97 {{- if (contains "cinder.backup.drivers.ceph" .Values.conf.cinder.DEFAULT.backup_driver) }}
98 - name: cinder-volume-backup-secret-clean
99{{ tuple $envAll "cinder_backup_storage_init" | include "helm-toolkit.snippets.image" | indent 10 }}
100{{ tuple $envAll $envAll.Values.pod.resources.jobs.clean | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
101 env:
102 - name: NAMESPACE
103 valueFrom:
104 fieldRef:
105 fieldPath: metadata.namespace
106 - name: RBD_POOL_SECRET
107 value: {{ .Values.secrets.rbd.backup | quote }}
108 command:
109 - /tmp/clean-secrets.sh
110 volumeMounts:
111 - name: pod-tmp
112 mountPath: /tmp
113 - name: cinder-bin
114 mountPath: /tmp/clean-secrets.sh
115 subPath: clean-secrets.sh
116 readOnly: true
117 {{ end }}
118 volumes:
119 - name: pod-tmp
120 emptyDir: {}
121 - name: cinder-bin
122 configMap:
123 name: cinder-bin
124 defaultMode: 0555
125{{- end }}
126{{- end }}