Mohammed Naser | 8a2c8fb | 2023-02-19 17:23:55 +0000 | [diff] [blame] | 1 | {{ if and .Values.enterprise.provisioner.enabled .Values.enterprise.enabled }} |
| 2 | --- |
| 3 | apiVersion: batch/v1 |
| 4 | kind: Job |
| 5 | metadata: |
| 6 | name: {{ template "enterprise-logs.provisionerFullname" . }} |
Giovanni Tirloni | 59219b6 | 2024-04-09 14:50:25 -0300 | [diff] [blame] | 7 | namespace: {{ $.Release.Namespace }} |
Mohammed Naser | 8a2c8fb | 2023-02-19 17:23:55 +0000 | [diff] [blame] | 8 | labels: |
| 9 | {{- include "enterprise-logs.provisionerLabels" . | nindent 4 }} |
| 10 | {{- with .Values.enterprise.provisioner.labels }} |
| 11 | {{- toYaml . | nindent 4 }} |
| 12 | {{- end }} |
| 13 | annotations: |
| 14 | {{- with .Values.enterprise.provisioner.annotations }} |
| 15 | {{- toYaml . | nindent 4 }} |
| 16 | {{- end }} |
| 17 | "helm.sh/hook": post-install |
| 18 | "helm.sh/hook-weight": "15" |
| 19 | spec: |
| 20 | backoffLimit: 6 |
| 21 | completions: 1 |
| 22 | parallelism: 1 |
| 23 | template: |
| 24 | metadata: |
| 25 | labels: |
| 26 | {{- include "enterprise-logs.provisionerSelectorLabels" . | nindent 8 }} |
| 27 | {{- with .Values.enterprise.provisioner.labels }} |
| 28 | {{- toYaml . | nindent 8 }} |
| 29 | {{- end }} |
| 30 | {{- with .Values.enterprise.provisioner.annotations }} |
| 31 | annotations: |
| 32 | {{- toYaml . | nindent 8 }} |
| 33 | {{- end }} |
| 34 | spec: |
| 35 | {{- with .Values.enterprise.provisioner.priorityClassName }} |
| 36 | priorityClassName: {{ . }} |
| 37 | {{- end }} |
| 38 | securityContext: |
| 39 | {{- toYaml .Values.enterprise.provisioner.securityContext | nindent 8 }} |
| 40 | {{- if .Values.imagePullSecrets }} |
| 41 | imagePullSecrets: |
| 42 | {{- range .Values.imagePullSecrets }} |
| 43 | - name: {{ . }} |
| 44 | {{- end }} |
| 45 | {{- end }} |
| 46 | initContainers: |
| 47 | - name: provisioner |
| 48 | image: {{ template "enterprise-logs.provisionerImage" . }} |
| 49 | imagePullPolicy: {{ .Values.enterprise.provisioner.image.pullPolicy }} |
| 50 | command: |
| 51 | - /bin/sh |
| 52 | - -exuc |
| 53 | - | |
| 54 | {{- range .Values.enterprise.provisioner.additionalTenants }} |
| 55 | /usr/bin/enterprise-logs-provisioner \ |
| 56 | -bootstrap-path=/bootstrap \ |
| 57 | -cluster-name={{ include "loki.clusterName" $ }} \ |
| 58 | -gel-url={{ include "loki.address" $ }} \ |
| 59 | -instance={{ .name }} \ |
| 60 | -access-policy=write-{{ .name }}:{{ .name }}:logs:write \ |
| 61 | -access-policy=read-{{ .name }}:{{ .name }}:logs:read \ |
| 62 | -token=write-{{ .name }} \ |
| 63 | -token=read-{{ .name }} |
| 64 | {{- end -}} |
| 65 | |
| 66 | {{- with .Values.monitoring.selfMonitoring.tenant }} |
| 67 | /usr/bin/enterprise-logs-provisioner \ |
| 68 | -bootstrap-path=/bootstrap \ |
| 69 | -cluster-name={{ include "loki.clusterName" $ }} \ |
| 70 | -gel-url={{ include "loki.address" $ }} \ |
| 71 | -instance={{ .name }} \ |
| 72 | -access-policy=self-monitoring:{{ .name }}:logs:write,logs:read \ |
| 73 | -token=self-monitoring |
| 74 | {{- end }} |
| 75 | volumeMounts: |
| 76 | {{- with .Values.enterprise.provisioner.extraVolumeMounts }} |
| 77 | {{ toYaml . | nindent 12 }} |
| 78 | {{- end }} |
| 79 | - name: bootstrap |
| 80 | mountPath: /bootstrap |
| 81 | - name: admin-token |
| 82 | mountPath: /bootstrap/token |
| 83 | subPath: token |
| 84 | {{- with .Values.enterprise.provisioner.env }} |
| 85 | env: |
| 86 | {{ toYaml . | nindent 12 }} |
| 87 | {{- end }} |
| 88 | containers: |
| 89 | - name: create-secret |
| 90 | image: {{ include "loki.kubectlImage" . }} |
| 91 | imagePullPolicy: {{ .Values.kubectlImage.pullPolicy }} |
| 92 | command: |
| 93 | - /bin/bash |
| 94 | - -exuc |
| 95 | - | |
Giovanni Tirloni | 59219b6 | 2024-04-09 14:50:25 -0300 | [diff] [blame] | 96 | # In case, the admin resources have already been created, the provisioner job |
| 97 | # does not write the token files to the bootstrap mount. |
| 98 | # Therefore, secrets are only created if the respective token files exist. |
| 99 | # Note: the following bash commands should always return a success status code. |
| 100 | # Therefore, in case the token file does not exist, the first clause of the |
| 101 | # or-operation is successful. |
Mohammed Naser | 8a2c8fb | 2023-02-19 17:23:55 +0000 | [diff] [blame] | 102 | {{- range .Values.enterprise.provisioner.additionalTenants }} |
Giovanni Tirloni | 59219b6 | 2024-04-09 14:50:25 -0300 | [diff] [blame] | 103 | ! test -s /bootstrap/token-write-{{ .name }} || \ |
| 104 | kubectl --namespace "{{ .secretNamespace }}" create secret generic "{{ include "enterprise-logs.provisionedSecretPrefix" $ }}-{{ .name }}" \ |
| 105 | --from-literal=token-write="$(cat /bootstrap/token-write-{{ .name }})" \ |
| 106 | --from-literal=token-read="$(cat /bootstrap/token-read-{{ .name }})" |
Mohammed Naser | 8a2c8fb | 2023-02-19 17:23:55 +0000 | [diff] [blame] | 107 | {{- end }} |
| 108 | {{- $namespace := $.Release.Namespace }} |
| 109 | {{- with .Values.monitoring.selfMonitoring.tenant }} |
| 110 | {{- $secretNamespace := tpl .secretNamespace $ }} |
Giovanni Tirloni | 59219b6 | 2024-04-09 14:50:25 -0300 | [diff] [blame] | 111 | ! test -s /bootstrap/token-self-monitoring || \ |
| 112 | kubectl --namespace "{{ $namespace }}" create secret generic "{{ include "enterprise-logs.selfMonitoringTenantSecret" $ }}" \ |
| 113 | --from-literal=username="{{ .name }}" \ |
| 114 | --from-literal=password="$(cat /bootstrap/token-self-monitoring)" |
Mohammed Naser | 8a2c8fb | 2023-02-19 17:23:55 +0000 | [diff] [blame] | 115 | {{- if not (eq $secretNamespace $namespace) }} |
Giovanni Tirloni | 59219b6 | 2024-04-09 14:50:25 -0300 | [diff] [blame] | 116 | ! test -s /bootstrap/token-self-monitoring || \ |
| 117 | kubectl --namespace "{{ $secretNamespace }}" create secret generic "{{ include "enterprise-logs.selfMonitoringTenantSecret" $ }}" \ |
| 118 | --from-literal=username="{{ .name }}" \ |
| 119 | --from-literal=password="$(cat /bootstrap/token-self-monitoring)" |
Mohammed Naser | 8a2c8fb | 2023-02-19 17:23:55 +0000 | [diff] [blame] | 120 | {{- end }} |
| 121 | {{- end }} |
| 122 | volumeMounts: |
| 123 | {{- with .Values.enterprise.provisioner.extraVolumeMounts }} |
| 124 | {{ toYaml . | nindent 12 }} |
| 125 | {{- end }} |
| 126 | - name: bootstrap |
| 127 | mountPath: /bootstrap |
| 128 | restartPolicy: OnFailure |
| 129 | serviceAccount: {{ include "enterprise-logs.provisionerFullname" . }} |
| 130 | serviceAccountName: {{ include "enterprise-logs.provisionerFullname" . }} |
| 131 | volumes: |
| 132 | - name: admin-token |
| 133 | secret: |
| 134 | secretName: "{{ include "enterprise-logs.adminTokenSecret" . }}" |
| 135 | - name: bootstrap |
| 136 | emptyDir: {} |
| 137 | {{- end }} |