-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path_helpers.tpl
More file actions
166 lines (155 loc) · 5.25 KB
/
_helpers.tpl
File metadata and controls
166 lines (155 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{{/*
Expand the name of the chart.
*/}}
{{- define "sourcebot.name" -}}
{{- default $.Chart.Name $.Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "sourcebot.fullname" -}}
{{- if $.Values.fullnameOverride }}
{{- $.Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default $.Chart.Name $.Values.nameOverride }}
{{- if contains $name $.Release.Name }}
{{- $.Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" $.Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "sourcebot.chart" -}}
{{- printf "%s-%s" $.Chart.Name $.Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "sourcebot.labels" -}}
helm.sh/chart: {{ include "sourcebot.chart" $ }}
{{ include "sourcebot.selectorLabels" $ }}
{{- if $.Chart.AppVersion }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
{{- $additionalLabels := mergeOverwrite (dict) (default dict $.Values.sourcebot.additionalLabels) (default dict $.Values.additionalLabels) }}
{{- with $additionalLabels }}
{{ toYaml . }}
{{- end }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "sourcebot.selectorLabels" -}}
app.kubernetes.io/name: {{ include "sourcebot.name" $ }}
app.kubernetes.io/instance: {{ $.Release.Name }}
{{- end }}
{{/*
Create the image to use for the container.
*/}}
{{- define "sourcebot.image" -}}
{{- if $.Values.sourcebot.image.digest -}}
"{{ $.Values.sourcebot.image.repository }}@{{ $.Values.sourcebot.image.digest }}"
{{- else if $.Values.sourcebot.image.tag -}}
"{{ $.Values.sourcebot.image.repository }}:{{ $.Values.sourcebot.image.tag }}"
{{- else -}}
"{{ $.Values.sourcebot.image.repository }}:{{ $.Chart.AppVersion }}"
{{- end -}}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "sourcebot.serviceAccountName" -}}
{{- if $.Values.sourcebot.serviceAccount.create }}
{{- default (include "sourcebot.fullname" $) $.Values.sourcebot.serviceAccount.name }}
{{- else }}
{{- default "default" $.Values.sourcebot.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Return PostgreSQL hostname
*/}}
{{- define "sourcebot.postgresql.hostname" -}}
{{- if .Values.postgresql.host }}
{{- .Values.postgresql.host }}
{{- else if .Values.postgresql.deploy }}
{{- printf "%s-postgresql" (include "sourcebot.fullname" .) -}}
{{- end }}
{{- end }}
{{/*
Return Redis hostname
*/}}
{{- define "sourcebot.redis.hostname" -}}
{{- if .Values.redis.host }}
{{- .Values.redis.host }}
{{- else if .Values.redis.deploy }}
{{- printf "%s-redis-primary" (include "sourcebot.fullname" .) -}}
{{- end }}
{{- end }}
{{/*
Helper to get value or secret reference
Returns either a direct value or a valueFrom secretKeyRef
*/}}
{{- define "sourcebot.getValueOrSecret" -}}
{{- if .value.existingSecret }}
valueFrom:
secretKeyRef:
name: {{ .value.existingSecret }}
key: {{ .value.existingSecretKey }}
{{- else if .value.value }}
value: {{ .value.value | quote }}
{{- end }}
{{- end }}
{{/*
Database environment variables
Builds DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_ARGS
These will be assembled into DATABASE_URL by the entrypoint.sh script
*/}}
{{- define "sourcebot.databaseEnv" -}}
- name: DATABASE_HOST
value: {{ include "sourcebot.postgresql.hostname" . | quote }}
- name: DATABASE_PORT
value: {{ .Values.postgresql.port | quote }}
- name: DATABASE_USERNAME
value: {{ .Values.postgresql.auth.username | quote }}
- name: DATABASE_PASSWORD
{{- if .Values.postgresql.auth.existingSecret }}
valueFrom:
secretKeyRef:
name: {{ .Values.postgresql.auth.existingSecret }}
key: {{ .Values.postgresql.auth.secretKeys.userPasswordKey }}
{{- else }}
value: {{ required "postgresql.auth.password is required when existingSecret is not set" .Values.postgresql.auth.password | quote }}
{{- end }}
- name: DATABASE_NAME
value: {{ .Values.postgresql.auth.database | quote }}
{{- if .Values.postgresql.auth.args }}
- name: DATABASE_ARGS
value: {{ .Values.postgresql.auth.args | quote }}
{{- end }}
{{- end -}}
{{/*
Redis environment variables
Builds REDIS_URL connection string
*/}}
{{- define "sourcebot.redisEnv" -}}
{{- $redisPassword := "" -}}
{{- if .Values.redis.auth.existingSecret }}
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.redis.auth.existingSecret }}
key: {{ .Values.redis.auth.existingSecretPasswordKey }}
- name: REDIS_URL
value: "redis://{{ .Values.redis.auth.username }}:$(REDIS_PASSWORD)@{{ include "sourcebot.redis.hostname" . }}:{{ .Values.redis.port }}/{{ .Values.redis.auth.database }}"
{{- else }}
{{- $redisPassword = required "redis.auth.password is required when existingSecret is not set" .Values.redis.auth.password -}}
- name: REDIS_URL
value: "redis://{{ .Values.redis.auth.username }}:{{ $redisPassword }}@{{ include "sourcebot.redis.hostname" . }}:{{ .Values.redis.port }}/{{ .Values.redis.auth.database }}"
{{- end }}
{{- end -}}