Mohammed Naser | f3f59a7 | 2023-01-15 21:02:04 -0500 | [diff] [blame] | 1 | {{/* |
| 2 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | you may not use this file except in compliance with the License. |
| 4 | You may obtain a copy of the License at |
| 5 | |
| 6 | http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | |
| 8 | Unless required by applicable law or agreed to in writing, software |
| 9 | distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | See the License for the specific language governing permissions and |
| 12 | limitations under the License. |
| 13 | */}} |
| 14 | |
| 15 | {{- if .Values.manifests.job_clean }} |
| 16 | {{- $envAll := . }} |
| 17 | {{- if .Values.bootstrap.enabled }} |
| 18 | |
| 19 | {{- $serviceAccountName := print "glance-clean" }} |
| 20 | {{ tuple $envAll "clean" $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }} |
| 21 | --- |
| 22 | apiVersion: rbac.authorization.k8s.io/v1 |
| 23 | kind: Role |
| 24 | metadata: |
| 25 | name: {{ $serviceAccountName }} |
| 26 | rules: |
| 27 | - apiGroups: |
| 28 | - "" |
| 29 | resources: |
| 30 | - secrets |
| 31 | verbs: |
| 32 | - get |
| 33 | - delete |
| 34 | --- |
| 35 | apiVersion: rbac.authorization.k8s.io/v1 |
| 36 | kind: RoleBinding |
| 37 | metadata: |
| 38 | name: {{ $serviceAccountName }} |
| 39 | roleRef: |
| 40 | apiGroup: rbac.authorization.k8s.io |
| 41 | kind: Role |
| 42 | name: {{ $serviceAccountName }} |
| 43 | subjects: |
| 44 | - kind: ServiceAccount |
| 45 | name: {{ $serviceAccountName }} |
| 46 | namespace: {{ $envAll.Release.Namespace }} |
| 47 | --- |
| 48 | apiVersion: batch/v1 |
| 49 | kind: Job |
| 50 | metadata: |
| 51 | name: {{ print "glance-clean" }} |
| 52 | labels: |
| 53 | {{ tuple $envAll "glance" "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" }} |
| 58 | spec: |
| 59 | template: |
| 60 | metadata: |
| 61 | labels: |
| 62 | {{ tuple $envAll "glance" "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.glance.enabled }} |
| 68 | {{ tuple $envAll "glance" | 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 .Values.storage "rbd" }} |
| 76 | - name: glance-secret-clean |
| 77 | {{ tuple $envAll "glance_storage_init" | include "helm-toolkit.snippets.image" | indent 10 }} |
| 78 | {{ tuple $envAll $envAll.Values.pod.resources.jobs.bootstrap | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} |
| 79 | {{ dict "envAll" $envAll "application" "clean" "container" "glance_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 | quote }} |
| 87 | command: |
| 88 | - /tmp/clean-secrets.sh |
| 89 | volumeMounts: |
| 90 | - name: pod-tmp |
| 91 | mountPath: /tmp |
| 92 | - name: glance-bin |
| 93 | mountPath: /tmp/clean-secrets.sh |
| 94 | subPath: clean-secrets.sh |
| 95 | readOnly: true |
| 96 | {{ end }} |
| 97 | - name: glance-image-clean |
| 98 | {{ tuple $envAll "bootstrap" | include "helm-toolkit.snippets.image" | indent 10 }} |
| 99 | {{ tuple $envAll $envAll.Values.pod.resources.jobs.bootstrap | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} |
| 100 | env: |
| 101 | {{- with $env := dict "ksUserSecret" .Values.secrets.identity.admin }} |
| 102 | {{- include "helm-toolkit.snippets.keystone_openrc_env_vars" $env | indent 12 }} |
| 103 | {{- end }} |
| 104 | command: |
| 105 | - /tmp/clean-image.sh |
| 106 | volumeMounts: |
| 107 | - name: pod-tmp |
| 108 | mountPath: /tmp |
| 109 | - name: glance-bin |
| 110 | mountPath: /tmp/clean-image.sh |
| 111 | subPath: clean-image.sh |
| 112 | readOnly: true |
| 113 | volumes: |
| 114 | - name: pod-tmp |
| 115 | emptyDir: {} |
| 116 | - name: glance-bin |
| 117 | configMap: |
| 118 | name: glance-bin |
| 119 | defaultMode: 0555 |
| 120 | {{- end }} |
| 121 | {{- end }} |