Skip to content

Commit d5fff17

Browse files
authored
feat: deploy cloud-sql-proxy in its down deployment (#340)
Signed-off-by: Christophe de Carvalho <[email protected]>
1 parent a7c6494 commit d5fff17

File tree

5 files changed

+129
-46
lines changed

5 files changed

+129
-46
lines changed

deployment/chainloop/templates/_helpers.tpl

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,22 @@ Return the Postgresql connection string for Atlas migration
173173
Return the Postgresql hostname
174174
*/}}
175175
{{- define "controlplane.database.host" -}}
176-
{{- ternary (include "chainloop.postgresql.fullname" .) .Values.controlplane.externalDatabase.host .Values.postgresql.enabled -}}
176+
{{- if .Values.controlplane.sqlProxy.enabled }}
177+
{{- include "chainloop.sql-proxy.fullname" . -}}
178+
{{- else -}}
179+
{{- ternary (include "chainloop.postgresql.fullname" .) .Values.controlplane.externalDatabase.host .Values.postgresql.enabled -}}
180+
{{- end -}}
177181
{{- end -}}
178182

179183
{{/*
180184
Return the Postgresql port
181185
*/}}
182186
{{- define "controlplane.database.port" -}}
183-
{{- ternary 5432 .Values.controlplane.externalDatabase.port .Values.postgresql.enabled -}}
187+
{{- if .Values.controlplane.sqlProxy.enabled }}
188+
{{- 5432 -}}
189+
{{- else -}}
190+
{{- ternary 5432 .Values.controlplane.externalDatabase.port .Values.postgresql.enabled -}}
191+
{{- end -}}
184192
{{- end -}}
185193

186194
{{/*
@@ -266,6 +274,52 @@ null
266274
{{- end -}}
267275
{{- end -}}
268276

277+
{{/*
278+
##############################################################################
279+
sql-proxy helpers
280+
##############################################################################
281+
*/}}
282+
283+
{{/*
284+
Chainloop sql-proxy release name
285+
*/}}
286+
{{- define "chainloop.sql-proxy.fullname" -}}
287+
{{- printf "%s-%s" (include "common.names.fullname" .) "sql-proxy" | trunc 63 | trimSuffix "-" -}}
288+
{{- end -}}
289+
290+
{{/*
291+
Chainloop sql-proxy Chart fullname
292+
*/}}
293+
{{- define "chainloop.sql-proxy.name" -}}
294+
{{- printf "%s-%s" (include "common.names.name" .) "sql-proxy" | trunc 63 | trimSuffix "-" -}}
295+
{{- end -}}
296+
297+
{{/*
298+
Common labels
299+
*/}}
300+
{{- define "chainloop.sql-proxy.labels" -}}
301+
{{- include "common.labels.standard" . }}
302+
app.kubernetes.io/part-of: chainloop
303+
app.kubernetes.io/component: sql-proxy
304+
{{- end }}
305+
306+
{{/*
307+
Migration labels
308+
*/}}
309+
{{- define "chainloop.sql-proxy.migration.labels" -}}
310+
{{- include "common.labels.standard" . }}
311+
app.kubernetes.io/part-of: chainloop
312+
app.kubernetes.io/component: sql-proxy-migration
313+
{{- end }}
314+
315+
{{/*
316+
Selector labels
317+
*/}}
318+
{{- define "chainloop.sql-proxy.selectorLabels" -}}
319+
{{- include "common.labels.matchLabels" .}}
320+
app.kubernetes.io/component: sql-proxy
321+
{{- end }}
322+
269323
{{/*
270324
##############################################################################
271325
CAS Helpers

deployment/chainloop/templates/controlplane/deployment.yaml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,6 @@ spec:
2929
securityContext:
3030
{{- toYaml .Values.controlplane.podSecurityContext | nindent 8 }}
3131
containers:
32-
{{ if .Values.controlplane.sqlProxy.enabled }}
33-
- name: cloud-sql-proxy
34-
# It is recommended to use the latest version of the Cloud SQL proxy
35-
# Make sure to update on a regular schedule!
36-
image: gcr.io/cloudsql-docker/gce-proxy:1.28.0 # make sure the use the latest version
37-
command:
38-
- "/cloud_sql_proxy"
39-
# If connecting from a VPC-native GKE cluster, you can use the
40-
# following flag to have the proxy connect over private IP
41-
# - "-ip_address_types=PRIVATE"
42-
43-
# By default, the proxy will write all logs to stderr. In some
44-
# environments, anything printed to stderr is consider an error. To
45-
# disable this behavior and write all logs to stdout (except errors
46-
# which will still go to stderr), use:
47-
- "-log_debug_stdout"
48-
- "-instances={{ .Values.controlplane.sqlProxy.connectionName }}=tcp:5432"
49-
securityContext:
50-
runAsNonRoot: true
51-
resources:
52-
{{- toYaml .Values.controlplane.sqlProxy.resources | nindent 12 }}
53-
{{- end }}
5432
- name: {{ .Chart.Name }}
5533
securityContext:
5634
{{- toYaml .Values.controlplane.securityContext | nindent 12 }}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{{ if .Values.controlplane.sqlProxy.enabled }}
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: {{ include "chainloop.sql-proxy.fullname" . }}
6+
labels:
7+
{{- include "chainloop.sql-proxy.labels" . | nindent 4 }}
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
{{- include "chainloop.sql-proxy.selectorLabels" . | nindent 6 }}
13+
template:
14+
metadata:
15+
annotations:
16+
kubectl.kubernetes.io/default-container: cloud-sql-proxy
17+
labels:
18+
{{- include "chainloop.sql-proxy.selectorLabels" . | nindent 8 }}
19+
spec:
20+
affinity:
21+
podAffinity:
22+
requiredDuringSchedulingIgnoredDuringExecution:
23+
- labelSelector:
24+
matchLabels:
25+
app.kubernetes.io/component: controlplane
26+
topologyKey: kubernetes.io/hostname
27+
{{- with .Values.controlplane.image.pullSecrets }}
28+
imagePullSecrets:
29+
{{- toYaml . | nindent 8 }}
30+
{{- end }}
31+
serviceAccountName: {{ include "controlplane.serviceAccountName" . }}
32+
securityContext:
33+
{{- toYaml .Values.controlplane.podSecurityContext | nindent 8 }}
34+
containers:
35+
36+
- name: cloud-sql-proxy
37+
# It is recommended to use the latest version of the Cloud SQL proxy
38+
# Make sure to update on a regular schedule!
39+
image: gcr.io/cloudsql-docker/gce-proxy:1.33.10 # make sure the use the latest version
40+
command:
41+
- "/cloud_sql_proxy"
42+
# If connecting from a VPC-native GKE cluster, you can use the
43+
# following flag to have the proxy connect over private IP
44+
# - "-ip_address_types=PRIVATE"
45+
46+
# By default, the proxy will write all logs to stderr. In some
47+
# environments, anything printed to stderr is consider an error. To
48+
# disable this behavior and write all logs to stdout (except errors
49+
# which will still go to stderr), use:
50+
- "-log_debug_stdout"
51+
- "-instances={{ .Values.controlplane.sqlProxy.connectionName }}=tcp:0.0.0.0:5432"
52+
securityContext:
53+
runAsNonRoot: true
54+
resources:
55+
{{- toYaml .Values.controlplane.sqlProxy.resources | nindent 12 }}
56+
{{- end }}

deployment/chainloop/templates/controlplane/migrate-job.yaml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,6 @@ spec:
2222
securityContext:
2323
{{- toYaml .Values.controlplane.podSecurityContext | nindent 8 }}
2424
containers:
25-
{{ if .Values.controlplane.sqlProxy.enabled }}
26-
- name: cloud-sql-proxy
27-
# It is recommended to use the latest version of the Cloud SQL proxy
28-
# Make sure to update on a regular schedule!
29-
image: gcr.io/cloudsql-docker/gce-proxy:1.28.0 # make sure the use the latest version
30-
command:
31-
- "/cloud_sql_proxy"
32-
# If connecting from a VPC-native GKE cluster, you can use the
33-
# following flag to have the proxy connect over private IP
34-
# - "-ip_address_types=PRIVATE"
35-
36-
# By default, the proxy will write all logs to stderr. In some
37-
# environments, anything printed to stderr is consider an error. To
38-
# disable this behavior and write all logs to stdout (except errors
39-
# which will still go to stderr), use:
40-
- "-log_debug_stdout"
41-
- "-instances={{ .Values.controlplane.sqlProxy.connectionName }}=tcp:5432"
42-
securityContext:
43-
runAsNonRoot: true
44-
resources:
45-
{{- toYaml .Values.controlplane.sqlProxy.resources | nindent 12 }}
46-
{{- end }}
4725
- name: migrate
4826
image: "{{ .Values.controlplane.migration.image.repository }}:{{ .Values.controlplane.migration.image.tag | default .Chart.AppVersion }}"
4927
imagePullPolicy: {{ .Values.controlplane.image.pullPolicy }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{ if .Values.controlplane.sqlProxy.enabled }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ include "chainloop.sql-proxy.fullname" . }}
6+
labels:
7+
{{- include "chainloop.sql-proxy.labels" . | nindent 4 }}
8+
spec:
9+
type: ClusterIP
10+
ports:
11+
- port: {{ .Values.controlplane.externalDatabase.port }}
12+
targetPort: {{ .Values.controlplane.externalDatabase.port }}
13+
protocol: TCP
14+
name: tpc
15+
selector:
16+
{{- include "chainloop.sql-proxy.selectorLabels" . | nindent 4 }}
17+
{{- end }}

0 commit comments

Comments
 (0)