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_storage_init }} |
| 16 | {{- $envAll := . }} |
| 17 | |
| 18 | {{- $internal_ceph_backend := .Values.ceph_client.internal_ceph_backend }} |
| 19 | |
| 20 | {{- $serviceAccountName := "cinder-storage-init" }} |
| 21 | {{ tuple $envAll "storage_init" $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }} |
| 22 | --- |
| 23 | apiVersion: rbac.authorization.k8s.io/v1 |
| 24 | kind: Role |
| 25 | metadata: |
| 26 | name: {{ $serviceAccountName }} |
| 27 | rules: |
| 28 | - apiGroups: |
| 29 | - "" |
| 30 | resources: |
| 31 | - secrets |
| 32 | verbs: |
| 33 | - get |
| 34 | - create |
| 35 | - update |
| 36 | - patch |
| 37 | --- |
| 38 | apiVersion: rbac.authorization.k8s.io/v1 |
| 39 | kind: RoleBinding |
| 40 | metadata: |
| 41 | name: {{ $serviceAccountName }} |
| 42 | roleRef: |
| 43 | apiGroup: rbac.authorization.k8s.io |
| 44 | kind: Role |
| 45 | name: {{ $serviceAccountName }} |
| 46 | subjects: |
| 47 | - kind: ServiceAccount |
| 48 | name: {{ $serviceAccountName }} |
| 49 | namespace: {{ $envAll.Release.Namespace }} |
| 50 | --- |
| 51 | apiVersion: batch/v1 |
| 52 | kind: Job |
| 53 | metadata: |
| 54 | name: cinder-storage-init |
| 55 | labels: |
| 56 | {{ tuple $envAll "cinder" "storage-init" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} |
Mohammed Naser | feec995 | 2023-01-31 22:39:07 +0000 | [diff] [blame] | 57 | annotations: |
| 58 | {{- if .Values.helm3_hook }} |
| 59 | "helm.sh/hook": post-install,post-upgrade |
| 60 | "helm.sh/hook-delete-policy": before-hook-creation |
| 61 | {{- end }} |
Mohammed Naser | f3f59a7 | 2023-01-15 21:02:04 -0500 | [diff] [blame] | 62 | spec: |
| 63 | template: |
| 64 | metadata: |
| 65 | labels: |
| 66 | {{ tuple $envAll "cinder" "storage-init" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} |
| 67 | spec: |
| 68 | serviceAccountName: {{ $serviceAccountName }} |
| 69 | {{ dict "envAll" $envAll "application" "cinder" | include "helm-toolkit.snippets.kubernetes_pod_security_context" | indent 6 }} |
| 70 | restartPolicy: OnFailure |
| 71 | {{ if $envAll.Values.pod.tolerations.cinder.enabled }} |
| 72 | {{ tuple $envAll "cinder" | include "helm-toolkit.snippets.kubernetes_tolerations" | indent 6 }} |
| 73 | {{ end }} |
| 74 | nodeSelector: |
| 75 | {{ .Values.labels.job.node_selector_key }}: {{ .Values.labels.job.node_selector_value }} |
| 76 | initContainers: |
| 77 | {{ tuple $envAll "storage_init" list | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 8 }} |
| 78 | {{- if eq "true" (include "cinder.utils.has_ceph_backend" $envAll) }} |
| 79 | - name: ceph-keyring-placement |
| 80 | {{ tuple $envAll "cinder_storage_init" | include "helm-toolkit.snippets.image" | indent 10 }} |
| 81 | securityContext: |
| 82 | runAsUser: 0 |
| 83 | command: |
| 84 | - /tmp/ceph-admin-keyring.sh |
| 85 | volumeMounts: |
| 86 | - name: pod-tmp |
| 87 | mountPath: /tmp |
| 88 | - name: etcceph |
| 89 | mountPath: /etc/ceph |
| 90 | - name: cinder-bin |
| 91 | mountPath: /tmp/ceph-admin-keyring.sh |
| 92 | subPath: ceph-admin-keyring.sh |
| 93 | readOnly: true |
| 94 | {{- if empty .Values.conf.ceph.admin_keyring }} |
| 95 | - name: ceph-keyring |
| 96 | mountPath: /tmp/client-keyring |
| 97 | subPath: key |
| 98 | readOnly: true |
| 99 | {{ end }} |
| 100 | {{ end }} |
| 101 | containers: |
| 102 | {{- range $name, $backend := .Values.conf.backends }} |
| 103 | {{- if (eq "true" ( dict "backend" $backend | include "cinder.utils.is_ceph_backend" )) }} |
| 104 | {{- if eq $internal_ceph_backend $name }} |
Mohammed Naser | c50c946 | 2023-02-23 18:38:47 +0000 | [diff] [blame] | 105 | - name: cinder-storage-init-{{ $name | lower }} |
Mohammed Naser | f3f59a7 | 2023-01-15 21:02:04 -0500 | [diff] [blame] | 106 | {{ tuple $envAll "cinder_storage_init" | include "helm-toolkit.snippets.image" | indent 10 }} |
| 107 | {{ tuple $envAll $envAll.Values.pod.resources.jobs.storage_init | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} |
| 108 | env: |
| 109 | - name: NAMESPACE |
| 110 | valueFrom: |
| 111 | fieldRef: |
| 112 | fieldPath: metadata.namespace |
| 113 | - name: STORAGE_BACKEND |
| 114 | value: {{ $backend.volume_driver | quote }} |
| 115 | - name: RBD_POOL_NAME |
| 116 | value: {{ $backend.rbd_pool | quote }} |
| 117 | - name: RBD_POOL_APP_NAME |
| 118 | value: {{ (index $envAll.Values.conf.ceph.pools $backend.rbd_pool).app_name | quote }} |
| 119 | - name: RBD_POOL_USER |
| 120 | value: {{ $backend.rbd_user | quote }} |
| 121 | - name: RBD_POOL_CRUSH_RULE |
| 122 | value: {{ (index $envAll.Values.conf.ceph.pools $backend.rbd_pool).crush_rule | quote }} |
| 123 | - name: RBD_POOL_REPLICATION |
| 124 | value: {{ (index $envAll.Values.conf.ceph.pools $backend.rbd_pool).replication | quote }} |
| 125 | - name: RBD_POOL_CHUNK_SIZE |
| 126 | value: {{ (index $envAll.Values.conf.ceph.pools $backend.rbd_pool).chunk_size | quote }} |
| 127 | - name: RBD_POOL_SECRET |
| 128 | value: {{ $envAll.Values.secrets.rbd.volume | quote }} |
| 129 | command: |
| 130 | - /tmp/storage-init.sh |
| 131 | volumeMounts: |
| 132 | - name: pod-tmp |
| 133 | mountPath: /tmp |
| 134 | - name: cinder-bin |
| 135 | mountPath: /tmp/storage-init.sh |
| 136 | subPath: storage-init.sh |
| 137 | readOnly: true |
| 138 | - name: etcceph |
| 139 | mountPath: /etc/ceph |
| 140 | - name: ceph-etc |
| 141 | mountPath: /etc/ceph/ceph.conf |
| 142 | subPath: ceph.conf |
| 143 | readOnly: true |
| 144 | {{- if empty $envAll.Values.conf.ceph.admin_keyring }} |
| 145 | - name: ceph-keyring |
| 146 | mountPath: /tmp/client-keyring |
| 147 | subPath: key |
| 148 | readOnly: true |
| 149 | {{- end }} |
| 150 | {{- end }} |
| 151 | {{- end }} |
| 152 | {{- end }} |
| 153 | volumes: |
| 154 | - name: pod-tmp |
| 155 | emptyDir: {} |
| 156 | - name: cinder-bin |
| 157 | configMap: |
| 158 | name: cinder-bin |
| 159 | defaultMode: 0555 |
| 160 | {{- if eq "true" (include "cinder.utils.has_ceph_backend" $envAll) }} |
| 161 | - name: etcceph |
| 162 | emptyDir: {} |
| 163 | - name: ceph-etc |
| 164 | configMap: |
| 165 | name: {{ .Values.ceph_client.configmap }} |
| 166 | defaultMode: 0444 |
| 167 | {{- if empty .Values.conf.ceph.admin_keyring }} |
| 168 | - name: ceph-keyring |
| 169 | secret: |
| 170 | secretName: {{ .Values.ceph_client.user_secret_name }} |
| 171 | {{- end }} |
| 172 | {{- end }} |
| 173 | {{- end }} |