|
| 1 | +{{/* |
| 2 | +Expand the name of the chart. |
| 3 | +*/}} |
| 4 | +{{- define "ra-self-hosted.name" -}} |
| 5 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
| 6 | +{{- end }} |
| 7 | + |
| 8 | +{{/* |
| 9 | +Create a default fully qualified app name. |
| 10 | +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 11 | +If release name contains chart name it will be used as a full name. |
| 12 | +*/}} |
| 13 | +{{- define "ra-self-hosted.fullname" -}} |
| 14 | +{{- if .Values.fullnameOverride }} |
| 15 | +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} |
| 16 | +{{- else }} |
| 17 | +{{- $name := default .Chart.Name .Values.nameOverride }} |
| 18 | +{{- if contains $name .Release.Name }} |
| 19 | +{{- .Release.Name | trunc 63 | trimSuffix "-" }} |
| 20 | +{{- else }} |
| 21 | +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} |
| 22 | +{{- end }} |
| 23 | +{{- end }} |
| 24 | +{{- end }} |
| 25 | + |
| 26 | +{{- define "ra-self-hosted-executor.fullname" -}} |
| 27 | +{{- printf "%s-%s" (include "ra-self-hosted.fullname" .) "executor" | trunc 63 | trimSuffix "-" }} |
| 28 | +{{- end -}} |
| 29 | + |
| 30 | +{{- define "ra-self-hosted-executor.pullsecret-name" -}} |
| 31 | +{{- printf "%s-%s-pullsecret" (include "ra-self-hosted.fullname" .) "executor" | trunc 63 | trimSuffix "-" }} |
| 32 | +{{- end -}} |
| 33 | + |
| 34 | +{{- define "ra-self-hosted-job-controller.fullname" -}} |
| 35 | +{{- printf "%s-%s" (include "ra-self-hosted.fullname" .) "job-controller" | trunc 63 | trimSuffix "-" }} |
| 36 | +{{- end -}} |
| 37 | + |
| 38 | +{{- define "ra-self-hosted-job-controller.pullsecret-name" -}} |
| 39 | +{{- printf "%s-%s-pullsecret" (include "ra-self-hosted.fullname" .) "job-controller" | trunc 63 | trimSuffix "-" }} |
| 40 | +{{- end -}} |
| 41 | + |
| 42 | +{{/* |
| 43 | +Create chart name and version as used by the chart label. |
| 44 | +*/}} |
| 45 | +{{- define "ra-self-hosted.chart" -}} |
| 46 | +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} |
| 47 | +{{- end }} |
| 48 | + |
| 49 | +{{/* |
| 50 | +Common labels |
| 51 | +*/}} |
| 52 | +{{- define "ra-self-hosted.labels-executor" -}} |
| 53 | +helm.sh/chart: {{ include "ra-self-hosted.chart" . }} |
| 54 | +{{ include "ra-self-hosted-executor.selectorLabels" . }} |
| 55 | +{{- if .Chart.AppVersion }} |
| 56 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 57 | +{{- end }} |
| 58 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 59 | +{{- if .Values.executor.labels }} |
| 60 | +{{ .Values.executor.labels }} |
| 61 | +{{- end }} |
| 62 | +{{- end }} |
| 63 | + |
| 64 | +{{- define "ra-self-hosted-job-controller.labels" -}} |
| 65 | +helm.sh/chart: {{ include "ra-self-hosted.chart" . }} |
| 66 | +{{ include "ra-self-hosted-job-controller.selectorLabels" . }} |
| 67 | +{{- if .Chart.AppVersion }} |
| 68 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 69 | +{{- end }} |
| 70 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 71 | +{{- if .Values.jobController.labels }} |
| 72 | +{{ .Values.jobController.labels }} |
| 73 | +{{- end }} |
| 74 | +{{- end }} |
| 75 | + |
| 76 | +{{- define "ra-self-hosted.labels" -}} |
| 77 | +helm.sh/chart: {{ include "ra-self-hosted.chart" . }} |
| 78 | +{{ include "ra-self-hosted.selectorLabels" . }} |
| 79 | +{{- if .Chart.AppVersion }} |
| 80 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 81 | +{{- end }} |
| 82 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 83 | +{{- if .Values.jobController.labels }} |
| 84 | +{{ .Values.jobController.labels }} |
| 85 | +{{- end }} |
| 86 | +{{- end }} |
| 87 | + |
| 88 | +{{/* |
| 89 | +Selector labels |
| 90 | +*/}} |
| 91 | +{{- define "ra-self-hosted-executor.selectorLabels" -}} |
| 92 | +app.kubernetes.io/name: {{ include "ra-self-hosted.name" . }} |
| 93 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 94 | +app.kubernetes.io/component: executor |
| 95 | +{{- end }} |
| 96 | + |
| 97 | +{{- define "ra-self-hosted-job-controller.selectorLabels" -}} |
| 98 | +app.kubernetes.io/name: {{ include "ra-self-hosted.name" . }} |
| 99 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 100 | +app.kubernetes.io/component: job-controller |
| 101 | +{{- end }} |
| 102 | + |
| 103 | +{{- define "ra-self-hosted.selectorLabels" -}} |
| 104 | +app.kubernetes.io/name: {{ include "ra-self-hosted.name" . }} |
| 105 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 106 | +{{- end }} |
| 107 | + |
| 108 | +{{- define "ra-self-hosted-executor.imageRegistry" -}} |
| 109 | +{{- .Values.executor.image.registry -}} |
| 110 | +{{- end -}} |
| 111 | + |
| 112 | +{{- define "ra-self-hosted-executor.imageRepo" -}} |
| 113 | +{{- .Values.executor.image.repository -}} |
| 114 | +{{- end -}} |
| 115 | + |
| 116 | + |
| 117 | +{{- define "ra-self-hosted-executor.image" -}} |
| 118 | +{{- if .Values.executor.image.digest -}} |
| 119 | +{{- if contains "sha256:" .Values.executor.image.digest -}} |
| 120 | +{{- printf "%s/%s@%s" (include "ra-self-hosted-executor.imageRegistry" .) (include "ra-self-hosted-executor.imageRepo" .) .Values.executor.image.digest -}} |
| 121 | +{{- else -}} |
| 122 | +{{- printf "%s/%s@%s" (include "ra-self-hosted-executor.imageRegistry" .) (include "ra-self-hosted-executor.imageRepo" .) "sha256" .Values.executor.image.digest -}} |
| 123 | +{{- end -}} |
| 124 | +{{- else -}} |
| 125 | +{{- printf "%s/%s:%s" (include "ra-self-hosted-executor.imageRegistry" .) (include "ra-self-hosted-executor.imageRepo" .) .Values.executor.image.tag -}} |
| 126 | +{{- end -}} |
| 127 | +{{- end -}} |
| 128 | + |
| 129 | +{{- define "ra-self-hosted-job-controller.imageRegistry" -}} |
| 130 | +{{- .Values.jobController.image.registry -}} |
| 131 | +{{- end -}} |
| 132 | + |
| 133 | +{{- define "ra-self-hosted-job-controller.imageRepo" -}} |
| 134 | +{{- .Values.jobController.image.repository -}} |
| 135 | +{{- end -}} |
| 136 | + |
| 137 | + |
| 138 | +{{- define "ra-self-hosted-job-controller.image" -}} |
| 139 | +{{- if .Values.jobController.image.digest -}} |
| 140 | +{{- if contains "sha256:" .Values.jobController.image.digest -}} |
| 141 | +{{- printf "%s/%s@%s" (include "ra-self-hosted-job-controller.imageRegistry" .) (include "ra-self-hosted-job-controller.imageRepo" .) .Values.jobController.image.digest -}} |
| 142 | +{{- else -}} |
| 143 | +{{- printf "%s/%s@%s" (include "ra-self-hosted-job-controller.imageRegistry" .) (include "ra-self-hosted-job-controller.imageRepo" .) "sha256" .Values.jobController.image.digest -}} |
| 144 | +{{- end -}} |
| 145 | +{{- else -}} |
| 146 | +{{- printf "%s/%s:%s" (include "ra-self-hosted-job-controller.imageRegistry" .) (include "ra-self-hosted-job-controller.imageRepo" .) .Values.jobController.image.tag -}} |
| 147 | +{{- end -}} |
| 148 | +{{- end -}} |
| 149 | + |
| 150 | +{{- define "ra-self-hosted-job-controller.db-pvc-name" -}} |
| 151 | +{{- if .Values.jobController.dbStorage.create -}} {{- printf "%s-%s" (include "ra-self-hosted-job-controller.fullname" .) "db" | trunc 63 -}} {{- else -}} {{ .Values.jobController.dbStorage.existingClaimName }} {{- end -}} |
| 152 | +{{- end -}} |
| 153 | + |
| 154 | +{{- define "ra-self-hosted-executor.db-pvc-name" -}} |
| 155 | +{{- if .Values.executor.dbStorage.create -}} {{- printf "%s-%s" (include "ra-self-hosted-executor.fullname" .) "db" | trunc 63 -}} {{- else -}} {{ .Values.executor.dbStorage.existingClaimName }} {{- end -}} |
| 156 | +{{- end -}} |
| 157 | + |
| 158 | +{{- define "ra-self-hosted-executor.storage-pvc-name" -}} |
| 159 | +{{- if .Values.executor.assessmentStorage.pvc.create -}} {{- printf "%s-%s" (include "ra-self-hosted-executor.fullname" .) "storage" | trunc 63 -}} {{- else -}} {{ .Values.executor.assessmentStorage.pvc.existingClaimName }} {{- end -}} |
| 160 | +{{- end -}} |
| 161 | + |
| 162 | +{{- define "ra-self-hosted-executor.registry-credentials-json" -}} |
| 163 | +{{- $creds := list -}} |
| 164 | +{{- range $k, $v := .Values.registryConfigs -}} |
| 165 | +{{- $cred := dict -}} |
| 166 | +{{- $cred = set $cred "registry_type" $v.type -}} |
| 167 | +{{- $cred = set $cred "registry_host" $v.host -}} |
| 168 | +{{- $cred = set $cred "registry_port" $v.port -}} |
| 169 | +{{- $credDetails := dict -}} |
| 170 | +{{- $credsDict := (include "yamlToJson" $v.credentials | fromYaml )}} |
| 171 | +{{- $credString := ($credsDict | toString)}} |
| 172 | +{{- $credDetails = set $credDetails "details" $credsDict -}} |
| 173 | +{{- $cred = set $cred "credential" $credDetails -}} |
| 174 | +{{- $cred = set $cred "registry_id" (sha256sum (printf "%v:%v:%v" $v.host $v.port $credString)) -}} |
| 175 | +{{- $creds = append $creds $cred }} |
| 176 | +{{- end -}} |
| 177 | +{{ toPrettyJson $creds }} |
| 178 | +{{- end -}} |
| 179 | + |
| 180 | +{{- define "ra-self-hosted-job-controller.job-configs-json" -}} |
| 181 | +{{- $jobs := list -}} |
| 182 | +{{- $heartBeatJob := dict }} |
| 183 | +{{- $heartBeatJob = set $heartBeatJob "type" "agent_heartbeat" -}} |
| 184 | +{{- $heartBeatJob = set $heartBeatJob "cron_schedule" "* * * * *" -}} |
| 185 | +{{- $jobs = append $jobs $heartBeatJob -}} |
| 186 | +{{- range $k, $v := .Values.registryConfigs -}} |
| 187 | +{{- $job := dict -}} |
| 188 | +{{- $job = set $job "type" "registry_collection" -}} |
| 189 | +{{- $job = set $job "cron_schedule" $v.cronSchedule -}} |
| 190 | +{{- $props := dict -}} |
| 191 | +{{- $props = set $props "registry_host" $v.host -}} |
| 192 | +{{- $props = set $props "registry_port" $v.port -}} |
| 193 | +{{- $props = set $props "registry_type" $v.type -}} |
| 194 | +{{- $credsDict := (include "yamlToJson" $v.credentials | fromYaml )}} |
| 195 | +{{- $credString := ($credsDict | toString)}} |
| 196 | +{{- $props = set $props "registry_allowed_repositories" $v.allowedRepositories -}} |
| 197 | +{{- $props = set $props "registry_id" (sha256sum (printf "%v:%v:%v" $v.host $v.port $credString)) -}} |
| 198 | +{{- $job = set $job "properties" $props -}} |
| 199 | +{{- $jobs = append $jobs $job -}} |
| 200 | +{{- end -}} |
| 201 | +{{- toPrettyJson $jobs -}} |
| 202 | +{{- end -}} |
| 203 | + |
| 204 | +{{- define "ra-self-hosted-job-controller.job-type-configs-json" -}} |
| 205 | +{{- $configs := list -}} |
| 206 | +{{- range $k, $v := .Values.crowdstrikeConfig.jobTypeConfigs -}} |
| 207 | +{{- $configs = append $configs (set (include "yamlToJson" $v | fromYaml) "name" (snakecase $k)) -}} |
| 208 | +{{- end -}} |
| 209 | +{{- $heartBeatConfig := dict }} |
| 210 | +{{- $heartBeatConfig = set $heartBeatConfig "name" "agent_heartbeat" -}} |
| 211 | +{{- $heartBeatConfig = set $heartBeatConfig "threads_per_pod" 1 -}} |
| 212 | +{{- $configs = append $configs $heartBeatConfig -}} |
| 213 | +{{- toPrettyJson $configs -}} |
| 214 | +{{- end -}} |
| 215 | + |
| 216 | +{{- define "yamlToJson" -}} |
| 217 | +{{- $config := dict -}} |
| 218 | +{{- range $k, $v := . -}} |
| 219 | +{{- if kindIs "map" $v -}} |
| 220 | +{{- $config = set $config (snakecase $k) (include "yamlToJson" $v | fromYaml ) -}} |
| 221 | +{{- else -}} |
| 222 | +{{- $config = set $config (snakecase $k) $v -}} |
| 223 | +{{- end -}} |
| 224 | +{{- end -}} |
| 225 | +{{- $config | toYaml -}} |
| 226 | +{{- end -}} |
| 227 | + |
| 228 | +{{- define "ra-self-hosted.cert-secret-name" }} |
| 229 | +{{- if .Values.tls.useCertManager -}} |
| 230 | +{{- printf "%s-%s" (include "ra-self-hosted.fullname" .) "tls" | trunc 63 }} |
| 231 | +{{- else -}} |
| 232 | +{{- .Values.tls.existingSecret -}} |
| 233 | +{{- end -}} |
| 234 | +{{- end -}} |
0 commit comments