Skip to content

Commit d73a51b

Browse files
committed
feat(helm): DRY cloudsql-proxy
1 parent c05fff3 commit d73a51b

File tree

6 files changed

+44
-114
lines changed

6 files changed

+44
-114
lines changed

helm/defectdojo/Chart.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ dependencies:
1919
condition: redis.enabled
2020
annotations:
2121
artifacthub.io/prerelease: "true"
22-
artifacthub.io/changes: ""
22+
artifacthub.io/changes: |
23+
- kind: changed
24+
description: DRY cloudsql-proxy

helm/defectdojo/templates/_helpers.tpl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,43 @@
181181
{{- end }}
182182
{{- end -}}
183183

184+
{{- /*
185+
Define cloudsql-proxy
186+
*/}}
187+
{{- define "cloudsqlProxy" -}}
188+
- name: cloudsql-proxy
189+
image: {{ .Values.cloudsql.image.repository }}:{{ .Values.cloudsql.image.tag }}
190+
imagePullPolicy: {{ .Values.cloudsql.image.pullPolicy }}
191+
{{- with .Values.cloudsql.extraEnv }}
192+
env: {{- . | toYaml | nindent 4 }}
193+
{{- end }}
194+
{{- with .Values.cloudsql.resources }}
195+
resources: {{- . | toYaml | nindent 4 }}
196+
{{- end }}
197+
restartPolicy: Always
198+
{{- if .Values.securityContext.enabled }}
199+
securityContext:
200+
{{- include "helpers.securityContext" (list
201+
.Values
202+
"securityContext.containerSecurityContext"
203+
"cloudsql.containerSecurityContext"
204+
) | nindent 4 }}
205+
{{- end }}
206+
command: ["/cloud_sql_proxy"]
207+
args:
208+
- "-verbose={{ .Values.cloudsql.verbose }}"
209+
- "-instances={{ .Values.cloudsql.instance }}=tcp:{{ .Values.postgresql.primary.service.ports.postgresql }}"
210+
{{- if .Values.cloudsql.enable_iam_login }}
211+
- "-enable_iam_login"
212+
{{- end }}
213+
{{- if .Values.cloudsql.use_private_ip }}
214+
- "-ip_address_types=PRIVATE"
215+
{{- end }}
216+
{{- with .Values.cloudsql.extraVolumeMounts }}
217+
volumeMounts: {{ . | toYaml | nindent 4 }}
218+
{{- end }}
219+
{{- end -}}
220+
184221
{{- /*
185222
Returns the JSON representation of the value for a dot-notation path
186223
from a given context.

helm/defectdojo/templates/celery-beat-deployment.yaml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,7 @@ spec:
8787
{{- end }}
8888
{{- end }}
8989
{{- if .Values.cloudsql.enabled }}
90-
- name: cloudsql-proxy
91-
image: {{ .Values.cloudsql.image.repository }}:{{ .Values.cloudsql.image.tag }}
92-
imagePullPolicy: {{ .Values.cloudsql.image.pullPolicy }}
93-
{{- with .Values.cloudsql.resources }}
94-
resources: {{- . | toYaml | nindent 10 }}
95-
{{- end }}
96-
restartPolicy: Always
97-
{{- if .Values.securityContext.enabled }}
98-
securityContext:
99-
{{- include "helpers.securityContext" (list
100-
.Values
101-
"securityContext.containerSecurityContext"
102-
"cloudsql.containerSecurityContext"
103-
) | nindent 10 }}
104-
{{- end }}
105-
command: ["/cloud_sql_proxy"]
106-
args:
107-
- "-verbose={{ .Values.cloudsql.verbose }}"
108-
- "-instances={{ .Values.cloudsql.instance }}=tcp:{{ .Values.postgresql.primary.service.ports.postgresql }}"
109-
{{- if .Values.cloudsql.enable_iam_login }}
110-
- "-enable_iam_login"
111-
{{- end }}
112-
{{- if .Values.cloudsql.use_private_ip }}
113-
- "-ip_address_types=PRIVATE"
114-
{{- end }}
90+
{{- include "cloudsqlProxy" . | nindent 6 }}
11591
{{- end }}
11692
{{- if .Values.dbMigrationChecker.enabled }}
11793
{{$data := dict "fullName" $fullName }}

helm/defectdojo/templates/celery-worker-deployment.yaml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,7 @@ spec:
8585
{{- end }}
8686
{{- end }}
8787
{{- if .Values.cloudsql.enabled }}
88-
- name: cloudsql-proxy
89-
image: {{ .Values.cloudsql.image.repository }}:{{ .Values.cloudsql.image.tag }}
90-
imagePullPolicy: {{ .Values.cloudsql.image.pullPolicy }}
91-
{{- with .Values.cloudsql.resources }}
92-
resources: {{- . | toYaml | nindent 10 }}
93-
{{- end }}
94-
restartPolicy: Always
95-
{{- if .Values.securityContext.enabled }}
96-
securityContext:
97-
{{- include "helpers.securityContext" (list
98-
.Values
99-
"securityContext.containerSecurityContext"
100-
"cloudsql.containerSecurityContext"
101-
) | nindent 10 }}
102-
{{- end }}
103-
command: ["/cloud_sql_proxy"]
104-
args:
105-
- "-verbose={{ .Values.cloudsql.verbose }}"
106-
- "-instances={{ .Values.cloudsql.instance }}=tcp:{{ .Values.postgresql.primary.service.ports.postgresql }}"
107-
{{- if .Values.cloudsql.enable_iam_login }}
108-
- "-enable_iam_login"
109-
{{- end }}
110-
{{- if .Values.cloudsql.use_private_ip }}
111-
- "-ip_address_types=PRIVATE"
112-
{{- end }}
88+
{{- include "cloudsqlProxy" . | nindent 6 }}
11389
{{- end }}
11490
{{- if .Values.dbMigrationChecker.enabled }}
11591
{{$data := dict "fullName" $fullName }}

helm/defectdojo/templates/django-deployment.yaml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -104,37 +104,7 @@ spec:
104104
- {{- . | toYaml | nindent 8 }}
105105
{{- end }}
106106
{{- if .Values.cloudsql.enabled }}
107-
- name: cloudsql-proxy
108-
image: {{ .Values.cloudsql.image.repository }}:{{ .Values.cloudsql.image.tag }}
109-
imagePullPolicy: {{ .Values.cloudsql.image.pullPolicy }}
110-
{{- with .Values.cloudsql.extraEnv }}
111-
env: {{- . | toYaml | nindent 8 }}
112-
{{- end }}
113-
{{- with .Values.cloudsql.resources }}
114-
resources: {{- . | toYaml | nindent 10 }}
115-
{{- end }}
116-
restartPolicy: Always
117-
{{- if .Values.securityContext.enabled }}
118-
securityContext:
119-
{{- include "helpers.securityContext" (list
120-
.Values
121-
"securityContext.containerSecurityContext"
122-
"cloudsql.containerSecurityContext"
123-
) | nindent 10 }}
124-
{{- end }}
125-
command: ["/cloud_sql_proxy"]
126-
args:
127-
- "-verbose={{ .Values.cloudsql.verbose }}"
128-
- "-instances={{ .Values.cloudsql.instance }}=tcp:{{ .Values.postgresql.primary.service.ports.postgresql }}"
129-
{{- if .Values.cloudsql.enable_iam_login }}
130-
- "-enable_iam_login"
131-
{{- end }}
132-
{{- if .Values.cloudsql.use_private_ip }}
133-
- "-ip_address_types=PRIVATE"
134-
{{- end }}
135-
{{- with .Values.cloudsql.extraVolumeMounts }}
136-
volumeMounts: {{ . | toYaml | nindent 10 }}
137-
{{- end }}
107+
{{- include "cloudsqlProxy" . | nindent 6 }}
138108
{{- end }}
139109
{{- if .Values.dbMigrationChecker.enabled }}
140110
{{- $data := dict "fullName" $fullName }}

helm/defectdojo/templates/initializer-job.yaml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,38 +74,7 @@ spec:
7474
{{- end }}
7575
initContainers:
7676
{{- if .Values.cloudsql.enabled }}
77-
- name: cloudsql-proxy
78-
image: {{ .Values.cloudsql.image.repository }}:{{ .Values.cloudsql.image.tag }}
79-
imagePullPolicy: {{ .Values.cloudsql.image.pullPolicy }}
80-
{{- with .Values.cloudsql.resources }}
81-
resources: {{- . | toYaml | nindent 10 }}
82-
{{- end }}
83-
restartPolicy: Always
84-
{{- if .Values.securityContext.enabled }}
85-
securityContext:
86-
{{- include "helpers.securityContext" (list
87-
.Values
88-
"securityContext.containerSecurityContext"
89-
"cloudsql.containerSecurityContext"
90-
) | nindent 10 }}
91-
{{- end }}
92-
command: ["/cloud_sql_proxy"]
93-
args:
94-
- "-verbose={{ .Values.cloudsql.verbose }}"
95-
- "-instances={{ .Values.cloudsql.instance }}=tcp:{{ .Values.postgresql.primary.service.ports.postgresql }}"
96-
{{- if .Values.cloudsql.enable_iam_login }}
97-
- "-enable_iam_login"
98-
{{- end }}
99-
{{- if .Values.cloudsql.use_private_ip }}
100-
- "-ip_address_types=PRIVATE"
101-
{{- end }}
102-
volumeMounts:
103-
{{- range .Values.initializer.extraVolumes }}
104-
- name: userconfig-{{ .name }}
105-
readOnly: true
106-
mountPath: {{ .path }}
107-
subPath: {{ .subPath }}
108-
{{- end }}
77+
{{- include "cloudsqlProxy" . | nindent 6 }}
10978
{{- end }}
11079
- name: wait-for-db
11180
command:

0 commit comments

Comments
 (0)